From 766469d0eaced9cfe48b5d26c49b5c17a94920b0 Mon Sep 17 00:00:00 2001 From: Josako Date: Tue, 4 Jun 2024 15:08:31 +0200 Subject: [PATCH] Database upgrades: is_active removed from user + tenant domain not unique --- ...750_remove_unneeded_is_active_as_it_is_.py | 64 +++++++++++++++++++ ...tenant_domains_do_not_need_to_be_unique.py | 64 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 migrations/public/versions/4701b1283750_remove_unneeded_is_active_as_it_is_.py create mode 100644 migrations/public/versions/dde18fb96c17_tenant_domains_do_not_need_to_be_unique.py diff --git a/migrations/public/versions/4701b1283750_remove_unneeded_is_active_as_it_is_.py b/migrations/public/versions/4701b1283750_remove_unneeded_is_active_as_it_is_.py new file mode 100644 index 0000000..dec634d --- /dev/null +++ b/migrations/public/versions/4701b1283750_remove_unneeded_is_active_as_it_is_.py @@ -0,0 +1,64 @@ +"""Remove unneeded is_active as it is confusing + +Revision ID: 4701b1283750 +Revises: 884ac7420cc5 +Create Date: 2024-05-31 17:43:26.565415 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '4701b1283750' +down_revision = '884ac7420cc5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('roles_users', schema=None) as batch_op: + batch_op.drop_constraint('roles_users_user_id_fkey', type_='foreignkey') + batch_op.drop_constraint('roles_users_role_id_fkey', type_='foreignkey') + batch_op.create_foreign_key(None, 'user', ['user_id'], ['id'], referent_schema='public', ondelete='CASCADE') + batch_op.create_foreign_key(None, 'role', ['role_id'], ['id'], referent_schema='public', ondelete='CASCADE') + + with op.batch_alter_table('tenant_domain', schema=None) as batch_op: + batch_op.drop_constraint('tenant_domain_updated_by_fkey', type_='foreignkey') + batch_op.drop_constraint('tenant_domain_created_by_fkey', type_='foreignkey') + batch_op.drop_constraint('tenant_domain_tenant_id_fkey', type_='foreignkey') + batch_op.create_foreign_key(None, 'user', ['updated_by'], ['id'], referent_schema='public') + batch_op.create_foreign_key(None, 'user', ['created_by'], ['id'], referent_schema='public') + batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public') + + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.drop_constraint('user_tenant_id_fkey', type_='foreignkey') + batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public') + batch_op.drop_column('is_active') + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.add_column(sa.Column('is_active', sa.BOOLEAN(), autoincrement=False, nullable=True)) + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.create_foreign_key('user_tenant_id_fkey', 'tenant', ['tenant_id'], ['id']) + + with op.batch_alter_table('tenant_domain', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.create_foreign_key('tenant_domain_tenant_id_fkey', 'tenant', ['tenant_id'], ['id']) + batch_op.create_foreign_key('tenant_domain_created_by_fkey', 'user', ['created_by'], ['id']) + batch_op.create_foreign_key('tenant_domain_updated_by_fkey', 'user', ['updated_by'], ['id']) + + with op.batch_alter_table('roles_users', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.create_foreign_key('roles_users_role_id_fkey', 'role', ['role_id'], ['id'], ondelete='CASCADE') + batch_op.create_foreign_key('roles_users_user_id_fkey', 'user', ['user_id'], ['id'], ondelete='CASCADE') + + # ### end Alembic commands ### diff --git a/migrations/public/versions/dde18fb96c17_tenant_domains_do_not_need_to_be_unique.py b/migrations/public/versions/dde18fb96c17_tenant_domains_do_not_need_to_be_unique.py new file mode 100644 index 0000000..f90f9bb --- /dev/null +++ b/migrations/public/versions/dde18fb96c17_tenant_domains_do_not_need_to_be_unique.py @@ -0,0 +1,64 @@ +"""Tenant Domains do not need to be unique + +Revision ID: dde18fb96c17 +Revises: 4701b1283750 +Create Date: 2024-06-04 15:06:24.574509 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'dde18fb96c17' +down_revision = '4701b1283750' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('roles_users', schema=None) as batch_op: + batch_op.drop_constraint('roles_users_user_id_fkey', type_='foreignkey') + batch_op.drop_constraint('roles_users_role_id_fkey', type_='foreignkey') + batch_op.create_foreign_key(None, 'role', ['role_id'], ['id'], referent_schema='public', ondelete='CASCADE') + batch_op.create_foreign_key(None, 'user', ['user_id'], ['id'], referent_schema='public', ondelete='CASCADE') + + with op.batch_alter_table('tenant_domain', schema=None) as batch_op: + batch_op.drop_constraint('tenant_domain_domain_key', type_='unique') + batch_op.drop_constraint('tenant_domain_tenant_id_fkey', type_='foreignkey') + batch_op.drop_constraint('tenant_domain_updated_by_fkey', type_='foreignkey') + batch_op.drop_constraint('tenant_domain_created_by_fkey', type_='foreignkey') + batch_op.create_foreign_key(None, 'user', ['created_by'], ['id'], referent_schema='public') + batch_op.create_foreign_key(None, 'user', ['updated_by'], ['id'], referent_schema='public') + batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public') + + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.drop_constraint('user_tenant_id_fkey', type_='foreignkey') + batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public') + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.create_foreign_key('user_tenant_id_fkey', 'tenant', ['tenant_id'], ['id']) + + with op.batch_alter_table('tenant_domain', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.create_foreign_key('tenant_domain_created_by_fkey', 'user', ['created_by'], ['id']) + batch_op.create_foreign_key('tenant_domain_updated_by_fkey', 'user', ['updated_by'], ['id']) + batch_op.create_foreign_key('tenant_domain_tenant_id_fkey', 'tenant', ['tenant_id'], ['id']) + batch_op.create_unique_constraint('tenant_domain_domain_key', ['domain']) + + with op.batch_alter_table('roles_users', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.create_foreign_key('roles_users_role_id_fkey', 'role', ['role_id'], ['id'], ondelete='CASCADE') + batch_op.create_foreign_key('roles_users_user_id_fkey', 'user', ['user_id'], ['id'], ondelete='CASCADE') + + # ### end Alembic commands ###