diff --git a/apps/api/package.json b/apps/api/package.json index 7a21c842e..b2bbd6c50 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -23,7 +23,7 @@ "@trpc/server": "next", "cors": "2.8.5", "devalue": "4.3.2", - "drizzle-orm": "0.30.2", + "drizzle-orm": "0.31.0", "envalid": "8.0.0", "googleapis": "134.0.0", "ioredis": "5.3.2", diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index c3fe1f21b..e41fe8f42 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -1,4 +1,3 @@ -import { sql } from 'drizzle-orm'; import { boolean, index, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core'; export const blockedHostnames = pgTable('blocked_hostnames', { @@ -20,9 +19,9 @@ export const urls = pgTable( }, (urls) => ({ // prettier-ignore - blockedIdx: index().on(urls.blocked).using(sql`hash`), + blockedIdx: index().using('hash', urls.blocked), // prettier-ignore - urlIdx: index().on(urls.url).using(sql`hash`), + urlIdx: index().using('hash', urls.url), }), ); @@ -37,7 +36,7 @@ export const visits = pgTable( }, (visits) => ({ // prettier-ignore - urlShortBase64Idx: index().on(visits.urlShortBase64).using(sql`hash`), + urlShortBase64Idx: index().using('hash', visits.urlShortBase64), timestampIdx: index().on(visits.timestamp), }), ); diff --git a/bun.lockb b/bun.lockb index 4085581c1..c33f1bcd3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/drizzle.config.ts b/drizzle.config.ts index 37674936f..fdf9674b9 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -9,9 +9,9 @@ const env = cleanEnv(process.env, { // biome-ignore lint/style/noDefaultExport: This must be a default export export default { schema: 'apps/api/src/db/schema.ts', - driver: 'pg', + dialect: 'postgresql', dbCredentials: { - connectionString: env.DATABASE_URL, + url: env.DATABASE_URL, }, out: 'drizzle', } satisfies Config; diff --git a/drizzle/0001_flawless_maria_hill.sql b/drizzle/0001_flawless_maria_hill.sql new file mode 100644 index 000000000..350628f7e --- /dev/null +++ b/drizzle/0001_flawless_maria_hill.sql @@ -0,0 +1,8 @@ +DROP INDEX IF EXISTS "urls_blocked_index";--> statement-breakpoint +DROP INDEX IF EXISTS "urls_url_index";--> statement-breakpoint +DROP INDEX IF EXISTS "visits_url_short_base64_index";--> statement-breakpoint +DROP INDEX IF EXISTS "visits_timestamp_index";--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "urls_blocked_index" ON "urls" USING hash (blocked);--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "urls_url_index" ON "urls" USING hash (url);--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "visits_url_short_base64_index" ON "visits" USING hash (url_short_base64);--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "visits_timestamp_index" ON "visits" USING btree (timestamp); \ No newline at end of file diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json index ac69f6919..3ea74b791 100644 --- a/drizzle/meta/0000_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,10 +1,8 @@ { - "id": "a1a9d125-cfb1-4769-baca-2f88b80c8dc9", - "prevId": "00000000-0000-0000-0000-000000000000", - "version": "5", - "dialect": "pg", + "version": "7", + "dialect": "postgresql", "tables": { - "blocked_hostnames": { + "public.blocked_hostnames": { "name": "blocked_hostnames", "schema": "", "columns": { @@ -27,7 +25,7 @@ "compositePrimaryKeys": {}, "uniqueConstraints": {} }, - "urls": { + "public.urls": { "name": "urls", "schema": "", "columns": { @@ -60,21 +58,39 @@ }, "indexes": { "urls_blocked_index": { + "columns": [ + { + "expression": "blocked", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], "name": "urls_blocked_index", - "columns": ["blocked"], - "isUnique": false + "isUnique": false, + "method": "btree", + "concurrently": false }, "urls_url_index": { + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], "name": "urls_url_index", - "columns": ["url"], - "isUnique": false + "isUnique": false, + "method": "btree", + "concurrently": false } }, "foreignKeys": {}, "compositePrimaryKeys": {}, "uniqueConstraints": {} }, - "visits": { + "public.visits": { "name": "visits", "schema": "", "columns": { @@ -100,25 +116,43 @@ }, "indexes": { "visits_url_short_base64_index": { + "columns": [ + { + "expression": "url_short_base64", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], "name": "visits_url_short_base64_index", - "columns": ["url_short_base64"], - "isUnique": false + "isUnique": false, + "method": "btree", + "concurrently": false }, "visits_timestamp_index": { + "columns": [ + { + "expression": "timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], "name": "visits_timestamp_index", - "columns": ["timestamp"], - "isUnique": false + "isUnique": false, + "method": "btree", + "concurrently": false } }, "foreignKeys": { "visits_url_short_base64_urls_short_base64_fk": { "name": "visits_url_short_base64_urls_short_base64_fk", "tableFrom": "visits", - "tableTo": "urls", "columnsFrom": ["url_short_base64"], + "tableTo": "urls", "columnsTo": ["short_base64"], - "onDelete": "cascade", - "onUpdate": "cascade" + "onUpdate": "cascade", + "onDelete": "cascade" } }, "compositePrimaryKeys": {}, @@ -128,8 +162,10 @@ "enums": {}, "schemas": {}, "_meta": { - "columns": {}, "schemas": {}, - "tables": {} - } + "tables": {}, + "columns": {} + }, + "id": "a1a9d125-cfb1-4769-baca-2f88b80c8dc9", + "prevId": "00000000-0000-0000-0000-000000000000" } diff --git a/drizzle/meta/0001_snapshot.json b/drizzle/meta/0001_snapshot.json new file mode 100644 index 000000000..acb78705c --- /dev/null +++ b/drizzle/meta/0001_snapshot.json @@ -0,0 +1,179 @@ +{ + "id": "5285b7db-7d21-4825-98dc-077f7612ee83", + "prevId": "a1a9d125-cfb1-4769-baca-2f88b80c8dc9", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.blocked_hostnames": { + "name": "blocked_hostnames", + "schema": "", + "columns": { + "hostname": { + "name": "hostname", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.urls": { + "name": "urls", + "schema": "", + "columns": { + "blocked": { + "name": "blocked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "short_base64": { + "name": "short_base64", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "urls_blocked_index": { + "name": "urls_blocked_index", + "columns": [ + { + "expression": "blocked", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hash", + "with": {} + }, + "urls_url_index": { + "name": "urls_url_index", + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hash", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.visits": { + "name": "visits", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "timestamp": { + "name": "timestamp", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "url_short_base64": { + "name": "url_short_base64", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "visits_url_short_base64_index": { + "name": "visits_url_short_base64_index", + "columns": [ + { + "expression": "url_short_base64", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hash", + "with": {} + }, + "visits_timestamp_index": { + "name": "visits_timestamp_index", + "columns": [ + { + "expression": "timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "visits_url_short_base64_urls_short_base64_fk": { + "name": "visits_url_short_base64_urls_short_base64_fk", + "tableFrom": "visits", + "tableTo": "urls", + "columnsFrom": [ + "url_short_base64" + ], + "columnsTo": [ + "short_base64" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 19a0c2fb1..aa74c103e 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -1,13 +1,20 @@ { - "version": "5", - "dialect": "pg", - "entries": [ - { - "idx": 0, - "version": "5", - "when": 1711606474248, - "tag": "0000_sweet_marvel_apes", - "breakpoints": true - } - ] -} + "version": "5", + "dialect": "pg", + "entries": [ + { + "idx": 0, + "version": "5", + "when": 1711606474248, + "tag": "0000_sweet_marvel_apes", + "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1717462907814, + "tag": "0001_flawless_maria_hill", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 095f76689..abcf83df5 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "lint": "biome check .", "lint:fix": "biome check . --apply-unsafe", "migrate": "bun ./migrate.ts", - "migrate:create": "drizzle-kit generate:pg", + "migrate:create": "drizzle-kit generate", "test": "bun run lint && bun run format && turbo run build type-check", "type-check": "turbo run type-check" }, "dependencies": { - "drizzle-kit": "0.21.4", + "drizzle-kit": "0.22.1", "envalid": "8.0.0", "pg": "8.11.3", "pino": "9.1.0",