From 8f1ad725c550d44b4090cd1de571b71e3a5b2fe6 Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Mon, 8 Jul 2024 18:16:57 +0800 Subject: [PATCH] feat: update migrate tenant_id --- ...c1af8d_add_dataset_permission_tenant_id.py | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) 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 daa507a7715247..8907f781174b6b 100644 --- a/api/migrations/versions/161cadc1af8d_add_dataset_permission_tenant_id.py +++ b/api/migrations/versions/161cadc1af8d_add_dataset_permission_tenant_id.py @@ -21,31 +21,7 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('dataset_permissions', schema=None) as batch_op: # Step 1: Add column without NOT NULL constraint - op.add_column('dataset_permissions', sa.Column('tenant_id', sa.UUID(), nullable=True)) - - # Step 2: Update the column to set a default value for existing rows - op.execute( - """ - UPDATE dataset_permissions - SET tenant_id = ( - SELECT tenant_id - FROM datasets - WHERE datasets.id = dataset_permissions.dataset_id - ) - """ - ) - - # 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) + op.add_column('dataset_permissions', sa.Column('tenant_id', sa.UUID(), nullable=False)) # ### end Alembic commands ###