A real-world walkthrough of fixing a production data integrity issue caused by a missing unique constraint in a Sequelize model. The author discovered 639 duplicate 'area of study' entries in a MySQL database because the unique constraint was defined in the Sequelize model but never applied in the original migration script. The fix involves writing a Sequelize migration that: fetches all duplicate records, reassigns foreign key relationships to the canonical IDs, deletes the excess rows, and finally adds the missing unique constraint to the database table via queryInterface.addConstraint.
2 Impressions