fixed the auth update breaking db migration
This commit is contained in:
@@ -1,100 +1,130 @@
|
||||
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
import { sql } from "drizzle-orm/sql";
|
||||
import {
|
||||
index,
|
||||
integer,
|
||||
sqliteTable,
|
||||
text,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const user = sqliteTable('user', {
|
||||
banExpires: integer('ban_expires', { mode: 'timestamp_ms' }),
|
||||
banned: integer('banned', { mode: 'boolean' }).default(false),
|
||||
banReason: text('ban_reason'),
|
||||
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
|
||||
displayUsername: text('display_username'),
|
||||
email: text('email').notNull().unique(),
|
||||
emailVerified: integer('email_verified', { mode: 'boolean' }).default(false).notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
image: text('image'),
|
||||
name: text('name').notNull(),
|
||||
role: text('role'),
|
||||
twoFactorEnabled: integer('two_factor_enabled', { mode: 'boolean' }).default(false),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
username: text('username').unique()
|
||||
export const user = sqliteTable("user", {
|
||||
banExpires: integer("ban_expires", { mode: "timestamp_ms" }),
|
||||
banned: integer("banned", { mode: "boolean" }).default(false),
|
||||
banReason: text("ban_reason"),
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
displayUsername: text("display_username"),
|
||||
email: text("email").notNull().unique(),
|
||||
emailVerified: integer("email_verified", { mode: "boolean" })
|
||||
.default(false)
|
||||
.notNull(),
|
||||
id: text("id").primaryKey(),
|
||||
image: text("image"),
|
||||
name: text("name").notNull(),
|
||||
role: text("role"),
|
||||
twoFactorEnabled: integer("two_factor_enabled", { mode: "boolean" }).default(
|
||||
false,
|
||||
),
|
||||
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||
.notNull(),
|
||||
username: text("username").unique(),
|
||||
});
|
||||
|
||||
export const session = sqliteTable(
|
||||
'session',
|
||||
{
|
||||
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
|
||||
expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
impersonatedBy: text('impersonated_by'),
|
||||
ipAddress: text('ip_address'),
|
||||
token: text('token').notNull().unique(),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
userAgent: text('user_agent'),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: 'cascade' })
|
||||
},
|
||||
(table) => [index('session_userId_idx').on(table.userId)]
|
||||
"session",
|
||||
{
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
||||
id: text("id").primaryKey(),
|
||||
impersonatedBy: text("impersonated_by"),
|
||||
ipAddress: text("ip_address"),
|
||||
token: text("token").notNull().unique(),
|
||||
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||
.notNull(),
|
||||
userAgent: text("user_agent"),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => [index("session_userId_idx").on(table.userId)],
|
||||
);
|
||||
|
||||
export const account = sqliteTable(
|
||||
'account',
|
||||
{
|
||||
accessToken: text('access_token'),
|
||||
accessTokenExpiresAt: integer('access_token_expires_at', {
|
||||
mode: 'timestamp_ms'
|
||||
}),
|
||||
accountId: text('account_id').notNull(),
|
||||
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
idToken: text('id_token'),
|
||||
password: text('password'),
|
||||
providerId: text('provider_id').notNull(),
|
||||
refreshToken: text('refresh_token'),
|
||||
refreshTokenExpiresAt: integer('refresh_token_expires_at', {
|
||||
mode: 'timestamp_ms'
|
||||
}),
|
||||
scope: text('scope'),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: 'cascade' })
|
||||
},
|
||||
(table) => [index('account_userId_idx').on(table.userId)]
|
||||
"account",
|
||||
{
|
||||
accessToken: text("access_token"),
|
||||
accessTokenExpiresAt: integer("access_token_expires_at", {
|
||||
mode: "timestamp_ms",
|
||||
}),
|
||||
accountId: text("account_id").notNull(),
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
id: text("id").primaryKey(),
|
||||
idToken: text("id_token"),
|
||||
issuer: text("issuer").notNull(),
|
||||
password: text("password"),
|
||||
providerId: text("provider_id").notNull(),
|
||||
refreshToken: text("refresh_token"),
|
||||
refreshTokenExpiresAt: integer("refresh_token_expires_at", {
|
||||
mode: "timestamp_ms",
|
||||
}),
|
||||
scope: text("scope"),
|
||||
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||
.notNull(),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("account_issuer_accountId_uidx").on(
|
||||
table.issuer,
|
||||
table.accountId,
|
||||
),
|
||||
index("account_userId_idx").on(table.userId),
|
||||
],
|
||||
);
|
||||
|
||||
export const verification = sqliteTable(
|
||||
'verification',
|
||||
{
|
||||
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
|
||||
expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
identifier: text('identifier').notNull(),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
value: text('value').notNull()
|
||||
},
|
||||
(table) => [index('verification_identifier_idx').on(table.identifier)]
|
||||
"verification",
|
||||
{
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
||||
id: text("id").primaryKey(),
|
||||
identifier: text("identifier").notNull(),
|
||||
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||
.notNull(),
|
||||
value: text("value").notNull(),
|
||||
},
|
||||
(table) => [index("verification_identifier_idx").on(table.identifier)],
|
||||
);
|
||||
|
||||
export const twoFactor = sqliteTable(
|
||||
'two_factor',
|
||||
{
|
||||
backupCodes: text('backup_codes').notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
secret: text('secret').notNull(),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: 'cascade' }),
|
||||
verified: integer('verified', { mode: 'boolean' }).default(true)
|
||||
},
|
||||
(table) => [
|
||||
index('twoFactor_secret_idx').on(table.secret),
|
||||
index('twoFactor_userId_idx').on(table.userId)
|
||||
]
|
||||
);
|
||||
"two_factor",
|
||||
{
|
||||
backupCodes: text("backup_codes").notNull(),
|
||||
failedVerificationCount: integer("failed_verification_count").default(0),
|
||||
id: text("id").primaryKey(),
|
||||
lockedUntil: integer("locked_until", { mode: "timestamp_ms" }),
|
||||
secret: text("secret").notNull(),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
verified: integer("verified", { mode: "boolean" }).default(true),
|
||||
},
|
||||
(table) => [
|
||||
index("twoFactor_secret_idx").on(table.secret),
|
||||
index("twoFactor_userId_idx").on(table.userId),
|
||||
],
|
||||
);
|
||||
Reference in New Issue
Block a user