diff --git a/drizzle/schema.ts b/drizzle/schema.ts index 7abf094a..14c140fc 100644 --- a/drizzle/schema.ts +++ b/drizzle/schema.ts @@ -1,4 +1,11 @@ -import { pgTable, serial, text } from "drizzle-orm/pg-core"; +import { + date, + integer, + json, + pgTable, + serial, + text, +} from "drizzle-orm/pg-core"; export const organizations = pgTable("organizations", { id: serial("id").primaryKey(), @@ -17,9 +24,56 @@ export const projects = pgTable("projects", { export const protocols = pgTable("protocols", { id: serial("id").primaryKey(), + hash: text("hash").notNull().unique(), name: text("name").notNull(), - slug: text("slug").notNull().unique(), + schemaVersion: integer("schema_version").notNull(), + description: text("description"), + importedAt: date("imported_at").notNull().defaultNow(), + lastModified: date("last_modified").notNull(), + stages: json("stages").notNull(), + codebook: json("codebook").notNull(), projectId: serial("project_id").references(() => projects.id, { onDelete: "cascade", }), }); + +export const protocolsAssets = pgTable("protocols_assets", { + protocolId: serial("protocol_id").references(() => protocols.id, { + onDelete: "cascade", + }), + assetId: text("asset_id").references(() => assets.assetId, { + onDelete: "cascade", + }), +}); + +export const assets = pgTable("assets", { + key: text("key").primaryKey(), + assetId: text("asset_id").notNull().unique(), + name: text("name").notNull(), + type: text("type").notNull(), + url: text("url").notNull(), + size: integer("size").notNull(), +}); + +export const interviews = pgTable("interviews", { + id: text("id").primaryKey(), + startTime: date("start_time").notNull().defaultNow(), + finishTime: date("finish_time"), + exportTime: date("export_time"), + lastUpdated: date("last_updated").notNull().defaultNow(), + network: json("network").notNull(), + participantId: text("participant_id").references(() => participants.id, { + onDelete: "cascade", + }), + protocolId: text("protocol_id").references(() => protocols.id, { + onDelete: "cascade", + }), + currentStep: integer("current_step").notNull().default(0), + stageMetadata: json("stage_metadata"), +}); + +export const participants = pgTable("participants", { + id: text("id").primaryKey(), + identifier: text("identifier").notNull().unique(), + label: text("label"), +});