Update participant and study API routes

This commit is contained in:
2024-09-25 22:13:29 -04:00
parent 33d36007c8
commit ccc3423953
36 changed files with 1448 additions and 228 deletions

View File

@@ -2,16 +2,14 @@
// https://orm.drizzle.team/docs/sql-schema-declaration
import { pgTableCreator } from "drizzle-orm/pg-core";
import { ColumnBaseConfig, ColumnDataType, SQL, sql } from "drizzle-orm";
import {
index,
pgTable,
serial,
integer,
timestamp,
varchar,
ExtraConfigColumn,
import {
serial,
varchar,
timestamp,
integer,
pgTable
} from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
/**
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
@@ -21,37 +19,30 @@ import {
*/
export const createTable = pgTableCreator((name) => `hristudio_${name}`);
export const posts = createTable(
"post",
{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
createdAt: timestamp("created_at", { withTimezone: true })
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(
() => new Date()
),
},
(example: { name: SQL<unknown> | Partial<ExtraConfigColumn<ColumnBaseConfig<ColumnDataType, string>>>; }) => ({
nameIndex: index("name_idx").on(example.name),
})
);
export const studies = createTable(
"study",
{
id: serial("id").primaryKey(),
title: varchar("title", { length: 256 }).notNull(),
description: varchar("description", { length: 1000 }),
userId: varchar("user_id", { length: 256 }).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(
() => new Date()
),
},
(study: { title: SQL<unknown> | Partial<ExtraConfigColumn<ColumnBaseConfig<ColumnDataType, string>>>; }) => ({
titleIndex: index("title_idx").on(study.title),
})
}
);
export const participants = createTable(
"participant",
{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
studyId: integer("study_id").references(() => studies.id).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
}
);