2023-12-25 18:49:16 +00:00
|
|
|
/**
|
|
|
|
* @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");
|
2023-12-26 02:33:18 +00:00
|
|
|
table.string("public_key").notNullable();
|
|
|
|
table.string("private_key").notNullable();
|
2023-12-25 18:49:16 +00:00
|
|
|
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();
|
2023-12-26 02:33:18 +00:00
|
|
|
table.timestamps(true, false, false);
|
|
|
|
|
|
|
|
table.index(["collection_types_id", "articles_id"]);
|
|
|
|
table.index(["collection_types_id", "users_id"]);
|
2023-12-25 18:49:16 +00:00
|
|
|
})
|
|
|
|
.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);
|
|
|
|
})
|
2023-12-26 02:33:18 +00:00
|
|
|
.createTable("remote_users", (table) => {
|
|
|
|
table.increments("id");
|
|
|
|
table.string("actor").notNullable().unique();
|
|
|
|
table.string("nickname").notNullable();
|
|
|
|
table.string("name");
|
|
|
|
table.string("inbox");
|
|
|
|
table.string("shared_inbox");
|
|
|
|
table.timestamps(true, false, false);
|
|
|
|
})
|
2023-12-25 18:49:16 +00:00
|
|
|
.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
|
2023-12-26 02:33:18 +00:00
|
|
|
.dropTableIfExists("remote_users")
|
2023-12-25 18:49:16 +00:00
|
|
|
.dropTableIfExists("outboxes")
|
|
|
|
.dropTableIfExists("collections")
|
|
|
|
.dropTableIfExists("collection_types")
|
|
|
|
.dropTableIfExists("articles")
|
|
|
|
.dropTableIfExists("users")
|
|
|
|
;
|
|
|
|
};
|