37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
"""Add tenants table.
|
|
|
|
Revision ID: 035
|
|
Revises: 034
|
|
Create Date: 2026-03-06
|
|
"""
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
revision = '035'
|
|
down_revision = '034'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
op.create_table(
|
|
'tenants',
|
|
sa.Column('id', UUID(as_uuid=True), primary_key=True,
|
|
server_default=sa.text('gen_random_uuid()')),
|
|
sa.Column('name', sa.String(200), nullable=False),
|
|
sa.Column('slug', sa.String(100), nullable=False, unique=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=False, server_default='true'),
|
|
sa.Column('created_at', sa.DateTime(), nullable=False,
|
|
server_default=sa.text('NOW()')),
|
|
)
|
|
# Seed default tenant — all existing data will be assigned to this tenant
|
|
op.execute("""
|
|
INSERT INTO tenants (name, slug, is_active)
|
|
VALUES ('HartOMat', 'hartomat', true)
|
|
""")
|
|
|
|
|
|
def downgrade():
|
|
op.drop_table('tenants')
|