Squashed commit of the following:

commit df4b0378571708086a276e49ac8630095e08b0b7
Author: Pitu <heyitspitu@gmail.com>
Date:   Sun Dec 27 03:00:17 2020 +0900

    feat: move database modification to a new migration file
This commit is contained in:
Pitu 2020-12-27 03:02:14 +09:00
parent 726f47f301
commit 68634418e1
2 changed files with 36 additions and 15 deletions

View File

@ -1,11 +1,11 @@
exports.up = async knex => {
await knex.schema.createTable('users', table => {
table.increments();
table.string('username').unique();
table.string('username');
table.text('password');
table.boolean('enabled');
table.boolean('isAdmin');
table.string('apiKey').unique();
table.string('apiKey');
table.timestamp('passwordEditedAt');
table.timestamp('apiKeyEditedAt');
table.timestamp('createdAt');
@ -16,12 +16,9 @@ exports.up = async knex => {
table.increments();
table.integer('userId');
table.string('name');
table.boolean('nsfw').defaultTo(false);
table.timestamp('zippedAt');
table.timestamp('createdAt');
table.timestamp('editedAt');
table.unique(['userId', 'name']);
});
await knex.schema.createTable('files', table => {
@ -31,7 +28,6 @@ exports.up = async knex => {
table.string('original');
table.string('type');
table.integer('size');
table.boolean('nsfw').defaultTo(false);
table.string('hash');
table.string('ip');
table.timestamp('createdAt');
@ -49,22 +45,18 @@ exports.up = async knex => {
table.timestamp('expiresAt');
table.timestamp('createdAt');
table.timestamp('editedAt');
table.unique(['userId', 'albumId', 'identifier']);
});
await knex.schema.createTable('albumsFiles', table => {
table.increments();
table.integer('albumId');
table.integer('fileId');
table.unique(['albumId', 'fileId']);
});
await knex.schema.createTable('albumsLinks', table => {
table.increments();
table.integer('albumId');
table.integer('linkId').unique();
table.integer('linkId');
});
await knex.schema.createTable('tags', table => {
@ -74,16 +66,12 @@ exports.up = async knex => {
table.string('name');
table.timestamp('createdAt');
table.timestamp('editedAt');
table.unique(['userId', 'name']);
});
await knex.schema.createTable('fileTags', table => {
table.increments();
table.integer('fileId');
table.integer('tagId');
table.unique(['fileId', 'tagId']);
});
await knex.schema.createTable('bans', table => {

View File

@ -0,0 +1,33 @@
exports.up = async knex => {
await knex.schema.alterTable('users', table => {
table.unique(['username', 'apiKey']);
});
await knex.schema.alterTable('albums', table => {
table.boolean('nsfw').defaultTo(false);
table.unique(['userId', 'name']);
});
await knex.schema.alterTable('links', table => {
table.unique(['userId', 'albumId', 'identifier']);
});
await knex.schema.alterTable('albumsFiles', table => {
table.unique(['albumId', 'fileId']);
});
await knex.schema.alterTable('albumsLinks', table => {
table.unique(['linkId']);
});
await knex.schema.alterTable('tags', table => {
table.unique(['userId', 'name']);
});
await knex.schema.alterTable('fileTags', table => {
table.unique(['fileId', 'tagId']);
});
};
exports.down = async knex => {
// Nothing
};