Skip to content

Commit

Permalink
Handle invalid strings in column
Browse files Browse the repository at this point in the history
  • Loading branch information
john-craft committed Nov 15, 2024
1 parent d5d39b3 commit 94111a1
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ module.exports = {
type: Sequelize.DATEONLY,
});

// Convert and move the data from 'dob' to 'dob_temp'
// Convert valid dates and set NULL for invalid ones
await queryInterface.sequelize.query(`
UPDATE "Users"
SET "dob_temp" = "dob"::DATE
SET "dob_temp" = CASE
WHEN "dob" ~ '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' AND "dob"::DATE IS NOT NULL
THEN "dob"::DATE
ELSE NULL
END
`);

// Remove the old 'dob' column
Expand Down

0 comments on commit 94111a1

Please sign in to comment.