Added entity report table.

This commit is contained in:
DebaucheryLibrarian
2026-11-13 00:23:28 +01:00
parent 06e7cd33fd
commit 3451d3d708
+43
View File
@@ -0,0 +1,43 @@
exports.up = async function(knex) {
// user reports about entities, primarily to flag broken scrapers
await knex.schema.createTable('reports', (table) => {
table.increments('id');
table.integer('entity_id')
.notNullable()
.references('id')
.inTable('entities')
.onDelete('cascade');
table.text('reasons'); // comma-separated reason keys, see reportReasons in traxxx-web
table.text('comment');
table.integer('user_id')
.references('id')
.inTable('users')
.onDelete('set null');
table.boolean('is_read')
.notNullable()
.defaultTo(false);
table.boolean('is_completed')
.notNullable()
.defaultTo(false);
table.datetime('created_at')
.notNullable()
.defaultTo(knex.fn.now());
});
// a user can't report the same entity again while their previous report is still open
await knex.raw(`
CREATE UNIQUE INDEX reports_open_entity_user_unique
ON reports (entity_id, user_id)
WHERE is_completed = false
`);
};
exports.down = async function(knex) {
await knex.schema.dropTable('reports');
};