-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from IntersectMBO/qa
From QA to PreProd
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
backend/database/migrations/20241121_2_WithdrawalsRestoreDataAndDropSchema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// This migration is depending on first one | ||
// This will restore all data to new table from temp schema and drop table and schema. | ||
module.exports = { | ||
async up(knex) { | ||
try { | ||
const strapiInstance = global.strapi; | ||
let result =[]; | ||
try { | ||
result = await knex.raw('SELECT * from temp.temp_migrate_data'); | ||
console.log("Data pulled"); | ||
} catch (error) { | ||
console.error('Error dropping column:', error); | ||
} | ||
for (const row of result.rows) { | ||
let entry = await global.strapi.entityService.findOne('api::proposal-content.proposal-content', row.id); | ||
let updatedEntry = { ...entry }; | ||
updatedEntry['proposal_withdrawals'] = [ | ||
{ | ||
prop_receiving_address: row.prop_receiving_address, | ||
prop_amount: row.prop_amount, | ||
}]; | ||
|
||
let r = await global.strapi.entityService.update('api::proposal-content.proposal-content', row.id,{ | ||
data: {proposal_withdrawals:[{ | ||
prop_receiving_address: row.prop_receiving_address, | ||
prop_amount: row.prop_amount, | ||
}] | ||
}}); | ||
console.log(`Updated entry with ID ${row.id}`); | ||
} | ||
try { | ||
await knex.raw('DROP TABLE IF EXISTS temp.temp_migrate_data'); | ||
console.log("Temp table temp_migrate_data deleted"); | ||
await knex.raw('DROP SCHEMA IF EXISTS temp'); | ||
} catch (error) { | ||
console.error('Error dropping table:', error); | ||
} | ||
console.log('Migration 20241121_2 completed!'); | ||
} catch (error) { | ||
console.error('Error running migration:', error); | ||
} | ||
} | ||
} |