Restructuring calculator data in database and improve api surface
This commit is contained in:
@@ -39,7 +39,6 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.$call(addDefaultColumns)
|
||||
.addColumn("name", "text", (cb) => cb.notNull().defaultTo(""))
|
||||
.addColumn("params", "jsonb", (cb) => cb.notNull())
|
||||
.addColumn("is_selected", "boolean", (cb) => cb.notNull().defaultTo(false))
|
||||
.addColumn("dataset_id", "bigint", (cb) => cb.notNull())
|
||||
.addForeignKeyConstraint(
|
||||
"fk_standards_configs_dataset_id",
|
||||
@@ -50,12 +49,18 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
)
|
||||
.execute();
|
||||
|
||||
// INDEX: ONE_SELECTED_STANDARDS_CONFIG
|
||||
await db.schema.createIndex("idx_one_selected_standards_config")
|
||||
.on("standards_configs")
|
||||
.column("is_selected")
|
||||
.unique()
|
||||
.where("is_selected", "=", true)
|
||||
// TABLE: CALCULATORS
|
||||
await db.schema.createTable("calculators")
|
||||
.$call(addDefaultColumns)
|
||||
.addColumn("name", "text", (cb) => cb.notNull().unique())
|
||||
.addColumn("standards_config_id", "bigint", (cb) => cb.notNull())
|
||||
.addForeignKeyConstraint(
|
||||
"fk_calculators_standards_config_id",
|
||||
["standards_config_id"],
|
||||
"standards_configs",
|
||||
["id"],
|
||||
(cb) => cb.onDelete("restrict")
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
||||
@@ -66,8 +71,8 @@ export async function down(db: Kysely<any>): Promise<void> {
|
||||
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
||||
await db.schema.dropIndex("idx_one_active_product_sync").ifExists().execute();
|
||||
|
||||
// INDEX: ONE_SELECTED_STANDARDS_CONFIG
|
||||
await db.schema.dropIndex("idx_one_selected_standards_config").ifExists().execute();
|
||||
// TABLE: CALCULATORS
|
||||
await db.schema.dropTable("calculators").ifExists().execute()
|
||||
|
||||
// TABLE: STANDARDS_CONFIGS
|
||||
await db.schema.dropTable("standards_configs").ifExists().execute()
|
||||
|
||||
Reference in New Issue
Block a user