---
id: w1/m2/t003
title: Core schema + migrations (tenants, apps, domains)
worker: worker1
status: done
estimate: 30m
depends_on: [w1/m2/t002]
---

## Objective

Define the source-of-truth tables for the product's core entities, with migrations.

## Context

- Schema (see `docs/ADR003-control-plane.md`): `tenants(id,name,plan,…)`, `apps(id,tenant_id,name,repo|image,port,replicas,tier,idle_ttl,…)`, `domains(id,app_id,host,verified_at,cert_status)`.
- Use a migration tool (e.g. golang-migrate) so schema is reproducible.

## Steps

1. Write migrations for `tenants`, `apps`, `domains` (+ FKs, indexes).
2. Run them on startup or via a migrate step.

## Files

- `operator/internal/controlplane/migrations/` · schema/model code.

## Acceptance criteria

- [ ] Migrations apply cleanly to `bex-db`; the three tables exist with the documented columns.

## Out of scope

- Auth/billing tables (t004); projection (t005); API (t006).
