From 82e752be4517776b741dab79ea92b1adf46b0d09 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Tue, 19 Nov 2024 12:27:22 +0100 Subject: [PATCH] 1-3131: db migration to make potentially stale non-nullable (#8796) This change adds a db migration to make the potentially_stale column non-nullable. It'll set any NULL values to `false`. In the down-migration, make the column nullable again. --- ...819-make-potentially-stale-non-nullable.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/migrations/20241119103819-make-potentially-stale-non-nullable.js diff --git a/src/migrations/20241119103819-make-potentially-stale-non-nullable.js b/src/migrations/20241119103819-make-potentially-stale-non-nullable.js new file mode 100644 index 000000000000..68e3e3b1f3be --- /dev/null +++ b/src/migrations/20241119103819-make-potentially-stale-non-nullable.js @@ -0,0 +1,29 @@ +'use strict'; + +exports.up = function (db, cb) { + db.runSql( + ` + UPDATE features + SET potentially_stale = FALSE + WHERE potentially_stale IS NULL; + + ALTER TABLE features + ALTER COLUMN potentially_stale SET DEFAULT FALSE; + ALTER TABLE features + ALTER COLUMN potentially_stale SET NOT NULL; + `, + cb + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + ALTER TABLE features + ALTER COLUMN potentially_stale DROP DEFAULT; + ALTER TABLE features + ALTER COLUMN potentially_stale DROP NOT NULL; + `, + cb + ); +};