Skip to content

Commit

Permalink
Merge pull request #28 from Kpoke/main
Browse files Browse the repository at this point in the history
main
  • Loading branch information
Kpoke authored Nov 13, 2024
2 parents a974ef5 + 5dbe149 commit 0e80e39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions v1Tov2Migrations/migrate_approved_captures.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ async function migrate() {
{ width: 40, total: recordCount },
);

const trx = await knex.transaction();
ws._write = async (rawCapture, enc, next) => {
console.log('processing ', rawCapture.id);
const trx = await knex.transaction();
try {
const tree = await trx
.select()
Expand All @@ -61,12 +62,13 @@ async function migrate() {
[+tree.id],
);

console.log('migrating ', tree.id)
console.log('migrating ', tree.id);
await createCapture(rawCapture, tree, trx, treeTags.rows);

await trx.commit();
console.log('processed ', rawCapture.id);
bar.tick();
if (bar.complete) {
await trx.commit();
console.log('Migration Complete');
process.exit();
}
Expand Down
7 changes: 4 additions & 3 deletions v1Tov2Migrations/migrate_raw_captures.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ async function migrate() {
{ width: 40, total: recordCount },
);

const trx = await knex.transaction();
ws._write = async (tree, enc, next) => {
console.log('processing ', tree.id);
const trx = await knex.transaction();
try {
console.log('processing ', tree.id);
const planter = await trx
.select()
.table('public.planter')
Expand Down Expand Up @@ -137,9 +137,10 @@ async function migrate() {

await createRawCapture(tree, treeAttributes, sessionId, trx);

await trx.commit();
console.log('processed ', tree.id);
bar.tick();
if (bar.complete) {
await trx.commit();
console.log('Migration Complete');
process.exit();
}
Expand Down
17 changes: 11 additions & 6 deletions v1Tov2Migrations/migrate_trees.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ async function migrate() {
}
console.log(`Migrating ${recordCount} records`);

const bar = new ProgressBar('Migrating [:bar] :percent :etas :current/:total (:rate)', {
width: 40,
total: recordCount,
});
const bar = new ProgressBar(
'Migrating [:bar] :percent :etas :current/:total (:rate)',
{
width: 40,
total: recordCount,
},
);

const trx = await knex.transaction();
ws._write = async (capture, enc, next) => {
console.log('processing ', capture.id);
const trx = await knex.transaction();
try {
// migrate capture_tags as well, do we want to?
const captureTags = await trx.raw(
Expand All @@ -43,9 +47,10 @@ async function migrate() {

await createTree(capture, trx, captureTags.rows);

await trx.commit();
console.log('processed ', capture.id);
bar.tick();
if (bar.complete) {
await trx.commit();
console.log('Migration Complete');
process.exit();
}
Expand Down

0 comments on commit 0e80e39

Please sign in to comment.