added calibration model
This commit is contained in:
32
src/lib/model/experiment_calibration.ts
Normal file
32
src/lib/model/experiment_calibration.ts
Normal file
@@ -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;
|
||||
34
src/lib/model/participant.ts
Normal file
34
src/lib/model/participant.ts
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user