-
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.
- Loading branch information
Showing
4 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
server/migrations/20240508112145-alter-form-fish-add-total-length.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 @@ | ||
'use strict' | ||
const { DataTypes } = require('sequelize') | ||
|
||
module.exports = { | ||
async up (queryInterface) { | ||
await queryInterface.addColumn('FormFishes', 'totalLengthEn', { | ||
type: DataTypes.TEXT, | ||
allowNull: true | ||
}) | ||
await queryInterface.addColumn('FormFishes', 'totalLengthLocal', { | ||
type: DataTypes.TEXT, | ||
allowNull: true | ||
}) | ||
await queryInterface.addColumn('FormFishes', 'totalLengthLang', { | ||
type: DataTypes.STRING(3), | ||
allowNull: true | ||
}) | ||
}, | ||
|
||
async down (queryInterface) { | ||
await queryInterface.removeColumn('FormFishes', 'totalLengthEn') | ||
await queryInterface.removeColumn('FormFishes', 'totalLengthLocal') | ||
await queryInterface.removeColumn('FormFishes', 'totalLengthLang') | ||
} | ||
} |
170 changes: 170 additions & 0 deletions
170
server/migrations/20240508112759-add-nomenclature-fish-total-length.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,170 @@ | ||
'use strict' | ||
|
||
const Sequelize = require('sequelize') | ||
const capitalizeFirstLetter = require('../utils/capitalizeFirstLetter') | ||
|
||
const nomenclatures = { | ||
fishes_total_length: [ | ||
{ | ||
label: { | ||
bg: '0 - 5 cm', | ||
en: '0 - 5 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '5 - 10 cm', | ||
en: '5 - 10 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '10 - 15 cm', | ||
en: '10 - 15 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '15 - 20 cm', | ||
en: '15 - 20 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '20 - 25 cm', | ||
en: '20 - 25 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '25 - 30 cm', | ||
en: '25 - 30 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '30 - 35 cm', | ||
en: '30 - 35 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '35 - 40 cm', | ||
en: '35 - 40 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '40 - 45 cm', | ||
en: '40 - 45 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '45 - 50 cm', | ||
en: '45 - 50 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '50 - 55 cm', | ||
en: '50 - 55 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '55 - 60 cm', | ||
en: '55 - 60 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '60 - 65 cm', | ||
en: '60 - 65 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '65 - 70 cm', | ||
en: '65 - 70 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '70 - 75 cm', | ||
en: '70 - 75 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '75 - 80 cm', | ||
en: '75 - 80 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '80 - 85 cm', | ||
en: '80 - 85 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '85 - 90 cm', | ||
en: '85 - 90 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '90 - 95 cm', | ||
en: '90 - 95 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '95 - 100 cm', | ||
en: '95 - 100 cm' | ||
} | ||
}, | ||
{ | ||
label: { | ||
bg: '> 100 cm', | ||
en: '> 100 cm' | ||
} | ||
} | ||
] | ||
} | ||
|
||
const nomenclatureValues = Object.entries(nomenclatures).flatMap(([type, values]) => values.map((value) => ({ | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
type, | ||
...Object.fromEntries(Object.keys(value.label).map(lang => [`label${capitalizeFirstLetter(lang)}`, value.label[lang]])) | ||
}))) | ||
|
||
const deleteExistingValues = (queryInterface) => | ||
queryInterface.bulkDelete('Nomenclatures', { | ||
type: { | ||
[Sequelize.Op.in]: Object.keys(nomenclatures) | ||
} | ||
}) | ||
|
||
module.exports = { | ||
async up (queryInterface) { | ||
// we use hard-coded IDs for the nomenclatures in test fixtures and fixtures cannot be applied if the migration is executed | ||
if (queryInterface.sequelize.options.dialect !== 'postgres') { | ||
return | ||
} | ||
await deleteExistingValues(queryInterface) | ||
await Promise.all([ | ||
queryInterface.bulkInsert('Nomenclatures', nomenclatureValues) | ||
]) | ||
}, | ||
|
||
async down (queryInterface) { | ||
// we use hard-coded IDs for the nomenclatures in test fixtures and fixtures cannot be applied if the migration is executed | ||
if (queryInterface.sequelize.options.dialect !== 'postgres') { | ||
return | ||
} | ||
await deleteExistingValues(queryInterface) | ||
} | ||
} |