-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,306 additions
and
1,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
{ | ||
"name": "drizzle-schema-checker", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "pnpm run vitest" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.0", | ||
"db0": "^0.1.4", | ||
"tsup": "^8.2.4", | ||
"vitest": "^2.1.1" | ||
}, | ||
"dependencies": { | ||
"@libsql/client": "^0.11.0", | ||
"better-sqlite3": "^11.3.0", | ||
"consola": "^3.2.3", | ||
"drizzle-orm": "^0.33.0", | ||
"zod": "^3.23.8" | ||
}, | ||
"packageManager": "[email protected]" | ||
"name": "drizzle-schema-checker", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "pnpm run vitest", | ||
"test:ci": "pnpm test -- --coverage --reporter=default --reporter=junit && pnpm test:bun", | ||
"lint": "biome lint", | ||
"format": "biome format --write" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.0", | ||
"db0": "^0.1.4", | ||
"tsup": "^8.2.4", | ||
"vitest": "^2.1.1" | ||
}, | ||
"dependencies": { | ||
"@libsql/client": "^0.11.0", | ||
"better-sqlite3": "^11.3.0", | ||
"consola": "^3.2.3", | ||
"drizzle-orm": "^0.33.0", | ||
"zod": "^3.23.8" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
import { sqliteTable, text, integer, primaryKey } from "drizzle-orm/sqlite-core"; | ||
import { | ||
sqliteTable, | ||
text, | ||
integer, | ||
primaryKey, | ||
} from "drizzle-orm/sqlite-core"; | ||
import type { tableNames } from ".."; | ||
import { sql } from "drizzle-orm"; | ||
|
||
const datesColumns = { | ||
created_at: integer("created_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`), | ||
update_at: integer("updated_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`), | ||
created_at: integer("created_at", { mode: "timestamp" }) | ||
.notNull() | ||
.default(sql`CURRENT_TIMESTAMP`), | ||
update_at: integer("updated_at", { mode: "timestamp" }) | ||
.notNull() | ||
.default(sql`CURRENT_TIMESTAMP`), | ||
}; | ||
|
||
export const getUsersTableSchema = (tableNames: tableNames) => sqliteTable(tableNames.users, { | ||
id: text("id").primaryKey().notNull(), | ||
password: text("password"), | ||
email: text("email").notNull().unique(), | ||
...datesColumns, | ||
}); | ||
export const getUsersTableSchema = (tableNames: tableNames) => | ||
sqliteTable(tableNames.users, { | ||
id: text("id").primaryKey().notNull(), | ||
password: text("password"), | ||
email: text("email").notNull().unique(), | ||
...datesColumns, | ||
}); | ||
|
||
export const getSessionsTableSchema = (tableNames: tableNames) => sqliteTable(tableNames.sessions, { | ||
id: text("id").primaryKey().notNull(), | ||
expires_at: integer("expires_at").notNull(), | ||
ip: text("ip"), | ||
ua: text("ua"), | ||
user_id: text("user_id") | ||
.references(() => getUsersTableSchema(tableNames).id) | ||
.notNull(), | ||
...datesColumns, | ||
}); | ||
export const getSessionsTableSchema = (tableNames: tableNames) => | ||
sqliteTable(tableNames.sessions, { | ||
id: text("id").primaryKey().notNull(), | ||
expires_at: integer("expires_at").notNull(), | ||
ip: text("ip"), | ||
ua: text("ua"), | ||
user_id: text("user_id") | ||
.references(() => getUsersTableSchema(tableNames).id) | ||
.notNull(), | ||
...datesColumns, | ||
}); | ||
|
||
// https://lucia-auth.com/guides/oauth/multiple-providers | ||
export const getOAuthAccountsTableSchema = (tableNames: tableNames) => sqliteTable(tableNames.oauthAccounts, { | ||
provider_id: text("provider_id").notNull(), | ||
provider_user_id: text("provider_user_id").notNull(), | ||
user_id: text("user_id") | ||
.references(() => getUsersTableSchema(tableNames).id) | ||
.notNull(), | ||
...datesColumns, | ||
}, slipAuthOAuthAccounts => ({ | ||
pk: primaryKey(slipAuthOAuthAccounts.provider_id, slipAuthOAuthAccounts.provider_user_id), | ||
})); | ||
export const getOAuthAccountsTableSchema = (tableNames: tableNames) => | ||
sqliteTable( | ||
tableNames.oauthAccounts, | ||
{ | ||
provider_id: text("provider_id").notNull(), | ||
provider_user_id: text("provider_user_id").notNull(), | ||
user_id: text("user_id") | ||
.references(() => getUsersTableSchema(tableNames).id) | ||
.notNull(), | ||
...datesColumns, | ||
}, | ||
(slipAuthOAuthAccounts) => ({ | ||
pk: primaryKey( | ||
slipAuthOAuthAccounts.provider_id, | ||
slipAuthOAuthAccounts.provider_user_id, | ||
), | ||
}), | ||
); |
Oops, something went wrong.