-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migration-structures-milo): rattacher animations collectives aux…
… structures
- Loading branch information
Showing
11 changed files
with
291 additions
and
225 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
require('dotenv').config() | ||
const { Sequelize } = require('sequelize') | ||
const sequelize = new Sequelize(process.env.DATABASE_URL, { | ||
dialect: 'postgres' | ||
}) | ||
|
||
sequelize.transaction(async transaction => { | ||
const ACsRAW = await sequelize.query( | ||
`SELECT * FROM rendez_vous WHERE rendez_vous.type = 'ATELIER' OR rendez_vous.type = 'INFORMATION_COLLECTIVE'` | ||
) | ||
const ACs = ACsRAW[0] | ||
for (const AC of ACs) { | ||
const idStructureRaw = await sequelize.query( | ||
`SELECT conseiller.id_structure_milo AS id_structure_milo FROM conseiller WHERE conseiller.id = '${AC.createur.id}'`, | ||
{ transaction } | ||
) | ||
const idStructure = idStructureRaw[0][0].id_structure_milo | ||
|
||
if (idStructure) | ||
await sequelize.query( | ||
`UPDATE rendez_vous SET id_structure_milo = '${idStructure}' WHERE rendez_vous.id = '${AC.id}'` | ||
) | ||
} | ||
await sequelize.query( | ||
`UPDATE rendez_vous SET date_suppression = NOW() WHERE (rendez_vous.type = 'ATELIER' OR rendez_vous.type = 'INFORMATION_COLLECTIVE') AND rendez_vous.id_structure_milo IS NULL` | ||
) | ||
|
||
await sequelize.query(`DELETE FROM rendez_vous_jeune_association WHERE id IN (SELECT rendez_vous_jeune_association.id FROM rendez_vous_jeune_association, jeune, rendez_vous | ||
WHERE rendez_vous.id_structure_milo IS NOT null | ||
AND rendez_vous.id = rendez_vous_jeune_association.id_rendez_vous | ||
AND rendez_vous_jeune_association.id_jeune = jeune.id | ||
AND jeune.id_structure_milo != rendez_vous.id_structure_milo)`) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
29 changes: 29 additions & 0 deletions
29
src/infrastructure/sequelize/migrations/20231206080808-ajout-structure-milo-rdv.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,29 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.sequelize.transaction(async transaction => { | ||
await queryInterface.addColumn( | ||
'rendez_vous', | ||
'id_structure_milo', | ||
{ | ||
type: Sequelize.STRING, | ||
references: { | ||
model: 'structure_milo', | ||
key: 'id' | ||
}, | ||
allowNull: true | ||
}, | ||
{ transaction } | ||
) | ||
}) | ||
}, | ||
|
||
down: async queryInterface => { | ||
await queryInterface.sequelize.transaction(async transaction => { | ||
await queryInterface.removeColumn('rendez_vous', 'id_structure_milo', { | ||
transaction | ||
}) | ||
}) | ||
} | ||
} |
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
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
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
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