From 3451d3d708f199c626e43b40b0ec7472b00f8a60 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 13 Nov 2026 00:23:28 +0100 Subject: [PATCH] Added entity report table. --- migrations/20261112230000_reports.js | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 migrations/20261112230000_reports.js diff --git a/migrations/20261112230000_reports.js b/migrations/20261112230000_reports.js new file mode 100644 index 00000000..38f3c53c --- /dev/null +++ b/migrations/20261112230000_reports.js @@ -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'); +};