activitypress/migrations/20231225130928_init.js

97 lines
3.6 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.string("public_key").notNullable();
table.string("private_key").notNullable();
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();
table.timestamps(true, false, false);
table.index(["collection_types_id", "articles_id"]);
table.index(["collection_types_id", "users_id"]);
})
.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);
})
.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);
})
.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("remote_users")
.dropTableIfExists("outboxes")
.dropTableIfExists("collections")
.dropTableIfExists("collection_types")
.dropTableIfExists("articles")
.dropTableIfExists("users")
;
};