Add user authentication and role management
This commit is contained in:
34
db/schema.ts
34
db/schema.ts
@@ -186,3 +186,37 @@ export const collectionRuns = sqliteTable(
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
export const users = sqliteTable(
|
||||
"users",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
username: text("username").notNull(),
|
||||
passwordHash: text("password_hash").notNull(),
|
||||
passwordSalt: text("password_salt").notNull(),
|
||||
passwordIterations: integer("password_iterations").notNull(),
|
||||
role: text("role").notNull(),
|
||||
createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("users_username_idx").on(table.username),
|
||||
uniqueIndex("users_single_super_admin_idx")
|
||||
.on(table.role)
|
||||
.where(sql`${table.role} = 'super_admin'`),
|
||||
],
|
||||
);
|
||||
|
||||
export const authSessions = sqliteTable(
|
||||
"auth_sessions",
|
||||
{
|
||||
tokenHash: text("token_hash").primaryKey(),
|
||||
userId: text("user_id").notNull(),
|
||||
expiresAt: text("expires_at").notNull(),
|
||||
createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
|
||||
},
|
||||
(table) => [
|
||||
index("auth_sessions_user_id_idx").on(table.userId),
|
||||
index("auth_sessions_expires_at_idx").on(table.expiresAt),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user