Skip to content

Commit

Permalink
Move plpgsql fix to migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Dec 12, 2024
1 parent 33b9c6f commit 6a40cfd
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 31 deletions.
1 change: 0 additions & 1 deletion server/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const MIGRATE_CONFIG: MigrationConfig = {
let drizzle: PgDatabase<PgQueryResultHKT, typeof schema>
if (config.db.startsWith('memory:') || config.db.startsWith('file:')) {
let pglite = new PGlite(config.db)
await pglite.exec('CREATE EXTENSION IF NOT EXISTS plpgsql;')
let drizzlePglite = devDrizzle(pglite, { schema })
await devMigrate(drizzlePglite, MIGRATE_CONFIG)
drizzle = drizzlePglite
Expand Down
1 change: 1 addition & 0 deletions server/db/migrations/0000_plpgsql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS plpgsql;
File renamed without changes.
File renamed without changes.
39 changes: 30 additions & 9 deletions server/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"id": "04568407-5e12-4f50-b185-c9393643e49c",
"prevId": "00000000-0000-0000-0000-000000000000",
"id": "2d13e331-00c6-421c-83bd-b784e734f551",
"prevId": "01514472-5c40-4777-aef9-fb6b310cb372",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.sessions": {
"name": "sessions",
"schema": "",
"columns": {
"clientId": {
"name": "clientId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
Expand Down Expand Up @@ -53,24 +59,27 @@
}
],
"isUnique": false,
"concurrently": false,
"with": {},
"method": "btree",
"with": {}
"concurrently": false
}
},
"foreignKeys": {
"sessions_userId_users_id_fk": {
"name": "sessions_userId_users_id_fk",
"tableFrom": "sessions",
"tableTo": "users",
"columnsFrom": ["userId"],
"tableTo": "users",
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
"onUpdate": "no action",
"onDelete": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.users": {
"name": "users",
Expand All @@ -88,17 +97,29 @@
"type": "text",
"primaryKey": true,
"notNull": true
},
"passwordHash": {
"name": "passwordHash",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"views": {},
"sequences": {},
"roles": {},
"policies": {},
"_meta": {
"columns": {},
"schemas": {},
Expand Down
10 changes: 2 additions & 8 deletions server/db/migrations/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "d54c9d0e-26fa-4a3e-aedf-1c6a459f1e92",
"prevId": "04568407-5e12-4f50-b185-c9393643e49c",
"id": "04568407-5e12-4f50-b185-c9393643e49c",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
Expand Down Expand Up @@ -88,12 +88,6 @@
"type": "text",
"primaryKey": true,
"notNull": true
},
"passwordHash": {
"name": "passwordHash",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
Expand Down
10 changes: 2 additions & 8 deletions server/db/migrations/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
{
"id": "01514472-5c40-4777-aef9-fb6b310cb372",
"prevId": "d54c9d0e-26fa-4a3e-aedf-1c6a459f1e92",
"id": "d54c9d0e-26fa-4a3e-aedf-1c6a459f1e92",
"prevId": "04568407-5e12-4f50-b185-c9393643e49c",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.sessions": {
"name": "sessions",
"schema": "",
"columns": {
"clientId": {
"name": "clientId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
Expand Down
119 changes: 119 additions & 0 deletions server/db/migrations/meta/0003_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"id": "01514472-5c40-4777-aef9-fb6b310cb372",
"prevId": "d54c9d0e-26fa-4a3e-aedf-1c6a459f1e92",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.sessions": {
"name": "sessions",
"schema": "",
"columns": {
"clientId": {
"name": "clientId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true
},
"usedAt": {
"name": "usedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"sessionsUserIdx": {
"name": "sessionsUserIdx",
"columns": [
{
"expression": "userId",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"sessions_userId_users_id_fk": {
"name": "sessions_userId_users_id_fk",
"tableFrom": "sessions",
"tableTo": "users",
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"passwordHash": {
"name": "passwordHash",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
17 changes: 12 additions & 5 deletions server/db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
{
"idx": 0,
"version": "7",
"when": 1724539278584,
"tag": "0000_low_eternity",
"when": 1734006544415,
"tag": "0000_plpgsql",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1724722229148,
"tag": "0001_huge_zodiak",
"when": 1724539278584,
"tag": "0001_low_eternity",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1724722229148,
"tag": "0002_huge_zodiak",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1724891569801,
"tag": "0002_lying_imperial_guard",
"tag": "0003_lying_imperial_guard",
"breakpoints": true
}
]
Expand Down

0 comments on commit 6a40cfd

Please sign in to comment.