Skip to content

Commit

Permalink
chore(app): migrate to lucia 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Feb 13, 2024
1 parent 1fd3375 commit 1ccb216
Show file tree
Hide file tree
Showing 39 changed files with 386 additions and 352 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PUBLIC_APP_URL=http://localhost:5173
PUBLIC_SELF_HOSTED=true
SECRET_PLUNK_API_KEY=
SECRET_DB_DRIVER=turso
SECRET_SQLITE_URL=file:./data/sqlite.db
Expand Down
Binary file modified bun.lockb
Binary file not shown.
5 changes: 2 additions & 3 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/lib/db/schema.ts',
out: './drizzle',
driver: (process.env.SECRET_DB_DRIVER ?? '') as 'turso',
driver: 'libsql',
dbCredentials: {
url: process.env.SECRET_SQLITE_URL ?? '',
authToken: process.env.SECRET_SQLITE_KEY ?? ''
url: process.env.SECRET_SQLITE_URL ?? ''
},
verbose: true,
strict: true
Expand Down
29 changes: 12 additions & 17 deletions drizzle/0000_round_cyclops.sql → drizzle/0000_bent_gauntlet.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,19 @@ CREATE TABLE `project_invitation` (
FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `user` (
`id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`username` text NOT NULL,
`created_at` text,
`updated_at` text
);
--> statement-breakpoint
CREATE TABLE `user_key` (
CREATE TABLE `session` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`hashed_password` text,
`expires_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `user_session` (
CREATE TABLE `user` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`active_expires` blob NOT NULL,
`idle_expires` blob NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
`email` text NOT NULL,
`username` text NOT NULL,
`created_at` text,
`updated_at` text
);
--> statement-breakpoint
CREATE TABLE `users_to_projects` (
Expand All @@ -100,8 +92,10 @@ CREATE TABLE `users_to_projects` (
--> statement-breakpoint
CREATE TABLE `verification_code` (
`id` text PRIMARY KEY NOT NULL,
`expires` integer,
`code` text NOT NULL,
`user_id` text NOT NULL,
`email` text NOT NULL,
`expires_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
Expand All @@ -117,4 +111,5 @@ CREATE TABLE `webhook` (
--> statement-breakpoint
CREATE UNIQUE INDEX `project_invitation_user_id_project_id_unique` ON `project_invitation` (`user_id`,`project_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `user_email_unique` ON `user` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `user_username_unique` ON `user` (`username`);
CREATE UNIQUE INDEX `user_username_unique` ON `user` (`username`);--> statement-breakpoint
CREATE UNIQUE INDEX `verification_code_user_id_unique` ON `verification_code` (`user_id`);
165 changes: 68 additions & 97 deletions drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "cf9d473c-a333-4248-8d24-8e57de8ec4f4",
"id": "101a376c-2848-40be-991c-14ec81fef5fb",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"access_token": {
Expand Down Expand Up @@ -482,67 +482,8 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"user_email_unique": {
"name": "user_email_unique",
"columns": [
"email"
],
"isUnique": true
},
"user_username_unique": {
"name": "user_username_unique",
"columns": [
"username"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user_key": {
"name": "user_key",
"session": {
"name": "session",
"columns": {
"id": {
"name": "id",
Expand All @@ -558,19 +499,19 @@
"notNull": true,
"autoincrement": false
},
"hashed_password": {
"name": "hashed_password",
"type": "text",
"expires_at": {
"name": "expires_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"user_key_user_id_user_id_fk": {
"name": "user_key_user_id_user_id_fk",
"tableFrom": "user_key",
"session_user_id_user_id_fk": {
"name": "session_user_id_user_id_fk",
"tableFrom": "session",
"tableTo": "user",
"columnsFrom": [
"user_id"
Expand All @@ -585,8 +526,8 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user_session": {
"name": "user_session",
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
Expand All @@ -595,44 +536,52 @@
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"active_expires": {
"name": "active_expires",
"type": "blob",
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"idle_expires": {
"name": "idle_expires",
"type": "blob",
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"user_session_user_id_user_id_fk": {
"name": "user_session_user_id_user_id_fk",
"tableFrom": "user_session",
"tableTo": "user",
"columnsFrom": [
"user_id"
"indexes": {
"user_email_unique": {
"name": "user_email_unique",
"columns": [
"email"
],
"columnsTo": [
"id"
"isUnique": true
},
"user_username_unique": {
"name": "user_username_unique",
"columns": [
"username"
],
"onDelete": "no action",
"onUpdate": "no action"
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
Expand Down Expand Up @@ -704,11 +653,11 @@
"notNull": true,
"autoincrement": false
},
"expires": {
"name": "expires",
"type": "integer",
"code": {
"name": "code",
"type": "text",
"primaryKey": false,
"notNull": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
Expand All @@ -717,9 +666,31 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"verification_code_user_id_unique": {
"name": "verification_code_user_id_unique",
"columns": [
"user_id"
],
"isUnique": true
}
},
"indexes": {},
"foreignKeys": {
"verification_code_user_id_user_id_fk": {
"name": "verification_code_user_id_user_id_fk",
Expand Down
4 changes: 2 additions & 2 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1707688702512,
"tag": "0000_round_cyclops",
"when": 1707858219034,
"tag": "0000_bent_gauntlet",
"breakpoints": true
}
]
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "bunx vite dev",
"dev": "bunx --bun vite dev",
"build": "bunx vite build",
"preview": "bunx vite preview",
"start": "node build/index.js",
"postinstall": "npm run db:migrate",
"start": "npm run db:migrate && node build/index.js",
"test": "bun run test:integration && bun run test:unit",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"test:integration": "playwright test",
"test:unit": "vitest",
"db:generate": "drizzle-kit generate:sqlite",
"db:push": "drizzle-kit push:sqlite",
"db:migrate": "tsx --tsconfig ./scripts/tsconfig.json ./scripts/migrate.ts"
"db:generate": "npx drizzle-kit generate:sqlite",
"db:push": "bunx --bun drizzle-kit push:sqlite",
"db:migrate": "bun ./scripts/migrate.ts"
},
"devDependencies": {
"@playwright/test": "^1.28.1",
Expand Down Expand Up @@ -58,7 +57,7 @@
"@cartamd/plugin-slash": "^3.1.0",
"@internationalized/date": "^3.5.1",
"@libsql/client": "^0.3.6",
"@lucia-auth/adapter-sqlite": "^2.0.1",
"@lucia-auth/adapter-drizzle": "^1.0.1",
"bits-ui": "^0.13.0",
"carta-md": "^3.5.0",
"clsx": "^2.1.0",
Expand All @@ -70,7 +69,7 @@
"feed": "^4.2.2",
"formsnap": "^0.4.2",
"isomorphic-dompurify": "^2.3.0",
"lucia": "^2.7.6",
"lucia": "^3.0.1",
"lucide-svelte": "^0.303.0",
"mode-watcher": "^0.1.2",
"rambda": "^8.6.0",
Expand Down
10 changes: 5 additions & 5 deletions scripts/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'dotenv/config';
import { migrate } from 'drizzle-orm/libsql/migrator';
import { db } from '../src/lib/db';

export const execMigrate = async () => {
return migrate(db, { migrationsFolder: 'drizzle' });
};

const main = async () => {
try {
await migrate(db, { migrationsFolder: 'drizzle' });
} catch (e) {
console.log('>>>MIGRATION_FAILED', e);
}
await execMigrate();
process.exit(0);
};

Expand Down
Loading

0 comments on commit 1ccb216

Please sign in to comment.