Skip to content

Commit

Permalink
Fix migration, syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorNadj committed Jul 5, 2022
1 parent a748e79 commit 9eac74c
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,31 @@ exports.up = async function (db) {
AND config->'isDataRegional' = 'false'
`);

await db.runSql('ALTER TABLE ${table} ENABLE TRIGGER ${table}_trigger;');
await db.runSql(`ALTER TABLE ${table} ENABLE TRIGGER ${table}_trigger;`);
}
};

exports.down = async function (db) {
for (const table of TABLES) {
await db.runSql('ALTER TABLE ${table} DISABLE TRIGGER ${table}_trigger;');
await db.runSql(`ALTER TABLE ${table} DISABLE TRIGGER ${table}_trigger;`);

// - Regional
await db.runSql(`
UPDATE ${table}
SET config = (config || '{"isDataRegional": true}' #- '{dhisInstanceCode}'
SET config = (config || '{"isDataRegional": true}') #- '{dhisInstanceCode}'
WHERE service_type = 'dhis'
AND config->'dhisInstanceCode' = 'regional'
AND config->>'dhisInstanceCode' = 'regional'
`);

// - Non-regional
await db.runSql(`
UPDATE ${table}
SET config = config || '{"isDataRegional": false}' #- '{dhisInstanceCode}'
SET config = (config || '{"isDataRegional": false}') #- '{dhisInstanceCode}'
WHERE service_type = 'dhis'
AND config->'dhisInstanceCode' = 'null'
AND config->>'dhisInstanceCode' = 'null'
`);

await db.runSql('ALTER TABLE ${table} ENABLE TRIGGER ${table}_trigger;');
await db.runSql(`ALTER TABLE ${table} ENABLE TRIGGER ${table}_trigger;`);
}

await db.runSql(`TRUNCATE TABLE dhis_instance`);
Expand Down

0 comments on commit 9eac74c

Please sign in to comment.