-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Rattrapage de la feature "LEARNER_IMPORT" pour les organisa…
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
api/db/migrations/20240515151525_add-unicity-constraint-on-import-format-name.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,25 @@ | ||
// Make sure you properly test your migration, especially DDL (Data Definition Language) | ||
// ! If the target table is large, and the migration take more than 20 minutes, the deployment will fail ! | ||
|
||
// You can design and test your migration to avoid this by following this guide | ||
// https://1024pix.atlassian.net/wiki/spaces/DEV/pages/2153512965/Cr+er+une+migration | ||
|
||
// If your migrations target `answers` or `knowledge-elements` | ||
// contact @team-captains, because automatic migrations are not active on `pix-datawarehouse-production` | ||
// this may prevent data replication to succeed the day after your migration is deployed on `pix-api-production` | ||
const TABLE_NAME = 'organization-learner-import-formats'; | ||
const COLUMN_NAME = 'name'; | ||
|
||
const up = async function (knex) { | ||
await knex.schema.alterTable(TABLE_NAME, function (table) { | ||
table.unique(COLUMN_NAME); | ||
}); | ||
}; | ||
|
||
const down = async function (knex) { | ||
await knex.schema.alterTable(TABLE_NAME, function (table) { | ||
table.dropUnique(COLUMN_NAME); | ||
}); | ||
}; | ||
|
||
export { down, up }; |
34 changes: 34 additions & 0 deletions
34
api/db/migrations/20240515151526_add-learner-import-to-sco-1d-organisation.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,34 @@ | ||
const up = async function (knex) { | ||
const [feature] = await knex.select('id').from('features').where({ key: 'LEARNER_IMPORT' }).limit(1); | ||
const organizationIdsSco1d = await knex.select('id').from('organizations').where({ type: 'SCO-1D' }); | ||
const [organizationLearnerImportFormat] = await knex | ||
.select('id') | ||
.from('organization-learner-import-formats') | ||
.where({ name: 'ONDE' }) | ||
.limit(1); | ||
|
||
for await (const organization of organizationIdsSco1d) { | ||
await knex('organization-features') | ||
.insert({ | ||
organizationId: organization.id, | ||
featureId: feature.id, | ||
params: { organizationLearnerImportFormatId: organizationLearnerImportFormat.id }, | ||
}) | ||
.onConflict() | ||
.ignore(); | ||
} | ||
}; | ||
|
||
const down = async function (knex) { | ||
const [feature] = await knex.select('id').from('features').where({ key: 'LEARNER_IMPORT' }).limit(1); | ||
const organizationIdsSco1d = await knex.select('id').from('organizations').where({ type: 'SCO-1D' }); | ||
|
||
for await (const organization of organizationIdsSco1d) { | ||
await knex('organization-features').del().where({ | ||
organizationId: organization.id, | ||
featureId: feature.id, | ||
}); | ||
} | ||
}; | ||
|
||
export { down, up }; |
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