Skip to content

Commit

Permalink
fix: update planter migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Kpoke committed Nov 15, 2023
1 parent 1cdeaf8 commit 2bb5626
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions v1Tov2Migrations/migrate_planter_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ const createWalletRegistrations = require('./helper/createWalletRegistrations');
async function migrate() {
const base_query_string = `SELECT pp.* FROM public.planter pp
left join treetracker.grower_account tg on pp.grower_account_uuid = tg.id
where (pp.email is not null or pp.phone is not null)
and tg.id is null order by organization_id asc
where
(
( pp.email is not null or pp.phone is not null )
and
tg.id is null
)
or
(
pp.organization_id is not null and tg.organization_id is null
)
order by organization_id asc
`;

const rowCountResult = await knex.select(
Expand All @@ -34,6 +43,23 @@ async function migrate() {
ws._write = async (planter, enc, next) => {
try {
if (planter.grower_account_uuid) {
// update organization_id
if (planter.organization_id) {
const org = await trx
.select()
.table('entity')
.where({ id: planter.organization_id })
.first();

const organization_id = org.stakeholder_uuid;

await trx('treetracker.grower_account')
.where({ id: planter.grower_account_uuid })
.update({
organization_id,
});
}

bar.tick();
if (bar.complete) {
await trx.commit();
Expand Down

0 comments on commit 2bb5626

Please sign in to comment.