-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
9c443c8
commit 103b7e5
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
users-api/src/migrations/20240119173749-change-dob-data-type.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,30 @@ | ||
'use strict'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up (queryInterface, Sequelize) { | ||
// Add a temporary column | ||
await queryInterface.addColumn('users', 'dob_temp', { | ||
type: Sequelize.DATEONLY, | ||
}); | ||
|
||
// Convert and move the data from 'dob' to 'dob_temp' | ||
await queryInterface.sequelize.query(` | ||
UPDATE "users" | ||
SET "dob_temp" = "dob"::DATE | ||
`); | ||
|
||
// Remove the old 'dob' column | ||
await queryInterface.removeColumn('users', 'dob'); | ||
|
||
// Rename the 'dob_temp' column to 'dob' | ||
await queryInterface.renameColumn('users', 'dob_temp', 'dob'); | ||
}, | ||
|
||
async down (queryInterface, Sequelize) { | ||
await queryInterface.changeColumn('users', 'dob', { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}); | ||
} | ||
}; |
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