company flows

This commit is contained in:
debu-2 2026-10-04 20:01:29 +05:30
parent 6541284a4c
commit cc3f3f3de5
17 changed files with 1960 additions and 66 deletions

View file

@ -7,7 +7,16 @@ from sqlalchemy import text
from app.config import get_settings
from app.database import SessionFactory, engine, mongo_client, mongo_db
from app.models import Base
from app.routers import auth, dns_setup, domains, emails, sticky_notes
from app.routers import (
aliases,
auth,
dns_setup,
domains,
emails,
groups,
people,
sticky_notes,
)
from app.services.domain_provisioning import ensure_platform_domain
from app.services.inbound_smtp import InboundSMTPServer
@ -15,6 +24,29 @@ settings = get_settings()
inbound_server = InboundSMTPServer()
async def migrate_user_org_columns(connection) -> None:
await connection.execute(
text("ALTER TABLE users ADD COLUMN IF NOT EXISTS org_role VARCHAR(20)")
)
await connection.execute(
text(
"ALTER TABLE users ADD COLUMN IF NOT EXISTS member_status VARCHAR(20)"
)
)
await connection.execute(
text(
"ALTER TABLE users ADD COLUMN IF NOT EXISTS created_by_id UUID "
"REFERENCES users(id)"
)
)
await connection.execute(
text("UPDATE users SET org_role = 'user' WHERE org_role IS NULL")
)
await connection.execute(
text("UPDATE users SET member_status = 'active' WHERE member_status IS NULL")
)
async def migrate_legacy_user_tables(connection) -> None:
"""Promote the former auth table to users without discarding old profiles."""
tables = (
@ -44,6 +76,7 @@ async def lifespan(_: FastAPI):
async with engine.begin() as connection:
await migrate_legacy_user_tables(connection)
await connection.run_sync(Base.metadata.create_all)
await migrate_user_org_columns(connection)
async with SessionFactory() as session:
await ensure_platform_domain(session)
await session.commit()
@ -124,6 +157,9 @@ app.include_router(emails.router, prefix=settings.api_prefix)
app.include_router(sticky_notes.router, prefix=settings.api_prefix)
app.include_router(auth.router, prefix=settings.api_prefix)
app.include_router(domains.router, prefix=settings.api_prefix)
app.include_router(people.router, prefix=settings.api_prefix)
app.include_router(groups.router, prefix=settings.api_prefix)
app.include_router(aliases.router, prefix=settings.api_prefix)
app.include_router(dns_setup.router, prefix=settings.api_prefix)