style(db): standardize database migration file formatting

This commit is contained in:
2026-04-07 08:09:15 -04:00
parent db9d6399dd
commit 3d9e2452c4
5 changed files with 744 additions and 747 deletions

View File

@@ -1,344 +1,321 @@
{ {
"id": "00000000-0000-0000-0000-000000000000", "id": "00000000-0000-0000-0000-000000000000",
"prevId": "", "prevId": "",
"version": "7", "version": "7",
"dialect": "postgresql", "dialect": "postgresql",
"tables": { "tables": {
"public.session": { "public.session": {
"name": "session", "name": "session",
"schema": "", "schema": "",
"columns": { "columns": {
"sessionToken": { "sessionToken": {
"name": "sessionToken", "name": "sessionToken",
"type": "text", "type": "text",
"primaryKey": true, "primaryKey": true,
"notNull": true "notNull": true
}, },
"userId": { "userId": {
"name": "userId", "name": "userId",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": true
}, },
"expires": { "expires": {
"name": "expires", "name": "expires",
"type": "timestamp", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": true
} }
}, },
"indexes": {}, "indexes": {},
"foreignKeys": { "foreignKeys": {
"session_userId_user_id_fk": { "session_userId_user_id_fk": {
"name": "session_userId_user_id_fk", "name": "session_userId_user_id_fk",
"tableFrom": "session", "tableFrom": "session",
"tableTo": "user", "tableTo": "user",
"schemaTo": "public", "schemaTo": "public",
"columnsFrom": [ "columnsFrom": ["userId"],
"userId" "columnsTo": ["id"],
], "onDelete": "cascade",
"columnsTo": [ "onUpdate": "no action"
"id" }
], },
"onDelete": "cascade", "compositePrimaryKeys": {},
"onUpdate": "no action" "uniqueConstraints": {},
} "checkConstraints": {},
}, "policies": {},
"compositePrimaryKeys": {}, "isRLSEnabled": false
"uniqueConstraints": {}, },
"checkConstraints": {}, "public.user": {
"policies": {}, "name": "user",
"isRLSEnabled": false "schema": "",
}, "columns": {
"public.user": { "id": {
"name": "user", "name": "id",
"schema": "", "type": "text",
"columns": { "primaryKey": true,
"id": { "notNull": true
"name": "id", },
"type": "text", "name": {
"primaryKey": true, "name": "name",
"notNull": true "type": "text",
}, "primaryKey": false,
"name": { "notNull": false
"name": "name", },
"type": "text", "email": {
"primaryKey": false, "name": "email",
"notNull": false "type": "text",
}, "primaryKey": false,
"email": { "notNull": true
"name": "email", },
"type": "text", "emailVerified": {
"primaryKey": false, "name": "emailVerified",
"notNull": true "type": "timestamp",
}, "primaryKey": false,
"emailVerified": { "notNull": false
"name": "emailVerified", },
"type": "timestamp", "image": {
"primaryKey": false, "name": "image",
"notNull": false "type": "text",
}, "primaryKey": false,
"image": { "notNull": false
"name": "image", }
"type": "text", },
"primaryKey": false, "indexes": {},
"notNull": false "foreignKeys": {},
} "compositePrimaryKeys": {},
}, "uniqueConstraints": {},
"indexes": {}, "checkConstraints": {},
"foreignKeys": {}, "policies": {},
"compositePrimaryKeys": {}, "isRLSEnabled": false
"uniqueConstraints": {}, },
"checkConstraints": {}, "public.verificationToken": {
"policies": {}, "name": "verificationToken",
"isRLSEnabled": false "schema": "",
}, "columns": {
"public.verificationToken": { "identifier": {
"name": "verificationToken", "name": "identifier",
"schema": "", "type": "text",
"columns": { "primaryKey": false,
"identifier": { "notNull": true
"name": "identifier", },
"type": "text", "token": {
"primaryKey": false, "name": "token",
"notNull": true "type": "text",
}, "primaryKey": false,
"token": { "notNull": true
"name": "token", },
"type": "text", "expires": {
"primaryKey": false, "name": "expires",
"notNull": true "type": "timestamp",
}, "primaryKey": false,
"expires": { "notNull": true
"name": "expires", }
"type": "timestamp", },
"primaryKey": false, "indexes": {},
"notNull": true "foreignKeys": {},
} "compositePrimaryKeys": {
}, "verificationToken_identifier_token_pk": {
"indexes": {}, "name": "verificationToken_identifier_token_pk",
"foreignKeys": {}, "columns": ["identifier", "token"]
"compositePrimaryKeys": { }
"verificationToken_identifier_token_pk": { },
"name": "verificationToken_identifier_token_pk", "uniqueConstraints": {},
"columns": [ "checkConstraints": {},
"identifier", "policies": {},
"token" "isRLSEnabled": false
] },
} "public.authenticator": {
}, "name": "authenticator",
"uniqueConstraints": {}, "schema": "",
"checkConstraints": {}, "columns": {
"policies": {}, "credentialID": {
"isRLSEnabled": false "name": "credentialID",
}, "type": "text",
"public.authenticator": { "primaryKey": false,
"name": "authenticator", "notNull": true
"schema": "", },
"columns": { "userId": {
"credentialID": { "name": "userId",
"name": "credentialID", "type": "text",
"type": "text", "primaryKey": false,
"primaryKey": false, "notNull": true
"notNull": true },
}, "providerAccountId": {
"userId": { "name": "providerAccountId",
"name": "userId", "type": "text",
"type": "text", "primaryKey": false,
"primaryKey": false, "notNull": true
"notNull": true },
}, "credentialPublicKey": {
"providerAccountId": { "name": "credentialPublicKey",
"name": "providerAccountId", "type": "text",
"type": "text", "primaryKey": false,
"primaryKey": false, "notNull": true
"notNull": true },
}, "counter": {
"credentialPublicKey": { "name": "counter",
"name": "credentialPublicKey", "type": "integer",
"type": "text", "primaryKey": false,
"primaryKey": false, "notNull": true
"notNull": true },
}, "credentialDeviceType": {
"counter": { "name": "credentialDeviceType",
"name": "counter", "type": "text",
"type": "integer", "primaryKey": false,
"primaryKey": false, "notNull": true
"notNull": true },
}, "credentialBackedUp": {
"credentialDeviceType": { "name": "credentialBackedUp",
"name": "credentialDeviceType", "type": "boolean",
"type": "text", "primaryKey": false,
"primaryKey": false, "notNull": true
"notNull": true },
}, "transports": {
"credentialBackedUp": { "name": "transports",
"name": "credentialBackedUp", "type": "text",
"type": "boolean", "primaryKey": false,
"primaryKey": false, "notNull": false
"notNull": true }
}, },
"transports": { "indexes": {},
"name": "transports", "foreignKeys": {
"type": "text", "authenticator_userId_user_id_fk": {
"primaryKey": false, "name": "authenticator_userId_user_id_fk",
"notNull": false "tableFrom": "authenticator",
} "tableTo": "user",
}, "schemaTo": "public",
"indexes": {}, "columnsFrom": ["userId"],
"foreignKeys": { "columnsTo": ["id"],
"authenticator_userId_user_id_fk": { "onDelete": "cascade",
"name": "authenticator_userId_user_id_fk", "onUpdate": "no action"
"tableFrom": "authenticator", }
"tableTo": "user", },
"schemaTo": "public", "compositePrimaryKeys": {
"columnsFrom": [ "authenticator_userId_credentialID_pk": {
"userId" "name": "authenticator_userId_credentialID_pk",
], "columns": ["credentialID", "userId"]
"columnsTo": [ }
"id" },
], "uniqueConstraints": {
"onDelete": "cascade", "authenticator_credentialID_unique": {
"onUpdate": "no action" "columns": ["credentialID"],
} "nullsNotDistinct": false,
}, "name": "authenticator_credentialID_unique"
"compositePrimaryKeys": { }
"authenticator_userId_credentialID_pk": { },
"name": "authenticator_userId_credentialID_pk", "checkConstraints": {},
"columns": [ "policies": {},
"credentialID", "isRLSEnabled": false
"userId" },
] "public.account": {
} "name": "account",
}, "schema": "",
"uniqueConstraints": { "columns": {
"authenticator_credentialID_unique": { "userId": {
"columns": [ "name": "userId",
"credentialID" "type": "text",
], "primaryKey": false,
"nullsNotDistinct": false, "notNull": true
"name": "authenticator_credentialID_unique" },
} "type": {
}, "name": "type",
"checkConstraints": {}, "type": "text",
"policies": {}, "primaryKey": false,
"isRLSEnabled": false "notNull": true
}, },
"public.account": { "provider": {
"name": "account", "name": "provider",
"schema": "", "type": "text",
"columns": { "primaryKey": false,
"userId": { "notNull": true
"name": "userId", },
"type": "text", "providerAccountId": {
"primaryKey": false, "name": "providerAccountId",
"notNull": true "type": "text",
}, "primaryKey": false,
"type": { "notNull": true
"name": "type", },
"type": "text", "refresh_token": {
"primaryKey": false, "name": "refresh_token",
"notNull": true "type": "text",
}, "primaryKey": false,
"provider": { "notNull": false
"name": "provider", },
"type": "text", "access_token": {
"primaryKey": false, "name": "access_token",
"notNull": true "type": "text",
}, "primaryKey": false,
"providerAccountId": { "notNull": false
"name": "providerAccountId", },
"type": "text", "expires_at": {
"primaryKey": false, "name": "expires_at",
"notNull": true "type": "text",
}, "primaryKey": false,
"refresh_token": { "notNull": false
"name": "refresh_token", },
"type": "text", "token_type": {
"primaryKey": false, "name": "token_type",
"notNull": false "type": "text",
}, "primaryKey": false,
"access_token": { "notNull": false
"name": "access_token", },
"type": "text", "scope": {
"primaryKey": false, "name": "scope",
"notNull": false "type": "text",
}, "primaryKey": false,
"expires_at": { "notNull": false
"name": "expires_at", },
"type": "text", "id_token": {
"primaryKey": false, "name": "id_token",
"notNull": false "type": "text",
}, "primaryKey": false,
"token_type": { "notNull": false
"name": "token_type", },
"type": "text", "session_state": {
"primaryKey": false, "name": "session_state",
"notNull": false "type": "text",
}, "primaryKey": false,
"scope": { "notNull": false
"name": "scope", }
"type": "text", },
"primaryKey": false, "indexes": {},
"notNull": false "foreignKeys": {
}, "account_userId_user_id_fk": {
"id_token": { "name": "account_userId_user_id_fk",
"name": "id_token", "tableFrom": "account",
"type": "text", "tableTo": "user",
"primaryKey": false, "schemaTo": "public",
"notNull": false "columnsFrom": ["userId"],
}, "columnsTo": ["id"],
"session_state": { "onDelete": "cascade",
"name": "session_state", "onUpdate": "no action"
"type": "text", }
"primaryKey": false, },
"notNull": false "compositePrimaryKeys": {
} "account_provider_providerAccountId_pk": {
}, "name": "account_provider_providerAccountId_pk",
"indexes": {}, "columns": ["provider", "providerAccountId"]
"foreignKeys": { }
"account_userId_user_id_fk": { },
"name": "account_userId_user_id_fk", "uniqueConstraints": {},
"tableFrom": "account", "checkConstraints": {},
"tableTo": "user", "policies": {},
"schemaTo": "public", "isRLSEnabled": false
"columnsFrom": [ }
"userId" },
], "enums": {},
"columnsTo": [ "schemas": {},
"id" "sequences": {},
], "roles": {},
"onDelete": "cascade", "policies": {},
"onUpdate": "no action" "views": {},
} "_meta": {
}, "schemas": {},
"compositePrimaryKeys": { "tables": {},
"account_provider_providerAccountId_pk": { "columns": {}
"name": "account_provider_providerAccountId_pk", },
"columns": [ "internal": {
"provider", "tables": {}
"providerAccountId" }
] }
}
},
"uniqueConstraints": {},
"checkConstraints": {},
"policies": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {}
}
}

View File

@@ -1,328 +1,316 @@
{ {
"id": "69e7666b-0b8c-4658-906d-993870a0b539", "id": "69e7666b-0b8c-4658-906d-993870a0b539",
"prevId": "00000000-0000-0000-0000-000000000000", "prevId": "00000000-0000-0000-0000-000000000000",
"version": "7", "version": "7",
"dialect": "postgresql", "dialect": "postgresql",
"tables": { "tables": {
"public.account": { "public.account": {
"name": "account", "name": "account",
"schema": "", "schema": "",
"columns": { "columns": {
"id": { "id": {
"name": "id", "name": "id",
"type": "text", "type": "text",
"primaryKey": true, "primaryKey": true,
"notNull": true "notNull": true
}, },
"accountId": { "accountId": {
"name": "accountId", "name": "accountId",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": true
}, },
"providerId": { "providerId": {
"name": "providerId", "name": "providerId",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": true
}, },
"userId": { "userId": {
"name": "userId", "name": "userId",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": true
}, },
"accessToken": { "accessToken": {
"name": "accessToken", "name": "accessToken",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"refreshToken": { "refreshToken": {
"name": "refreshToken", "name": "refreshToken",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"accessTokenExpiresAt": { "accessTokenExpiresAt": {
"name": "accessTokenExpiresAt", "name": "accessTokenExpiresAt",
"type": "timestamp", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"refreshTokenExpiresAt": { "refreshTokenExpiresAt": {
"name": "refreshTokenExpiresAt", "name": "refreshTokenExpiresAt",
"type": "timestamp", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"scope": { "scope": {
"name": "scope", "name": "scope",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"idToken": { "idToken": {
"name": "idToken", "name": "idToken",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"password": { "password": {
"name": "password", "name": "password",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": false "notNull": false
}, },
"createdAt": { "createdAt": {
"name": "createdAt", "name": "createdAt",
"type": "timestamp", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": false, "notNull": false,
"default": "now()" "default": "now()"
}, },
"updatedAt": { "updatedAt": {
"name": "updatedAt", "name": "updatedAt",
"type": "timestamp", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": false, "notNull": false,
"default": "now()" "default": "now()"
} }
}, },
"indexes": {}, "indexes": {},
"foreignKeys": { "foreignKeys": {
"account_userId_user_id_fk": { "account_userId_user_id_fk": {
"name": "account_userId_user_id_fk", "name": "account_userId_user_id_fk",
"tableFrom": "account", "tableFrom": "account",
"tableTo": "user", "tableTo": "user",
"columnsFrom": [ "columnsFrom": ["userId"],
"userId" "columnsTo": ["id"],
], "onDelete": "cascade",
"columnsTo": [ "onUpdate": "no action"
"id" }
], },
"onDelete": "cascade", "compositePrimaryKeys": {},
"onUpdate": "no action" "uniqueConstraints": {},
} "policies": {},
}, "checkConstraints": {},
"compositePrimaryKeys": {}, "isRLSEnabled": false
"uniqueConstraints": {}, },
"policies": {}, "public.session": {
"checkConstraints": {}, "name": "session",
"isRLSEnabled": false "schema": "",
}, "columns": {
"public.session": { "id": {
"name": "session", "name": "id",
"schema": "", "type": "text",
"columns": { "primaryKey": true,
"id": { "notNull": true
"name": "id", },
"type": "text", "expiresAt": {
"primaryKey": true, "name": "expiresAt",
"notNull": true "type": "timestamp",
}, "primaryKey": false,
"expiresAt": { "notNull": true
"name": "expiresAt", },
"type": "timestamp", "token": {
"primaryKey": false, "name": "token",
"notNull": true "type": "text",
}, "primaryKey": false,
"token": { "notNull": true
"name": "token", },
"type": "text", "createdAt": {
"primaryKey": false, "name": "createdAt",
"notNull": true "type": "timestamp",
}, "primaryKey": false,
"createdAt": { "notNull": false,
"name": "createdAt", "default": "now()"
"type": "timestamp", },
"primaryKey": false, "updatedAt": {
"notNull": false, "name": "updatedAt",
"default": "now()" "type": "timestamp",
}, "primaryKey": false,
"updatedAt": { "notNull": false,
"name": "updatedAt", "default": "now()"
"type": "timestamp", },
"primaryKey": false, "ipAddress": {
"notNull": false, "name": "ipAddress",
"default": "now()" "type": "text",
}, "primaryKey": false,
"ipAddress": { "notNull": false
"name": "ipAddress", },
"type": "text", "userAgent": {
"primaryKey": false, "name": "userAgent",
"notNull": false "type": "text",
}, "primaryKey": false,
"userAgent": { "notNull": false
"name": "userAgent", },
"type": "text", "userId": {
"primaryKey": false, "name": "userId",
"notNull": false "type": "text",
}, "primaryKey": false,
"userId": { "notNull": true
"name": "userId", }
"type": "text", },
"primaryKey": false, "indexes": {},
"notNull": true "foreignKeys": {
} "session_userId_user_id_fk": {
}, "name": "session_userId_user_id_fk",
"indexes": {}, "tableFrom": "session",
"foreignKeys": { "tableTo": "user",
"session_userId_user_id_fk": { "columnsFrom": ["userId"],
"name": "session_userId_user_id_fk", "columnsTo": ["id"],
"tableFrom": "session", "onDelete": "cascade",
"tableTo": "user", "onUpdate": "no action"
"columnsFrom": [ }
"userId" },
], "compositePrimaryKeys": {},
"columnsTo": [ "uniqueConstraints": {
"id" "session_token_unique": {
], "name": "session_token_unique",
"onDelete": "cascade", "nullsNotDistinct": false,
"onUpdate": "no action" "columns": ["token"]
} }
}, },
"compositePrimaryKeys": {}, "policies": {},
"uniqueConstraints": { "checkConstraints": {},
"session_token_unique": { "isRLSEnabled": false
"name": "session_token_unique", },
"nullsNotDistinct": false, "public.user": {
"columns": [ "name": "user",
"token" "schema": "",
] "columns": {
} "id": {
}, "name": "id",
"policies": {}, "type": "text",
"checkConstraints": {}, "primaryKey": true,
"isRLSEnabled": false "notNull": true
}, },
"public.user": { "name": {
"name": "user", "name": "name",
"schema": "", "type": "text",
"columns": { "primaryKey": false,
"id": { "notNull": false
"name": "id", },
"type": "text", "email": {
"primaryKey": true, "name": "email",
"notNull": true "type": "text",
}, "primaryKey": false,
"name": { "notNull": true
"name": "name", },
"type": "text", "emailVerified": {
"primaryKey": false, "name": "emailVerified",
"notNull": false "type": "boolean",
}, "primaryKey": false,
"email": { "notNull": false,
"name": "email", "default": false
"type": "text", },
"primaryKey": false, "image": {
"notNull": true "name": "image",
}, "type": "text",
"emailVerified": { "primaryKey": false,
"name": "emailVerified", "notNull": false
"type": "boolean", },
"primaryKey": false, "createdAt": {
"notNull": false, "name": "createdAt",
"default": false "type": "timestamp",
}, "primaryKey": false,
"image": { "notNull": false,
"name": "image", "default": "now()"
"type": "text", },
"primaryKey": false, "updatedAt": {
"notNull": false "name": "updatedAt",
}, "type": "timestamp",
"createdAt": { "primaryKey": false,
"name": "createdAt", "notNull": false,
"type": "timestamp", "default": "now()"
"primaryKey": false, }
"notNull": false, },
"default": "now()" "indexes": {},
}, "foreignKeys": {},
"updatedAt": { "compositePrimaryKeys": {},
"name": "updatedAt", "uniqueConstraints": {
"type": "timestamp", "user_email_unique": {
"primaryKey": false, "name": "user_email_unique",
"notNull": false, "nullsNotDistinct": false,
"default": "now()" "columns": ["email"]
} }
}, },
"indexes": {}, "policies": {},
"foreignKeys": {}, "checkConstraints": {},
"compositePrimaryKeys": {}, "isRLSEnabled": false
"uniqueConstraints": { },
"user_email_unique": { "public.verification": {
"name": "user_email_unique", "name": "verification",
"nullsNotDistinct": false, "schema": "",
"columns": [ "columns": {
"email" "id": {
] "name": "id",
} "type": "text",
}, "primaryKey": true,
"policies": {}, "notNull": true
"checkConstraints": {}, },
"isRLSEnabled": false "identifier": {
}, "name": "identifier",
"public.verification": { "type": "text",
"name": "verification", "primaryKey": false,
"schema": "", "notNull": true
"columns": { },
"id": { "value": {
"name": "id", "name": "value",
"type": "text", "type": "text",
"primaryKey": true, "primaryKey": false,
"notNull": true "notNull": true
}, },
"identifier": { "expiresAt": {
"name": "identifier", "name": "expiresAt",
"type": "text", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": true
}, },
"value": { "createdAt": {
"name": "value", "name": "createdAt",
"type": "text", "type": "timestamp",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": false,
}, "default": "now()"
"expiresAt": { },
"name": "expiresAt", "updatedAt": {
"type": "timestamp", "name": "updatedAt",
"primaryKey": false, "type": "timestamp",
"notNull": true "primaryKey": false,
}, "notNull": false,
"createdAt": { "default": "now()"
"name": "createdAt", }
"type": "timestamp", },
"primaryKey": false, "indexes": {},
"notNull": false, "foreignKeys": {},
"default": "now()" "compositePrimaryKeys": {},
}, "uniqueConstraints": {},
"updatedAt": { "policies": {},
"name": "updatedAt", "checkConstraints": {},
"type": "timestamp", "isRLSEnabled": false
"primaryKey": false, }
"notNull": false, },
"default": "now()" "enums": {},
} "schemas": {},
}, "sequences": {},
"indexes": {}, "roles": {},
"foreignKeys": {}, "policies": {},
"compositePrimaryKeys": {}, "views": {},
"uniqueConstraints": {}, "_meta": {
"policies": {}, "columns": {},
"checkConstraints": {}, "schemas": {},
"isRLSEnabled": false "tables": {}
} }
}, }
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -1,20 +1,20 @@
{ {
"version": "7", "version": "7",
"dialect": "postgresql", "dialect": "postgresql",
"entries": [ "entries": [
{ {
"idx": 0, "idx": 0,
"version": "7", "version": "7",
"when": 1755586325384, "when": 1755586325384,
"tag": "0000_loose_catseye", "tag": "0000_loose_catseye",
"breakpoints": true "breakpoints": true
}, },
{ {
"idx": 1, "idx": 1,
"version": "7", "version": "7",
"when": 1775526538601, "when": 1775526538601,
"tag": "0001_great_sentry", "tag": "0001_great_sentry",
"breakpoints": true "breakpoints": true
} }
] ]
} }

View File

@@ -1,21 +1,21 @@
import { relations } from "drizzle-orm/relations"; import { relations } from "drizzle-orm/relations";
import { user, session, account } from "./schema"; import { user, session, account } from "./schema";
export const sessionRelations = relations(session, ({one}) => ({ export const sessionRelations = relations(session, ({ one }) => ({
user: one(user, { user: one(user, {
fields: [session.userId], fields: [session.userId],
references: [user.id] references: [user.id],
}), }),
})); }));
export const userRelations = relations(user, ({many}) => ({ export const userRelations = relations(user, ({ many }) => ({
sessions: many(session), sessions: many(session),
accounts: many(account), accounts: many(account),
})); }));
export const accountRelations = relations(account, ({one}) => ({ export const accountRelations = relations(account, ({ one }) => ({
user: one(user, { user: one(user, {
fields: [account.userId], fields: [account.userId],
references: [user.id] references: [user.id],
}), }),
})); }));

View File

@@ -1,72 +1,104 @@
import { pgTable, foreignKey, text, timestamp, primaryKey, unique, integer, boolean } from "drizzle-orm/pg-core" import {
import { sql } from "drizzle-orm" pgTable,
foreignKey,
text,
timestamp,
primaryKey,
unique,
integer,
boolean,
} from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
export const session = pgTable(
"session",
export const session = pgTable("session", { {
sessionToken: text().primaryKey().notNull(), sessionToken: text().primaryKey().notNull(),
userId: text().notNull(), userId: text().notNull(),
expires: timestamp({ mode: 'string' }).notNull(), expires: timestamp({ mode: "string" }).notNull(),
}, (table) => [ },
foreignKey({ (table) => [
foreignKey({
columns: [table.userId], columns: [table.userId],
foreignColumns: [user.id], foreignColumns: [user.id],
name: "session_userId_user_id_fk" name: "session_userId_user_id_fk",
}).onDelete("cascade"), }).onDelete("cascade"),
]); ],
);
export const user = pgTable("user", { export const user = pgTable("user", {
id: text().primaryKey().notNull(), id: text().primaryKey().notNull(),
name: text(), name: text(),
email: text().notNull(), email: text().notNull(),
emailVerified: timestamp({ mode: 'string' }), emailVerified: timestamp({ mode: "string" }),
image: text(), image: text(),
}); });
export const verificationToken = pgTable("verificationToken", { export const verificationToken = pgTable(
identifier: text().notNull(), "verificationToken",
token: text().notNull(), {
expires: timestamp({ mode: 'string' }).notNull(), identifier: text().notNull(),
}, (table) => [ token: text().notNull(),
primaryKey({ columns: [table.identifier, table.token], name: "verificationToken_identifier_token_pk"}), expires: timestamp({ mode: "string" }).notNull(),
]); },
(table) => [
primaryKey({
columns: [table.identifier, table.token],
name: "verificationToken_identifier_token_pk",
}),
],
);
export const authenticator = pgTable("authenticator", { export const authenticator = pgTable(
credentialId: text().notNull(), "authenticator",
userId: text().notNull(), {
providerAccountId: text().notNull(), credentialId: text().notNull(),
credentialPublicKey: text().notNull(), userId: text().notNull(),
counter: integer().notNull(), providerAccountId: text().notNull(),
credentialDeviceType: text().notNull(), credentialPublicKey: text().notNull(),
credentialBackedUp: boolean().notNull(), counter: integer().notNull(),
transports: text(), credentialDeviceType: text().notNull(),
}, (table) => [ credentialBackedUp: boolean().notNull(),
foreignKey({ transports: text(),
},
(table) => [
foreignKey({
columns: [table.userId], columns: [table.userId],
foreignColumns: [user.id], foreignColumns: [user.id],
name: "authenticator_userId_user_id_fk" name: "authenticator_userId_user_id_fk",
}).onDelete("cascade"), }).onDelete("cascade"),
primaryKey({ columns: [table.credentialId, table.userId], name: "authenticator_userId_credentialID_pk"}), primaryKey({
unique("authenticator_credentialID_unique").on(table.credentialId), columns: [table.credentialId, table.userId],
]); name: "authenticator_userId_credentialID_pk",
}),
unique("authenticator_credentialID_unique").on(table.credentialId),
],
);
export const account = pgTable("account", { export const account = pgTable(
userId: text().notNull(), "account",
type: text().notNull(), {
provider: text().notNull(), userId: text().notNull(),
providerAccountId: text().notNull(), type: text().notNull(),
refreshToken: text("refresh_token"), provider: text().notNull(),
accessToken: text("access_token"), providerAccountId: text().notNull(),
expiresAt: text("expires_at"), refreshToken: text("refresh_token"),
tokenType: text("token_type"), accessToken: text("access_token"),
scope: text(), expiresAt: text("expires_at"),
idToken: text("id_token"), tokenType: text("token_type"),
sessionState: text("session_state"), scope: text(),
}, (table) => [ idToken: text("id_token"),
foreignKey({ sessionState: text("session_state"),
},
(table) => [
foreignKey({
columns: [table.userId], columns: [table.userId],
foreignColumns: [user.id], foreignColumns: [user.id],
name: "account_userId_user_id_fk" name: "account_userId_user_id_fk",
}).onDelete("cascade"), }).onDelete("cascade"),
primaryKey({ columns: [table.provider, table.providerAccountId], name: "account_provider_providerAccountId_pk"}), primaryKey({
]); columns: [table.provider, table.providerAccountId],
name: "account_provider_providerAccountId_pk",
}),
],
);