fix: prevent migration rollback failure when NULL values exist

This commit is contained in:
carla 2026-01-07 09:52:40 +01:00
parent e1211fcf0f
commit 29a953c038

View file

@ -203,6 +203,11 @@ defmodule Mv.Repo.Migrations.RemovePhoneNumberAndMakeFieldsOptional do
end
def down do
# Set default values for NULL fields before restoring NOT NULL constraint
# This prevents the migration from failing if NULL values exist
execute("UPDATE members SET first_name = '' WHERE first_name IS NULL")
execute("UPDATE members SET last_name = '' WHERE last_name IS NULL")
# Restore first_name and last_name as NOT NULL
execute("ALTER TABLE members ALTER COLUMN first_name SET NOT NULL")
execute("ALTER TABLE members ALTER COLUMN last_name SET NOT NULL")