Added voting. Improved comments.

This commit is contained in:
2023-06-25 19:52:00 +02:00
parent 754a89b913
commit f42daa2f83
29 changed files with 916 additions and 154 deletions

View File

@@ -39,6 +39,8 @@ export async function up(knex) {
table.increments('id');
table.text('slug')
.unique()
.index()
.notNullable();
table.integer('founder_id')
@@ -102,6 +104,30 @@ export async function up(knex) {
await knex.raw('ALTER TABLE posts ADD CONSTRAINT post_content CHECK (body IS NOT NULL OR link IS NOT NULL)');
await knex.schema.createTable('posts_votes', (table) => {
table.increments('id');
table.tinyint('value')
.notNullable()
.defaultTo(1);
table.integer('user_id')
.notNullable()
.references('id')
.inTable('users');
table.string('post_id')
.notNullable()
.references('id')
.inTable('posts');
table.datetime('created_at')
.notNullable()
.defaultTo(knex.fn.now());
table.unique(['user_id', 'post_id']);
});
await knex.schema.createTable('comments', (table) => {
table.text('id', 8)
.primary()
@@ -112,7 +138,7 @@ export async function up(knex) {
.references('id')
.inTable('posts');
table.integer('parent_comment_id')
table.text('parent_id')
.references('id')
.inTable('comments');
@@ -123,6 +149,32 @@ export async function up(knex) {
table.text('body');
table.boolean('deleted')
.notNullable()
.defaultTo(false);
table.datetime('created_at')
.notNullable()
.defaultTo(knex.fn.now());
});
await knex.schema.createTable('comments_votes', (table) => {
table.increments('id');
table.tinyint('value')
.notNullable()
.defaultTo(1);
table.integer('user_id')
.notNullable()
.references('id')
.inTable('users');
table.string('comment_id')
.notNullable()
.references('id')
.inTable('comments');
table.datetime('created_at')
.notNullable()
.defaultTo(knex.fn.now());
@@ -130,11 +182,13 @@ export async function up(knex) {
}
export async function down(knex) {
await knex.schema.dropTable('comments');
await knex.schema.dropTable('posts');
await knex.schema.dropTable('shelves_settings');
await knex.schema.dropTable('shelves');
await knex.schema.dropTable('users');
await knex.schema.dropTableIfExists('comments_votes');
await knex.schema.dropTableIfExists('comments');
await knex.schema.dropTableIfExists('posts_votes');
await knex.schema.dropTableIfExists('posts');
await knex.schema.dropTableIfExists('shelves_settings');
await knex.schema.dropTableIfExists('shelves');
await knex.schema.dropTableIfExists('users');
await knex.raw(`
DROP FUNCTION IF EXISTS shack_id;