2021-10-13 17:12:03 +09:00
|
|
|
import {Knex} from 'knex';
|
2020-12-31 03:06:16 +09:00
|
|
|
|
|
|
|
export async function up(knex:Knex) {
|
2022-07-19 23:41:50 +09:00
|
|
|
await knex.schema.createTable("schema_migration",(b)=>{
|
|
|
|
b.string("version");
|
|
|
|
b.boolean("dirty");
|
|
|
|
});
|
|
|
|
|
2020-12-31 03:06:16 +09:00
|
|
|
await knex.schema.createTable("users",(b)=>{
|
|
|
|
b.string("username").primary().comment("user's login id");
|
|
|
|
b.string("password_hash",64).notNullable();
|
|
|
|
b.string("password_salt",64).notNullable();
|
|
|
|
});
|
2021-01-11 23:37:29 +09:00
|
|
|
await knex.schema.createTable("document",(b)=>{
|
2020-12-31 03:06:16 +09:00
|
|
|
b.increments("id").primary();
|
|
|
|
b.string("title").notNullable();
|
|
|
|
b.string("content_type",16).notNullable();
|
|
|
|
b.string("basepath",256).notNullable().comment("directory path for resource");
|
|
|
|
b.string("filename",256).notNullable().comment("filename");
|
2021-01-03 01:36:34 +09:00
|
|
|
b.string("content_hash").nullable();
|
2020-12-31 03:06:16 +09:00
|
|
|
b.json("additional").nullable();
|
2021-01-15 18:43:36 +09:00
|
|
|
b.integer("created_at").notNullable();
|
2022-07-19 23:41:50 +09:00
|
|
|
b.integer("modified_at").notNullable();
|
2021-01-15 18:43:36 +09:00
|
|
|
b.integer("deleted_at");
|
2020-12-31 03:06:16 +09:00
|
|
|
b.index("content_type","content_type_index");
|
|
|
|
});
|
|
|
|
await knex.schema.createTable("tags", (b)=>{
|
|
|
|
b.string("name").primary();
|
|
|
|
b.text("description");
|
|
|
|
});
|
2021-01-11 23:37:29 +09:00
|
|
|
await knex.schema.createTable("doc_tag_relation",(b)=>{
|
|
|
|
b.integer("doc_id").unsigned().notNullable();
|
2020-12-31 03:06:16 +09:00
|
|
|
b.string("tag_name").notNullable();
|
2021-01-11 23:37:29 +09:00
|
|
|
b.foreign("doc_id").references("document.id");
|
2020-12-31 03:06:16 +09:00
|
|
|
b.foreign("tag_name").references("tags.name");
|
2021-01-11 23:37:29 +09:00
|
|
|
b.primary(["doc_id","tag_name"]);
|
2020-12-31 03:06:16 +09:00
|
|
|
});
|
|
|
|
await knex.schema.createTable("permissions",b=>{
|
2021-01-10 04:27:50 +09:00
|
|
|
b.string('username').notNullable();
|
2020-12-31 03:06:16 +09:00
|
|
|
b.string("name").notNullable();
|
|
|
|
b.primary(["username","name"]);
|
|
|
|
b.foreign('username').references('users.username');
|
|
|
|
});
|
|
|
|
//create admin account.
|
|
|
|
await knex.insert({
|
|
|
|
username:"admin",
|
|
|
|
password_hash:"unchecked",
|
|
|
|
password_salt:"unchecked"
|
|
|
|
}).into('users');
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function down(knex:Knex) {
|
2022-07-19 23:41:50 +09:00
|
|
|
throw new Error('Downward migrations are not supported. Restore from backup.');
|
2020-12-31 03:06:16 +09:00
|
|
|
};
|