diff --git a/package.json b/package.json index 124a1ea..7df81c6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "build": "next build", "start": "next start", "db:generate": "drizzle-kit generate", - "db:push": "drizzle-kit migrate" + "db:push": "drizzle-kit migrate", + "db:studio": "drizzle-kit studio" }, "dependencies": { "@better-auth/drizzle-adapter": "^1.5.4", diff --git a/src/lib/model/experiment_calibration.ts b/src/lib/model/experiment_calibration.ts new file mode 100644 index 0000000..c6cffd5 --- /dev/null +++ b/src/lib/model/experiment_calibration.ts @@ -0,0 +1,32 @@ +import { sqliteTable, text, integer, uniqueIndex } from 'drizzle-orm/sqlite-core'; +import { relations, sql } from 'drizzle-orm'; +import { experiment } from './experiment'; + +export const experiment_calibration = sqliteTable( + 'experiment_calibration', + { + id: integer('id').primaryKey({ autoIncrement: true }), + experimentId: integer('experiment_id') + .references(() => experiment.id), + dialectLabel: text('dialect_label').notNull(), // e.g. 'ch_be', 'ch_zh', … + order: integer('order').notNull(), // order of the calibration items + file: text('file').notNull(), // path to the audio file for calibration + createdAt: integer('created_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`), + updatedAt: integer('updated_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`) + .$onUpdate(() => sql`(unixepoch())`), + }, +); + +export const experiment_calibrationRelations = relations(experiment_calibration, ({ one }) => ({ + experiment: one(experiment, { + fields: [experiment_calibration.experimentId], + references: [experiment.id], + }) +})); + +export type ExperimentCalibration = typeof experiment_calibration.$inferSelect; +export type NewExperimentCalibration = typeof experiment_calibration.$inferInsert; diff --git a/src/lib/model/participant.ts b/src/lib/model/participant.ts new file mode 100644 index 0000000..e95eec8 --- /dev/null +++ b/src/lib/model/participant.ts @@ -0,0 +1,34 @@ +import { sqliteTable, text, integer, uniqueIndex } from 'drizzle-orm/sqlite-core'; +import { relations, sql } from 'drizzle-orm'; +import { dataset_entry } from './dataset_entry'; +import { experiment } from './experiment'; + +export const participant = sqliteTable( + 'participant', + { + id: integer('id').primaryKey({ autoIncrement: true }), + experimentId: integer('experiment_id').references(() => experiment.id), + userId: text('user_id').notNull(), + calibrationAnswers: text('calibration_answers', { mode: 'json' }), + createdAt: integer('created_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`), + updatedAt: integer('updated_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`) + .$onUpdate(() => sql`(unixepoch())`), + }, + (table) => ({ + uniqueParticipant: uniqueIndex('unique_participant').on(table.experimentId, table.userId), + }) +); + +export const participantRelations = relations(participant, ({ one }) => ({ + experiment: one(experiment, { + fields: [participant.experimentId], + references: [experiment.id], + }) +})); + +export type Participant = typeof participant.$inferSelect; +export type NewParticipant = typeof participant.$inferInsert;