Setting up db migrations
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Kysely, sql } from 'kysely'
|
||||
import { addDefaultColumns } from '../db';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
// TABLE: PRODUCT_SYNCS
|
||||
await db.schema.createTable("product_syncs")
|
||||
.$call(addDefaultColumns)
|
||||
.addColumn("printful_product_id_filter", sql`integer[]`)
|
||||
.addColumn("syncing_printful_product_ids", sql`integer[]`, (cb) => cb
|
||||
.notNull()
|
||||
.defaultTo(sql`'{}'::integer[]`)
|
||||
)
|
||||
.addColumn("started_at", "timestamptz")
|
||||
.addColumn("ended_at", "timestamptz")
|
||||
.addColumn("has_failed", "boolean", (cb) => cb.notNull().defaultTo(false))
|
||||
.execute()
|
||||
|
||||
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
||||
await db.schema.createIndex("idx_one_active_product_sync")
|
||||
.on("product_syncs")
|
||||
.unique()
|
||||
.column("ended_at")
|
||||
.where(sql.ref("started_at"), "is not", null)
|
||||
.where("ended_at", "is", null)
|
||||
.nullsNotDistinct()
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
// TABLE: PRODUCT_SYNCS
|
||||
await db.schema.dropTable("product_syncs").ifExists().execute()
|
||||
|
||||
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
||||
await db.schema.dropIndex("idx_one_active_product_sync").ifExists().execute();
|
||||
}
|
||||
Reference in New Issue
Block a user