edge-city
git clone https://git.pyrossh.dev/edge-city
edge-city is a next level meta-framework for react that runs only on edge runtimes
7bd8479
— pyrossh
2023-05-25T11:59:05+05:30
improve migrations
Generated files not shown: pnpm-lock.yaml
- example/drizzle.config.json +0 -4
- example/main.js +0 -4
- example/migrations/0000_cheerful_omega_sentinel.sql +7 -0
- example/{src/db/migrations → migrations}/meta/0000_snapshot.json +1 -1
- example/{src/db/migrations → migrations}/meta/_journal.json +3 -2
- example/migrations/schema.js +5 -0
- example/package.json +4 -0
- example/scripts/migrate.js +14 -0
- example/src/db/migrations/0000_empty_shatterstar.sql +0 -7
- example/src/{db/index.js → services/db.js} +1 -6
- example/src/services/todos.service.js +2 -2
example/drizzle.config.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"out": "./db/migrations/",
|
|
3
|
-
"schema": "./db/index.js"
|
|
4
|
-
}
|
example/main.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { getTodos } from "@/services/todos.service";
|
|
2
|
-
|
|
3
|
-
const todos = await getTodos();
|
|
4
|
-
console.log(todos);
|
example/migrations/0000_cheerful_omega_sentinel.sql
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
create table if not exists "todos" (
|
|
2
|
+
"id" serial primary key not null,
|
|
3
|
+
"text" text not null,
|
|
4
|
+
"completed" boolean not null,
|
|
5
|
+
"createdAt" date not null,
|
|
6
|
+
"updatedAt" date
|
|
7
|
+
);
|
example/{src/db/migrations → migrations}/meta/0000_snapshot.json
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "5",
|
|
3
3
|
"dialect": "pg",
|
|
4
|
-
"id": "
|
|
4
|
+
"id": "d0432aeb-cfc0-4ad1-af0d-b91474ba236a",
|
|
5
5
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
6
6
|
"tables": {
|
|
7
7
|
"todos": {
|
example/{src/db/migrations → migrations}/meta/_journal.json
RENAMED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
{
|
|
6
6
|
"idx": 0,
|
|
7
7
|
"version": "5",
|
|
8
|
-
"when":
|
|
8
|
+
"when": 1684994794751,
|
|
9
|
-
"tag": "
|
|
9
|
+
"tag": "0000_cheerful_omega_sentinel",
|
|
10
|
+
"breakpoints": false
|
|
10
11
|
}
|
|
11
12
|
]
|
|
12
13
|
}
|
example/migrations/schema.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { todos } from "../src/services/todos.service";
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
todos,
|
|
5
|
+
}
|
example/package.json
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "edge-city dev -p cloudflare",
|
|
6
6
|
"build": " edge-city build -p cloudflare",
|
|
7
|
+
"generate": "drizzle-kit generate:pg --out migrations --schema migrations/schema.js",
|
|
8
|
+
"migrate": "node scripts/migrate.js",
|
|
7
9
|
"test": "jest",
|
|
8
10
|
"test-e2e": "playwright test"
|
|
9
11
|
},
|
|
@@ -23,6 +25,8 @@
|
|
|
23
25
|
"zod": "^3.21.4"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
28
|
+
"drizzle-kit": "0.18.0",
|
|
29
|
+
"postgres": "3.3.4",
|
|
26
30
|
"@playwright/test": "^1.31.2",
|
|
27
31
|
"eslint": "^8.35.0",
|
|
28
32
|
"eslint-config-react-app": "^7.0.1"
|
example/scripts/migrate.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
|
+
import { migrate } from 'drizzle-orm/postgres-js/migrator';
|
|
3
|
+
import postgres from 'postgres';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
dotenv.config();
|
|
6
|
+
|
|
7
|
+
const main = async () => {
|
|
8
|
+
console.log("migration started");
|
|
9
|
+
const client = postgres(process.env.EC_PG_CONN_URL + "?sslmode=require", { max: 1 });
|
|
10
|
+
await migrate(drizzle(client), { migrationsFolder: './migrations' });
|
|
11
|
+
console.log("migration complete");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main();
|
example/src/db/migrations/0000_empty_shatterstar.sql
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS "todos" (
|
|
2
|
-
"id" serial PRIMARY KEY NOT NULL,
|
|
3
|
-
"text" text NOT NULL,
|
|
4
|
-
"completed" boolean NOT NULL,
|
|
5
|
-
"createdAt" date NOT NULL,
|
|
6
|
-
"updatedAt" date
|
|
7
|
-
);
|
example/src/{db/index.js → services/db.js}
RENAMED
|
@@ -12,9 +12,4 @@ const db = drizzle(pool, {
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
export default db;
|
|
15
|
+
export default db;
|
|
16
|
-
|
|
17
|
-
// import { migrate } from 'drizzle-orm/neon-serverless/migrator';
|
|
18
|
-
// export const migrateAll = async () => {
|
|
19
|
-
// await migrate(db, { migrationsFolder: './db/migrations' });
|
|
20
|
-
// }
|
example/src/services/todos.service.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { eq, asc } from 'drizzle-orm';
|
|
2
|
-
import db from "
|
|
2
|
+
import db from "./db";
|
|
3
3
|
import { boolean, date, pgTable, serial, text } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
|
-
const todos = pgTable('todos', {
|
|
6
|
+
export const todos = pgTable('todos', {
|
|
7
7
|
id: serial('id').primaryKey(),
|
|
8
8
|
text: text('text').notNull(),
|
|
9
9
|
completed: boolean('completed').notNull(),
|