Jun 27 MT-7
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""phase33 — tenant_settings table for per-tenant branding (MT-7)
|
||||
|
||||
Adds a single-row-per-tenant settings store in the tenant database.
|
||||
Tenant-zero starts with defaults (no visual change until admin edits them).
|
||||
|
||||
Revision: phase33_tenant_settings
|
||||
Down: phase32_device_token_columns
|
||||
"""
|
||||
|
||||
revision = 'phase33_tenant_settings'
|
||||
down_revision = 'phase32_device_token_columns'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
def _table_exists(bind, table_name):
|
||||
result = bind.execute(sa.text(
|
||||
"SELECT COUNT(*) FROM information_schema.tables "
|
||||
"WHERE table_schema = DATABASE() AND table_name = :t"
|
||||
), {'t': table_name})
|
||||
return result.scalar() > 0
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
if not _table_exists(bind, 'tenant_settings'):
|
||||
op.execute(sa.text("""
|
||||
CREATE TABLE tenant_settings (
|
||||
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
company_name VARCHAR(150) NULL,
|
||||
logo_url VARCHAR(500) NULL,
|
||||
primary_color VARCHAR(7) NOT NULL DEFAULT '#1a56db',
|
||||
accent_color VARCHAR(7) NOT NULL DEFAULT '#16a34a',
|
||||
support_email VARCHAR(255) NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
updated_by INT NULL,
|
||||
CONSTRAINT fk_tenant_settings_user
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
bind = op.get_bind()
|
||||
if _table_exists(bind, 'tenant_settings'):
|
||||
op.execute(sa.text('DROP TABLE tenant_settings'))
|
||||
Reference in New Issue
Block a user