Skip to content

Commit

Permalink
feat(migration-structures-milo): rattacher animations collectives aux…
Browse files Browse the repository at this point in the history
… structures
  • Loading branch information
Mzem committed Dec 9, 2023
1 parent 4feb877 commit 47b4e60
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 15 deletions.
15 changes: 0 additions & 15 deletions scripts/data-migrations/purger-sessions-milo.js

This file was deleted.

27 changes: 27 additions & 0 deletions scripts/data-migrations/structures-milo-ac.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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`
)
})
1 change: 1 addition & 0 deletions src/domain/rendez-vous/rendez-vous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface RendezVous {
icsSequence?: number
createur: Createur
idAgence?: string
idStructureMilo?: string
dateCloture?: DateTime
informationsPartenaire?: RendezVous.InformationsPartenaire
nombreMaxParticipants?: number
Expand Down
1 change: 1 addition & 0 deletions src/infrastructure/jdd/rendez-vous.jdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function unRendezVousJDD(
icsSequence: null,
dateCloture: null,
idAgence: null,
idStructureMilo: null,
createur: { id: '1', nom: 'Tavernier', prenom: 'Nils' },
typePartenaire: null,
idPartenaire: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function toRendezVousDto(rendezVous: RendezVous): AsSql<RendezVousDto> {
icsSequence: rendezVous.icsSequence ?? null,
createur: rendezVous.createur,
idAgence: rendezVous.idAgence ?? null,
idStructureMilo: rendezVous.idStructureMilo ?? null,
typePartenaire: rendezVous.informationsPartenaire?.type ?? null,
idPartenaire: rendezVous.informationsPartenaire?.id ?? null,
nombreMaxParticipants: rendezVous.nombreMaxParticipants ?? null
Expand Down Expand Up @@ -59,6 +60,7 @@ export function toRendezVous(rendezVousSql: RendezVousSqlModel): RendezVous {
createur: rendezVousSql.createur,
dateCloture: DateService.fromJSDateToDateTime(rendezVousSql.dateCloture),
idAgence: rendezVousSql.idAgence ?? undefined,
idStructureMilo: rendezVousSql.idStructureMilo ?? undefined,
informationsPartenaire: buildInformationsPartenaire(rendezVousSql),
nombreMaxParticipants: rendezVousSql.nombreMaxParticipants ?? undefined
}
Expand Down
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
})
})
}
}
8 changes: 8 additions & 0 deletions src/infrastructure/sequelize/models/rendez-vous.sql-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AgenceSqlModel } from './agence.sql-model'
import { JeuneSqlModel } from './jeune.sql-model'
import { RendezVousJeuneAssociationSqlModel } from './rendez-vous-jeune-association.sql-model'
import { LogModificationRendezVousSqlModel } from './log-modification-rendez-vous-sql.model'
import { StructureMiloSqlModel } from './structure-milo.sql-model'

export class RendezVousDto extends Model {
@PrimaryKey
Expand Down Expand Up @@ -84,6 +85,13 @@ export class RendezVousDto extends Model {
})
idAgence: string | null

@ForeignKey(() => StructureMiloSqlModel)
@Column({
field: 'id_structure_milo',
type: DataType.STRING
})
idStructureMilo: string | null

@Column({
field: 'type_partenaire',
type: DataType.STRING
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/rendez-vous.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const unRendezVous = (args: Partial<RendezVous> = {}): RendezVous => {
icsSequence: undefined,
dateCloture: undefined,
idAgence: undefined,
idStructureMilo: undefined,
precision: 'Ceci est une précision',
createur: {
id: '1',
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/sql-models/rendez-vous.sql-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function unRendezVousDto(
icsSequence: null,
dateCloture: null,
idAgence: null,
idStructureMilo: null,
createur: { id: '1', nom: 'Tavernier', prenom: 'Nils' },
source: RendezVous.Source.PASS_EMPLOI,
typePartenaire: null,
Expand Down

0 comments on commit 47b4e60

Please sign in to comment.