Fix addTopic migration in notifications-backend plugin
The migration code fails when user_settings is non-empty because it adds a non-nullable constraint before DML is applied. This fixes that issue and adds a test case for that particular migration. Signed-off-by: Adam Kunicki <kunickiaj@gmail.com>
This commit is contained in:
@@ -18,14 +18,10 @@ const crypto = require('crypto');
|
||||
exports.up = async function up(knex) {
|
||||
await knex.schema.alterTable('user_settings', table => {
|
||||
table.string('topic').nullable().after('origin');
|
||||
table.string('settings_key_hash', 64).notNullable();
|
||||
table.string('settings_key_hash', 64).nullable();
|
||||
table.dropUnique([], 'user_settings_unique_idx');
|
||||
});
|
||||
|
||||
await knex.schema.alterTable('user_settings', table => {
|
||||
table.unique(['settings_key_hash'], 'user_settings_unique_idx');
|
||||
});
|
||||
|
||||
const rows = await knex('user_settings').select('user', 'channel', 'origin');
|
||||
for (const row of rows) {
|
||||
const rawKey = `${row.user}|${row.channel}|${row.origin}|}`;
|
||||
@@ -35,10 +31,14 @@ exports.up = async function up(knex) {
|
||||
user: row.user,
|
||||
channel: row.channel,
|
||||
origin: row.origin,
|
||||
topic: row.topic,
|
||||
})
|
||||
.update({ settings_key_hash: hash });
|
||||
}
|
||||
|
||||
await knex.schema.alterTable('user_settings', table => {
|
||||
table.string('settings_key_hash', 64).notNullable().alter();
|
||||
table.unique(['settings_key_hash'], 'user_settings_unique_idx');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = async function down(knex) {
|
||||
|
||||
Reference in New Issue
Block a user