Files
cog-socket/src/lib/server/db/schema.ts
2025-07-16 16:46:27 +02:00

51 lines
1.8 KiB
TypeScript

import { pgTable, serial, integer, text, timestamp, boolean, pgEnum } from 'drizzle-orm/pg-core';
export const user = pgTable('user', {
id: text('id').primaryKey(),
age: integer('age'),
username: text('username').notNull().unique(),
passwordHash: text('password_hash').notNull()
});
export const session = pgTable('session', {
id: text('id').primaryKey(),
userId: text('user_id')
.notNull()
.references(() => user.id),
expiresAt: timestamp('expires_at', { withTimezone: true, mode: 'date' }).notNull()
});
export const experimentTypeEnum = pgEnum('experiment_type', ['jsPsych', 'PsychoJS']);
export const experiment = pgTable('experiment', {
id: text('id').primaryKey(),
name: text('name').notNull(),
description: text('description'),
createdBy: text('created_by')
.notNull()
.references(() => user.id),
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),
multiplayer: boolean('multiplayer').default(false).notNull(),
type: experimentTypeEnum('type').notNull()
});
export const sessionStatusEnum = pgEnum('session_status', ['in progress', 'completed', 'aborted']);
export const experimentSession = pgTable('experiment_session', {
id: text('id').primaryKey(),
experimentId: text('experiment_id')
.notNull()
.references(() => experiment.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'date' }).notNull(),
status: sessionStatusEnum('status').notNull(),
externalId: text('external_id'),
ipAddress: text('ip_address'),
userAgent: text('user_agent')
});
export type Session = typeof session.$inferSelect;
export type User = typeof user.$inferSelect;
export type Experiment = typeof experiment.$inferSelect;
export type ExperimentSession = typeof experimentSession.$inferSelect;