68 lines
2.4 KiB
JavaScript
68 lines
2.4 KiB
JavaScript
import {
|
|
integer,
|
|
index,
|
|
jsonb,
|
|
pgTable,
|
|
serial,
|
|
timestamp,
|
|
uniqueIndex,
|
|
varchar,
|
|
} from 'drizzle-orm/pg-core'
|
|
|
|
export const users = pgTable('users', {
|
|
id: serial('id').primaryKey(),
|
|
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
passwordHash: varchar('password_hash', { length: 255 }).notNull(),
|
|
nickname: varchar('nickname', { length: 60 }).notNull(),
|
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull(),
|
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull(),
|
|
})
|
|
|
|
export const authSessions = pgTable(
|
|
'auth_sessions',
|
|
{
|
|
id: serial('id').primaryKey(),
|
|
userId: integer('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
tokenHash: varchar('token_hash', { length: 255 }).notNull().unique(),
|
|
expiresAt: timestamp('expires_at', { withTimezone: true }).notNull(),
|
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull(),
|
|
},
|
|
(table) => ({
|
|
userIndex: index('auth_sessions_user_id_idx').on(table.userId),
|
|
}),
|
|
)
|
|
|
|
export const plannerEntries = pgTable(
|
|
'planner_entries',
|
|
{
|
|
id: serial('id').primaryKey(),
|
|
userId: integer('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
entryDate: varchar('entry_date', { length: 10 }).notNull(),
|
|
payload: jsonb('payload').notNull(),
|
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull(),
|
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull(),
|
|
},
|
|
(table) => ({
|
|
userDateUnique: uniqueIndex('planner_entries_user_date_unique').on(table.userId, table.entryDate),
|
|
userIndex: index('planner_entries_user_id_idx').on(table.userId),
|
|
}),
|
|
)
|
|
|
|
export const goals = pgTable(
|
|
'goals',
|
|
{
|
|
id: serial('id').primaryKey(),
|
|
userId: integer('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
title: varchar('title', { length: 120 }).notNull(),
|
|
targetDate: varchar('target_date', { length: 10 }).notNull(),
|
|
activeFrom: varchar('active_from', { length: 10 }),
|
|
activeUntil: varchar('active_until', { length: 10 }),
|
|
color: varchar('color', { length: 32 }).notNull().default('#1c1917'),
|
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull(),
|
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull(),
|
|
},
|
|
(table) => ({
|
|
userIndex: index('goals_user_id_idx').on(table.userId),
|
|
}),
|
|
)
|