Migrating to Drizzle.

This commit is contained in:
Bradley Shellnut 2024-01-30 18:19:51 -08:00
parent 6a66a51085
commit 354838f4f6
4 changed files with 726 additions and 25 deletions

11
drizzle.config.ts Normal file
View file

@ -0,0 +1,11 @@
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/schema.ts',
out: './drizzle',
driver: 'mysql2',
dbCredentials: {
connectionString: process.env.DATABASE_URL
}
});

View file

@ -39,6 +39,7 @@
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"autoprefixer": "^10.4.17",
"drizzle-kit": "^0.20.13",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
@ -78,9 +79,11 @@
"@fontsource/fira-mono": "^4.5.10",
"@iconify-icons/line-md": "^1.2.26",
"@iconify-icons/mdi": "^1.2.47",
"@lucia-auth/adapter-drizzle": "^1.0.0",
"@lucia-auth/adapter-prisma": "4.0.0",
"@lukeed/uuid": "^2.0.1",
"@paralleldrive/cuid2": "^2.2.2",
"@planetscale/database": "^1.14.0",
"@prisma/client": "^5.8.1",
"@sentry/sveltekit": "^7.88.0",
"@sveltejs/adapter-vercel": "^5.1.0",
@ -91,6 +94,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cookie": "^0.5.0",
"drizzle-orm": "^0.29.3",
"feather-icons": "^4.29.1",
"formsnap": "^0.4.3",
"html-entities": "^2.4.0",
@ -99,6 +103,7 @@
"loader": "^2.1.1",
"lucia": "3.0.1",
"lucide-svelte": "^0.298.0",
"mysql2": "^3.9.1",
"open-props": "^1.6.18",
"oslo": "^1.0.3",
"radix-svelte": "^0.9.0",

File diff suppressed because it is too large Load diff

27
src/schema.ts Normal file
View file

@ -0,0 +1,27 @@
import { DrizzleMySQLAdapter } from "@lucia-auth/adapter-drizzle";
import mysql from "mysql2/promise";
import { int, mysqlEnum, mysqlTable, uniqueIndex, datetime, varchar, serial } from 'drizzle-orm/mysql-core';
import { drizzle } from "drizzle-orm/mysql2";
const connection = await mysql.createConnection();
const db = drizzle(connection);
const userTable = mysqlTable("user", {
id: varchar("id", {
length: 255
}).primaryKey()
});
const sessionTable = mysqlTable("session", {
id: varchar("id", {
length: 255
}).primaryKey(),
userId: varchar("user_id", {
length: 255
})
.notNull()
.references(() => userTable.id),
expiresAt: datetime("expires_at").notNull()
});
const adapter = new DrizzleMySQLAdapter(db, sessionTable, userTable);