54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
|
|
|
export const users = sqliteTable('users', {
|
|
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
name: text('name').notNull(),
|
|
username: text('username').notNull().unique(),
|
|
passwordHash: text('password_hash').notNull(),
|
|
role: text('role').notNull(), // 'admin' | 'shift_manager' | 'volunteer'
|
|
createdAt: integer('created_at').notNull().$defaultFn(() => Date.now())
|
|
});
|
|
|
|
export const sessions = sqliteTable('sessions', {
|
|
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
userId: text('user_id')
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
|
expiresAt: integer('expires_at').notNull()
|
|
});
|
|
|
|
export const beneficiaries = sqliteTable('beneficiaries', {
|
|
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
number: integer('number').notNull().unique(),
|
|
name: text('name').notNull(),
|
|
contact: text('contact').notNull(),
|
|
householdSize: integer('household_size').notNull().default(1),
|
|
observations: text('observations'),
|
|
status: text('status').notNull().default('ativo'), // 'ativo' | 'inativo'
|
|
createdAt: integer('created_at').notNull().$defaultFn(() => Date.now()),
|
|
updatedAt: integer('updated_at').notNull().$defaultFn(() => Date.now())
|
|
});
|
|
|
|
export const shifts = sqliteTable('shifts', {
|
|
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
code: text('code').notNull().unique(), // 'T1', 'T2', 'T3'
|
|
startTime: text('start_time').notNull(), // '14:30'
|
|
endTime: text('end_time').notNull(), // '16:30'
|
|
days: text('days').notNull(), // '2,4' (Tuesday, Thursday)
|
|
createdAt: integer('created_at').notNull().$defaultFn(() => Date.now()),
|
|
updatedAt: integer('updated_at').notNull().$defaultFn(() => Date.now())
|
|
});
|
|
|
|
export const deliveries = sqliteTable('deliveries', {
|
|
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
beneficiaryId: text('beneficiary_id')
|
|
.notNull()
|
|
.references(() => beneficiaries.id, { onDelete: 'cascade' }),
|
|
shiftId: text('shift_id')
|
|
.notNull()
|
|
.references(() => shifts.id, { onDelete: 'cascade' }),
|
|
date: text('date').notNull(), // 'YYYY-MM-DD'
|
|
createdAt: integer('created_at').notNull().$defaultFn(() => Date.now())
|
|
});
|
|
|