Skip to content

Commit

Permalink
Merge pull request #29 from IntersectMBO/qa
Browse files Browse the repository at this point in the history
From QA to PreProd
  • Loading branch information
nebojsact authored Nov 26, 2024
2 parents 99ab315 + 30d7bf7 commit 3e56591
Showing 1 changed file with 43 additions and 0 deletions.
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);
}
}
}

0 comments on commit 3e56591

Please sign in to comment.