Skip to content

Commit

Permalink
Update workflow from seeds when already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed May 3, 2024
1 parent 3abd117 commit 3994b4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- Fix password reset link @robgietema
- Fix serving videos @robgietema
- Fix related items in get call @robgietema
- Update workflow from seeds when already exists @robgietema

### Internal

Expand Down
21 changes: 16 additions & 5 deletions src/seeds/workflow/workflow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { map } from 'lodash';
import { map, merge } from 'lodash';

import { fileExists, stripI18n } from '../../helpers';
import { Workflow } from '../../models';
Expand All @@ -10,10 +10,21 @@ export const seedWorkflow = async (trx, profilePath) => {
await Workflow.delete(trx);
}
await Promise.all(
map(
profile.workflows,
async (workflow) => await Workflow.create(workflow, {}, trx),
),
map(profile.workflows, async (workflow) => {
// Check if type exists
const current = await Workflow.fetchById(workflow.id, {}, trx);

// If doesn't exist
if (!current) {
await Workflow.create(workflow, {}, trx);
} else {
await Workflow.update(
workflow.id,
merge(current.$toDatabaseJson(), workflow),
trx,
);
}
}),
);
console.log('Workflows imported');
}
Expand Down

0 comments on commit 3994b4c

Please sign in to comment.