Miguel Casqueira 277d984af2 Prevent inserting null commit during DB migration
Change-type: patch
Closes: #1581
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-02-03 10:44:11 -05:00

29 lines
738 B
JavaScript

export async function up(knex) {
await knex.schema.createTable('currentCommit', (table) => {
table.integer('id').primary();
table.integer('appId').notNullable();
table.string('commit').notNullable();
table.unique(['appId']);
});
const currentCommit = await knex('config')
.where({ key: 'currentCommit' })
.select('value');
if (currentCommit[0] != null && currentCommit[0].value != null) {
const apps = await knex('app').select(['appId']);
for (const app of apps) {
await knex('currentCommit').insert({
appId: app.appId,
commit: currentCommit[0].value,
});
}
await knex('config').where({ key: 'currentCommit' }).delete();
}
}
export async function down() {
throw new Error('Not implemented');
}