1.1.0 #29
@@ -0,0 +1,41 @@
|
|||||||
|
import { Kysely, sql } from 'kysely'
|
||||||
|
import { addDefaultColumns } from '../db';
|
||||||
|
|
||||||
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
// TABLE: ACCOUNTS
|
||||||
|
await db.schema.createTable("accounts")
|
||||||
|
.addColumn("id", "uuid", (cb) => cb.primaryKey().defaultTo(sql`gen_random_uuid()`))
|
||||||
|
.addColumn("created_at", "timestamptz", (cb) => cb
|
||||||
|
.notNull()
|
||||||
|
.defaultTo(sql`now()`)
|
||||||
|
)
|
||||||
|
.addColumn("discord_id", "text", (cb) => cb.unique())
|
||||||
|
.addColumn("email", "text", (cb) => cb.unique())
|
||||||
|
.addColumn("name", "text", (cb) => cb.notNull().defaultTo(""))
|
||||||
|
.addColumn("gender", "text", (cb) => cb.notNull())
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
// TABLE: ASSESSMENTS
|
||||||
|
await db.schema.createTable("assessments")
|
||||||
|
.$call(addDefaultColumns)
|
||||||
|
.addColumn("account_id", "uuid")
|
||||||
|
.addColumn("name", "text", (cb) => cb.notNull().defaultTo(""))
|
||||||
|
.addColumn("gender", "text", (cb) => cb.notNull())
|
||||||
|
.addColumn("age", "numeric", (cb) => cb.notNull())
|
||||||
|
.addColumn("weight", "numeric", (cb) => cb.notNull())
|
||||||
|
.addForeignKeyConstraint(
|
||||||
|
"fk_assessments_account_id",
|
||||||
|
["account_id"],
|
||||||
|
"accounts",
|
||||||
|
["id"],
|
||||||
|
(cb) => cb.onDelete("cascade")
|
||||||
|
)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
|
// TABLE: ASSESSMENTS
|
||||||
|
await db.schema.dropTable("assessments").ifExists().execute()
|
||||||
|
// TABLE: ACCOUNTS
|
||||||
|
await db.schema.dropTable("accounts").ifExists().execute()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user