Skip to content

Commit

Permalink
update drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
JLarky committed Aug 12, 2024
1 parent e60fe80 commit 2c2eb09
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 381 deletions.
5 changes: 0 additions & 5 deletions drizzle.config.json

This file was deleted.

10 changes: 10 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'drizzle-kit';

export const migrationsFolder = './src/db/migrations';

export default defineConfig({
dialect: 'postgresql', // supports "sqlite" | "mysql"
schema: './src/db',
out: migrationsFolder,
breakpoints: false,
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"astro-seo": "^0.7.2",
"clsx": "^1.2.1",
"cookie": "^0.5.0",
"drizzle-kit": "^0.19.3",
"drizzle-orm": "^0.27.0",
"drizzle-kit": "^0.24.0",
"drizzle-orm": "^0.33.0",
"eslint": "^8.44.0",
"eslint-plugin-astro": "^0.27.2",
"eslint-plugin-deprecation": "^1.4.1",
Expand Down
47 changes: 27 additions & 20 deletions src/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"version": "5",
"dialect": "pg",
"id": "1d984902-03b4-4306-aa9b-a9adef27bd11",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"gpt_keys": {
"public.gpt_keys": {
"name": "gpt_keys",
"schema": "",
"columns": {
Expand Down Expand Up @@ -67,9 +65,10 @@
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"prompt_likes": {
"public.prompt_likes": {
"name": "prompt_likes",
"schema": "",
"columns": {
Expand Down Expand Up @@ -103,9 +102,10 @@
"user_id"
]
}
}
},
"uniqueConstraints": {}
},
"prompts": {
"public.prompts": {
"name": "prompts",
"schema": "",
"columns": {
Expand Down Expand Up @@ -175,9 +175,10 @@
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"shared_key_ratelimit": {
"public.shared_key_ratelimit": {
"name": "shared_key_ratelimit",
"schema": "",
"columns": {
Expand All @@ -203,9 +204,10 @@
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"surveys": {
"public.surveys": {
"name": "surveys",
"schema": "",
"columns": {
Expand Down Expand Up @@ -244,22 +246,27 @@
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"gpt_type": {
"public.gpt_type": {
"name": "gpt_type",
"values": {
"gpt-3": "gpt-3",
"gpt-4": "gpt-4"
}
"schema": "public",
"values": [
"gpt-3",
"gpt-4"
]
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
},
"id": "1d984902-03b4-4306-aa9b-a9adef27bd11",
"prevId": "00000000-0000-0000-0000-000000000000",
"sequences": {}
}
4 changes: 2 additions & 2 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'drizzle-orm/pg-core';

// Hello and welcome to the schema file!
// 1. run `doppler run npx drizzle-kit generate:pg` to generate migrations
// 1. run `doppler run npx drizzle-kit generate` to generate migrations
// 2. (IMPORTANT) if you are creating new tables you would need to manually
// edit SQL file to add row level security policies
// 3. once this is done, run `doppler run yarn migrate` to apply the migration
Expand Down Expand Up @@ -48,7 +48,7 @@ export const promptLikes = pgTable(
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(table) => {
return { pk: primaryKey(table.promptId, table.userId) };
return { pk: primaryKey({ columns: [table.promptId, table.userId] }) };
}
);

Expand Down
5 changes: 2 additions & 3 deletions src/db/scripts/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @ts-check
// funny story: if you put this file to src/db/migrate.ts it will be running during
// `drizzle-kit generate:pg` but moving it to src/db/scripts seems to fix the issue
// `drizzle-kit generate` but moving it to src/db/scripts seems to fix the issue
import { migrate } from 'drizzle-orm/postgres-js/migrator';

import config from '../../../drizzle.config.json' assert { type: 'json' };
import { migrationsFolder } from '../../../drizzle.config';
import { db } from '../db';

const migrationsFolder = config.out;
console.log('Migrating database using', migrationsFolder, 'folder');

// this will automatically run needed migrations on the database
Expand Down
Loading

0 comments on commit 2c2eb09

Please sign in to comment.