From 5cc539a32891b100a5f9817a6984d71f69c3835d Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Mon, 8 Jul 2024 16:18:54 +0800 Subject: [PATCH] feat: migrate upgrade when tenant_id is null --- .../161cadc1af8d_add_dataset_permission_tenant_id.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/migrations/versions/161cadc1af8d_add_dataset_permission_tenant_id.py b/api/migrations/versions/161cadc1af8d_add_dataset_permission_tenant_id.py index fa00004f1abe0b..daa507a7715247 100644 --- a/api/migrations/versions/161cadc1af8d_add_dataset_permission_tenant_id.py +++ b/api/migrations/versions/161cadc1af8d_add_dataset_permission_tenant_id.py @@ -35,7 +35,16 @@ def upgrade(): """ ) - # Step 3: Alter column to NOT NULL + # Step 3: Update the column to set a default value for existing rows + op.execute( + """ + UPDATE dataset_permissions + SET tenant_id = '00000000-0000-0000-0000-000000000000' + WHERE tenant_id IS NULL + """ + ) + + # Step 4: Alter column to NOT NULL op.alter_column('dataset_permissions', 'tenant_id', nullable=False) # ### end Alembic commands ###