Improved SFW and tag media seed file to allow updates.

This commit is contained in:
DebaucheryLibrarian
2020-09-05 02:57:24 +02:00
parent bba73c4f31
commit c96e10b33d
3 changed files with 25 additions and 28 deletions

View File

@@ -45,26 +45,21 @@ exports.up = knex => Promise.resolve()
table.text('comment');
table.text('group');
table.boolean('is_sfw')
.defaultTo(false);
table.unique('hash');
table.unique('source');
table.datetime('created_at')
.defaultTo(knex.fn.now());
}))
.then(() => knex.schema.createTable('media_sfw', (table) => {
table.text('id', 21)
.primary();
table.text('media_id', 21)
.references('id')
.inTable('media')
.unique();
}))
.then(() => { // eslint-disable-line arrow-body-style
// allow vim fold
return knex.raw(`
CREATE FUNCTION get_random_sfw_media_id() RETURNS varchar AS $$
SELECT media_id FROM media_sfw
SELECT id FROM media
WHERE is_sfw = true
ORDER BY random()
LIMIT 1;
$$ LANGUAGE sql STABLE;