81 lines
2.9 KiB
JavaScript
81 lines
2.9 KiB
JavaScript
|
/**
|
||
|
* @param { import("knex").Knex } knex
|
||
|
* @returns { Promise<void> }
|
||
|
*/
|
||
|
export const up = async function (knex) {
|
||
|
return knex.schema
|
||
|
.createTable("users", (table) => {
|
||
|
table.increments("id");
|
||
|
table.string("name").notNullable();
|
||
|
table.string("nickname").notNullable();
|
||
|
table.string("bio");
|
||
|
table.boolean("deleted").notNullable();
|
||
|
table.timestamps(true, false, false);
|
||
|
})
|
||
|
.createTable("articles", (table) => {
|
||
|
table.increments("id");
|
||
|
table.string("title").notNullable();
|
||
|
table.string("slug").notNullable().unique();
|
||
|
table.string("file").notNullable().unique();
|
||
|
table.integer("users_id");
|
||
|
table.foreign("users_id").references("users.id").onDelete("CASCADE");
|
||
|
table.boolean("deleted").notNullable();
|
||
|
table.timestamps(true, false, false);
|
||
|
})
|
||
|
.createTable("collection_types", (table) => {
|
||
|
table.integer("id").unsigned().primary();
|
||
|
table.string("name").notNullable();
|
||
|
})
|
||
|
.createTable("collections", (table) => {
|
||
|
table.increments("id");
|
||
|
table.integer("collection_types_id").notNullable();
|
||
|
table.foreign("collection_types_id").references("collection_types.id");
|
||
|
table.integer("articles_id");
|
||
|
table.foreign("articles_id").references("articles.id").onDelete("CASCADE");
|
||
|
table.integer("users_id");
|
||
|
table.foreign("users_id").references("users.id").onDelete("CASCADE");
|
||
|
table.string("value").notNullable();
|
||
|
})
|
||
|
.createTable("outboxes", (table) => {
|
||
|
table.increments("id");
|
||
|
table.integer("users_id");
|
||
|
table.foreign("users_id").references("users.id").onDelete("CASCADE");
|
||
|
table.string("verb").notNullable();
|
||
|
table.integer("articles_id");
|
||
|
table.foreign("articles_id").references("articles.id").onDelete("CASCADE");
|
||
|
table.timestamps(true, false, false);
|
||
|
})
|
||
|
.then(() => {
|
||
|
// Hardcoding these so they can be referenced by constants in code.
|
||
|
knex("collection_types").insert([
|
||
|
{
|
||
|
id: 0,
|
||
|
name: "followers"
|
||
|
},
|
||
|
{
|
||
|
id: 1,
|
||
|
name: "likes"
|
||
|
},
|
||
|
{
|
||
|
id: 2,
|
||
|
name: "announcements"
|
||
|
}
|
||
|
]);
|
||
|
});
|
||
|
;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @param { import("knex").Knex } knex
|
||
|
* @returns { Promise<void> }
|
||
|
*/
|
||
|
export const down = function (knex) {
|
||
|
return knex.schema
|
||
|
.dropTableIfExists("outboxes")
|
||
|
.dropTableIfExists("collections")
|
||
|
.dropTableIfExists("collection_types")
|
||
|
.dropTableIfExists("articles")
|
||
|
.dropTableIfExists("users")
|
||
|
;
|
||
|
};
|