You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.5 KiB
JavaScript
62 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
module.exports.up = function(knex, Promise) {
|
|
return knex.schema
|
|
.createTable("srap_items", (table) => {
|
|
// NOTE: The id is the primary name for the item
|
|
table.text("id").notNullable().primary();
|
|
table.jsonb("data").notNullable();
|
|
// NOTE: created_by references an alias, and it is allowed for this to be a broken/dead reference!
|
|
table.text("created_by");
|
|
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
|
|
table.timestamp("updated_at").notNullable(); // FIXME: Maybe should be nullable?
|
|
table.timestamp("metadata_updated_at");
|
|
})
|
|
.createTable("srap_aliases", (table) => {
|
|
table.text("alias").notNullable().primary();
|
|
table.text("item_id").references("srap_items.id").notNullable().onUpdate("CASCADE").onDelete("CASCADE");
|
|
})
|
|
.createTable("srap_tags", (table) => {
|
|
table.bigIncrements("id").primary();
|
|
table.text("item_id").references("srap_items.id").notNullable().onUpdate("CASCADE").onDelete("CASCADE");
|
|
table.text("name").notNullable().index();
|
|
})
|
|
.createTable("srap_task_results", (table) => {
|
|
table.primary([ "task", "item_id" ]);
|
|
table.text("task").notNullable();
|
|
table.text("item_id").references("srap_items.id").notNullable().onUpdate("CASCADE").onDelete("CASCADE");
|
|
table.text("task_version").notNullable();
|
|
table.jsonb("metadata").notNullable();
|
|
table.boolean("is_successful").notNullable();
|
|
table.boolean("is_invalidated").notNullable().defaultTo(false);
|
|
table.timestamp("updated_at").notNullable().defaultTo(knex.fn.now());
|
|
table.timestamp("expires_at");
|
|
})
|
|
.createTable("srap_tasks_in_progress", (table) => {
|
|
table.primary([ "task", "item_id" ]);
|
|
table.text("task").notNullable();
|
|
table.text("item_id").references("srap_items.id").notNullable().onUpdate("CASCADE").onDelete("CASCADE");
|
|
table.timestamp("started_at").notNullable().defaultTo(knex.fn.now());
|
|
})
|
|
.createTable("srap_failures", (table) => {
|
|
table.bigIncrements("id").primary();
|
|
table.text("task").notNullable();
|
|
table.text("item_id").notNullable();
|
|
table.timestamp("occurred_at").notNullable().defaultTo(knex.fn.now());
|
|
|
|
table.foreign([ "task", "item_id" ])
|
|
.references([ "task", "item_id" ])
|
|
.inTable("srap_task_results");
|
|
});
|
|
}
|
|
|
|
module.exports.down = function(knex, Promise) {
|
|
return knex.schema
|
|
.dropTable("srap_failures")
|
|
.dropTable("srap_tasks_in_progress")
|
|
.dropTable("srap_task_results")
|
|
.dropTable("srap_tags")
|
|
.dropTable("srap_aliases")
|
|
.dropTable("srap_items");
|
|
}
|