add organization cmd
parent
0056e6566c
commit
29df704818
@ -0,0 +1,96 @@
|
|||||||
|
"""register organiztion
|
||||||
|
|
||||||
|
Revision ID: 4b37d4034604
|
||||||
|
Revises: 18dd49e03533
|
||||||
|
Create Date: 2025-03-24 20:33:14.746272
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import models as models
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '4b37d4034604'
|
||||||
|
down_revision = '18dd49e03533'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('app_organization_access',
|
||||||
|
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('app_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('organization_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('permissions', sa.Text(), nullable=True),
|
||||||
|
sa.Column('created_by', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='app_organization_access_pkey'),
|
||||||
|
sa.UniqueConstraint('app_id', 'organization_id', name='unique_app_organization')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('app_organization_access', schema=None) as batch_op:
|
||||||
|
batch_op.create_index('app_org_access_app_idx', ['app_id'], unique=False)
|
||||||
|
batch_op.create_index('app_org_access_org_idx', ['organization_id'], unique=False)
|
||||||
|
|
||||||
|
op.create_table('organization_members',
|
||||||
|
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('organization_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('account_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('role', sa.String(length=64), nullable=False),
|
||||||
|
sa.Column('department', sa.String(length=255), nullable=True),
|
||||||
|
sa.Column('title', sa.String(length=255), nullable=True),
|
||||||
|
sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False),
|
||||||
|
sa.Column('meta_data', sa.Text(), nullable=True),
|
||||||
|
sa.Column('created_by', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='organization_member_pkey'),
|
||||||
|
sa.UniqueConstraint('organization_id', 'account_id', name='unique_org_account')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('organization_members', schema=None) as batch_op:
|
||||||
|
batch_op.create_index('org_member_account_idx', ['account_id'], unique=False)
|
||||||
|
batch_op.create_index('org_member_org_idx', ['organization_id'], unique=False)
|
||||||
|
|
||||||
|
op.create_table('organizations',
|
||||||
|
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=255), nullable=False),
|
||||||
|
sa.Column('code', sa.String(length=64), nullable=False),
|
||||||
|
sa.Column('description', sa.Text(), nullable=True),
|
||||||
|
sa.Column('type', sa.String(length=64), nullable=False),
|
||||||
|
sa.Column('logo', sa.String(length=255), nullable=True),
|
||||||
|
sa.Column('settings', sa.Text(), nullable=True),
|
||||||
|
sa.Column('status', sa.String(length=16), server_default=sa.text("'active'::character varying"), nullable=False),
|
||||||
|
sa.Column('created_by', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='organization_pkey'),
|
||||||
|
sa.UniqueConstraint('code', name=op.f('organizations_code_key'))
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('organizations', schema=None) as batch_op:
|
||||||
|
batch_op.create_index('organization_code_idx', ['code'], unique=False)
|
||||||
|
batch_op.create_index('organization_tenant_id_idx', ['tenant_id'], unique=False)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('organizations', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index('organization_tenant_id_idx')
|
||||||
|
batch_op.drop_index('organization_code_idx')
|
||||||
|
|
||||||
|
op.drop_table('organizations')
|
||||||
|
with op.batch_alter_table('organization_members', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index('org_member_org_idx')
|
||||||
|
batch_op.drop_index('org_member_account_idx')
|
||||||
|
|
||||||
|
op.drop_table('organization_members')
|
||||||
|
with op.batch_alter_table('app_organization_access', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index('app_org_access_org_idx')
|
||||||
|
batch_op.drop_index('app_org_access_app_idx')
|
||||||
|
|
||||||
|
op.drop_table('app_organization_access')
|
||||||
|
# ### end Alembic commands ###
|
||||||
Loading…
Reference in New Issue