From 8bb9a90cdeaa59c422c0509ee4dc88a78f7e1d55 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Thu, 12 Dec 2024 13:12:10 -0700 Subject: [PATCH] Provide default value to organization_name field in FSE --- .../versions/2024-12-06-09-59_9206124a098b.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/lcfs/db/migrations/versions/2024-12-06-09-59_9206124a098b.py b/backend/lcfs/db/migrations/versions/2024-12-06-09-59_9206124a098b.py index fc805ff14..d12cf71d4 100644 --- a/backend/lcfs/db/migrations/versions/2024-12-06-09-59_9206124a098b.py +++ b/backend/lcfs/db/migrations/versions/2024-12-06-09-59_9206124a098b.py @@ -5,21 +5,33 @@ Create Date: 2024-12-04 09:59:22.876386 """ + from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '9206124a098b' -down_revision = '26ab15f8ab18' +revision = "9206124a098b" +down_revision = "26ab15f8ab18" branch_labels = None depends_on = None def upgrade(): - # Add the column 'organization_name' to 'final_supply_equipment' table - op.add_column("final_supply_equipment", sa.Column("organization_name", sa.String(), nullable=True)) + # Add the column 'organization_name' to 'final_supply_equipment' table with a default value + op.add_column( + "final_supply_equipment", + sa.Column("organization_name", sa.String(), nullable=False, server_default=""), + ) + + # Update existing rows to have the default value + op.execute( + "UPDATE final_supply_equipment SET organization_name = '' WHERE organization_name IS NULL" + ) + + # Remove the server default to prevent future rows from automatically getting the default value + op.alter_column("final_supply_equipment", "organization_name", server_default=None) def downgrade(): # Remove the column 'organization_name' from 'final_supply_equipment' table - op.drop_column("final_supply_equipment", "organization_name") \ No newline at end of file + op.drop_column("final_supply_equipment", "organization_name")