Skip to content

Database schema and migrations

Every table of the tenant databases and of the master database, with its model and the rules its columns carry, followed by the migration history: the raw SQL files, the runners, and what the tenant and master auto-migrations apply on upgrade. It was moved verbatim out of the repo-root CLAUDE.md; the schema-change checklist stays there. The admin-facing notes are in Database & Migrations.

Code described: app/models/, app/database.py, setup_databases.sql, migrations/, app/services/tenant_provisioner.py, app/services/tenant_manager.py, app/services/tenant_data_migrations.py, app/services/master_db.py, scripts/sql/tenant_schema_template.sql.

Database Schema

Two declarative bases: Base (tenant databases, app/database.py) and MasterBase (master database, app/models/tenant.py). Never mix them.

Tenant database tables (one DB per tenant: milestone_<slug>)

Users & access

Table Model Purpose
users User App users and staff resources. email (unique), password, names, job_title, role (FK → roles.key, ON UPDATE CASCADE; the old CHECK is gone), max_capacity % (part-time), SSO fields, active, is_resource ("Bookable as a resource": listed by GET /staff and bookable on projects; NOT NULL DEFAULT TRUE, admins FALSE on create and back-filled FALSE on upgrade), is_system (protects provisioned admin). Props: full_name, is_admin (role == 'admin'), site_ids, team_ids, role_name (correlated subquery on roles.name), permissions (the resolved PermissionSet, not mapped)
user_sites UserSite M:N user ↔ site (composite PK)
sessions Session express-session-compatible session store: sid PK, sess JSON text, expired (ms epoch)
roles / role_permissions Role / RolePermission Roles (key unique, ^[a-z][a-z0-9_]{1,19}$, immutable; name, is_system for admin/superuser/user, sort_order) and their {permission, mode} rows (allow/approval; no row = deny; the admin role has none and holds everything in code). System roles and their defaults are seeded from the catalogue (app/services/permissions.py)
approval_policies / approval_policy_roles ApprovalPolicy / ApprovalPolicyRole Per approvable action (assignments.self_*): pm_approves + the approving roles (M:N, both FKs CASCADE). Seeded: PM approves, no roles
approval_requests ApprovalRequest Own-booking requests: requester (FK CASCADE), action, project_id (FK CASCADE), level + target_id, assignment_id (no FK, three tables), requested/previous JSON, note, status (pending/approved/rejected/cancelled/superseded/expired) + close_reason, decided_by (SET NULL), decided_at, decision_note, superseded_by_id
sso_config SSOConfig Tenant-level SSO singleton (CHECK id = 1): enabled, Entra tenant/client id, client_secret (AES-256-GCM encrypted, legacy plaintext encrypted by the auto-migration — use the sso.py helpers), redirect URI, auto_create_users, default_role

Sites & calendar

Table Model Purpose
sites Site Physical locations: name (unique), location, city, country/region codes, timezone, active, last_holiday_fetch
bank_holidays BankHoliday Public holidays per site (affect working-day calc); date + optional end_date (multi-day), year (NOT NULL); is_custom for manual, imported or edited entries (editing a Nager row sets is_custom = 1); refreshable from the Nager API — a refresh replaces only non-custom rows, only for the years the API actually returned (a failed year keeps its rows; replace_existing also clears stale years), and skips Nager entries on any day a custom holiday covers, or sharing a name (trimmed, case-insensitive) with a custom holiday of the same year (moved holidays)
company_events CompanyEvent Audits/meetings with color — displayed but do not affect working-day calc. counts_as_unavailable (BOOLEAN NOT NULL DEFAULT FALSE) marks a site closure: staff of the event's sites are unavailable for its dates (evaluated client-side). site_id is legacy (nullable, FK ON DELETE SET NULL), kept equal to the first linked site; site links live in company_event_sites
company_event_sites CompanyEventSite M:N event ↔ site (composite PK, both FKs CASCADE). Deleting a site deletes events left with no site

Teams (1.12.0, app/models/team.py; every FK ON DELETE CASCADE, so deleting a site or a team removes all its links)

Table Model Purpose
teams Team A named group of people at one site: site_id, name (unique per site, teams_site_name_unique), description, color, active. Inactive teams still scope everything; only the header filter hides them
team_members TeamMember M:N team ↔ user. A member must belong to the team's site (user_sites); removing a site from a user drops that site's memberships
project_teams ProjectTeam M:N project ↔ team; every team at the project's site (a site-less project has none)
tag_teams TagTeam M:N tag ↔ team. Per site: no team row at a site = the whole site; rows = only projects sharing one of those teams
company_event_teams CompanyEventTeam M:N event ↔ team, same per-site rule. A team-limited closure takes out only those teams' members (client-side)
equipment_teams EquipmentTeam M:N equipment ↔ team, same per-site rule

Projects

Table Model Purpose
projects Project R&D projects: name, site_id (FK ON DELETE CASCADE — deleting a site deletes its projects), customer, pm_id (FK users ON DELETE SET NULL), sales_pm (free text), confirmed, volume, dates, notes, archived, updated_at; tags M:N; field_values / field_selections relationships (the read path uses load_project_field_values column queries instead)
project_phases ProjectPhase Phases: project_id (CASCADE), type (name), dates, is_milestone, sort_order, completion, status (Kanban column), dependencies (JSON text)
project_subphases ProjectSubphase Recursive subphases: parent_id + parent_type CHECK(phase/subphase), depth, dates, milestone/completion/status/dependencies
tags / project_tags Tag / ProjectTag Project tags: name (unique tenant-wide), color, all_sites (default true), sort_order + M:N join with projects (no group since 2.0.0: tag_groups and tags.group_id were converted into project fields and dropped)
tag_sites TagSite M:N tag ↔ site, consulted only when all_sites = false (both FKs CASCADE). Deleting a site deletes restricted tags left with no site
project_fields ProjectField Project fields (2.0.0): name (unique, case-insensitive in the API), field_type CHECK project_fields_type_check (text/number/toggle/select/multiselect, immutable), sort_order, decimals (2.1.0: a number field's decimals 0–3, CHECK project_fields_decimals_check, NULL = as typed and on every other type; new values are rounded half-up to it on write). Colouring / grouping the Gantt by a field is a per-user frontend preference, not stored here
project_field_options ProjectFieldOption Dropdown items: field_id (CASCADE), name (unique per field), color, all_sites (default true), sort_order; site / team limits in project_field_option_sites / project_field_option_teams (the tag_sites / tag_teams shape, every FK CASCADE). A site delete deletes items left with no site
project_field_values ProjectFieldValue One row per project and text/number/toggle field: value_text / value_number (DOUBLE PRECISION) / value_bool, UNIQUE (field_id, project_id); absent = empty
project_field_selections (table) Items chosen per project (project_id, option_id, assigned_at; the project_tags shape, FKs CASCADE); one per single-select field, enforced by the API
custom_columns CustomColumn User-defined Gantt columns: column_type CHECK(text/boolean/list), list_options JSON, site_id (NULL = global), display_order, width
custom_column_values CustomColumnValue EAV values: entity_type CHECK(project/phase/subphase) + entity_id, unique per (column, entity). No FK to the entity: project/site/phase/subphase deletes remove them explicitly, and orphans are cleaned by the tenant data migrations

Assignments (three staff levels + equipment)

Table Model Purpose
project_assignments ProjectAssignment Project-level staff: allocation %, own start/end dates
phase_staff_assignments PhaseStaffAssignment Phase-level staff: allocation + optional own start_date / end_date (both NULL = linked, follows the phase; both set = an unlinked segment inside it; CHECK phase_staff_assignments_segment_dates_check = both or neither). Several non-overlapping rows per person per phase
subphase_staff_assignments SubphaseStaffAssignment Subphase-level staff: same shape and rules as the phase table (CHECK subphase_staff_assignments_segment_dates_check)
equipment_assignments EquipmentAssignment Equipment bookings: project + equipment + dates + an optional note (TEXT, 2.0.0) (project-level only; tenants provisioned before 1.0.15 may carry unused legacy phase/subphase columns)

The three staff tables carry approval_status (approved/pending, a pending own booking — excluded from availability, capacity, card access and assignee notifications) and approval_request_id (FK approval_requests SET NULL: the open request on the row).

Resources & time-off

Table Model Purpose
equipment Equipment Lab equipment: name, type (free-form string, managed via /equipment-types). site_id is legacy "primary site" (FK ON DELETE SET NULL), kept equal to the lowest linked site id; site links live in equipment_sites
equipment_sites EquipmentSite M:N equipment ↔ site (composite PK, both FKs CASCADE, index idx_equipment_sites_site). Deleting a site deletes only equipment left with no site and re-points survivors' site_id (Site.equipment has no delete cascade)
equipment_blocks EquipmentBlock Maintenance/unavailability windows (the vacation analogue for equipment)
vacations Vacation Staff time-off (absences). absence_type_id FK → absence_types (nullable, ON DELETE SET NULL; NULL = treated as unavailable). Recurring absences are encoded in description as [R:0,2,4] (days of week, 0=Sun) — parsed by frontend/src/utils/recurringVacation.ts
absence_types AbsenceType Tenant-wide absence categories: name (unique), color #RRGGBB, counts_as_unavailable (false = shown but capacity not reduced, e.g. Home Office), sort_order, is_active. Seeded when empty: Holidays, Home Office, Illness, Business Trip, Training
skills / user_skills Skill / UserSkill Global skills + M:N with proficiency CHECK(1–5)

Dashboards (2.3.0, app/models/dashboard.py; instance-wide, no site column, no site-export sheet)

Table Model Purpose
dashboards Dashboard name (≤ 100), description, owner_id (FK users ON DELETE SET NULL; NULL = admin-owned — the two seeded dashboards, or a shared dashboard whose owner was deleted), visibility CHECK dashboards_visibility_check (private / shared / everyone; DASHBOARD_VISIBILITIES), is_default (at most one: partial unique index dashboards_one_default ... WHERE is_default, ORM postgresql_where and sqlite_where), created_at / updated_at. Deleting a user deletes their private dashboards and nulls the owner of the others (users.py DELETE)
dashboard_roles DashboardRole M:N dashboard ↔ role (PK pair, both FKs CASCADE): the roles a shared dashboard is shared with. A shared dashboard left with no target of any kind is seen by its owner and admins only (Shared with no one left)
dashboard_sites DashboardSite M:N dashboard ↔ site (PK pair, both FKs CASCADE, idx_dashboard_sites_site): opens for the site's members (live user_sites; a sites.view_all holder who is not a member does not match)
dashboard_teams DashboardTeam M:N dashboard ↔ team (PK pair, both FKs CASCADE, idx_dashboard_teams_team): opens for the team's members (inactive teams included)
dashboard_users DashboardUser M:N dashboard ↔ user (PK pair, both FKs CASCADE, idx_dashboard_users_user): the people it is shared with by name. Links are stored only for shared; a deactivated person keeps the link (only deletes cascade)
dashboard_widgets DashboardWidget dashboard_id (CASCADE), kind CHECK dashboard_widgets_kind_check (kpi / bar / line / pie / table / gauge / heatmap / treemap / sankey; DASHBOARD_WIDGET_KINDS, newest last), title (≤ 120), query / options / layout as compact JSON text (sorted keys; objects on the wire), sort_order. A dashboard save replaces its widgets wholesale (new ids)

Misc

Table Model Purpose
card_comments CardComment Comment threads: a Kanban card's (phase/subphase, also shown in the booking dialog of that card) or, since 2.0.0, a project's (the thread of its project-level bookings). Polymorphic (entity_type, entity_id), entity_type CHECK(phase/subphase/project) (COMMENT_ENTITY_TYPES in the model; same shape as custom_column_values, so no FK on entity_id — phase/subphase deletes must clear them explicitly; orphans are cleaned by the tenant data migrations; a project thread (entity_id = project_id) goes with the project through the FK cascade). project_id FK ON DELETE CASCADE. body stores @[Name](id) mention tokens; mentioned_user_ids (TEXT, JSON id list) is derived from them server-side. author_id is nullable, FK ON DELETE SET NULL (comments survive user deletion; UI shows "Deleted user") + created_at/updated_at. Indexes idx_card_comments_entity, idx_card_comments_project
audit_log AuditLog Tenant audit log (2.4.0, app/models/audit_log.py; instance-wide, no site-export sheet): one immutable row per recorded action, written only by app/services/audit_log.record (adds and flushes, never commits). id BIGSERIAL, created_at, category CHECK audit_log_category_check (auth / admin / access / change; AUDIT_LOG_CATEGORIES), action (≤ 100, past-tense key such as auth.login.failed, project.created), outcome CHECK audit_log_outcome_check (success / failure), actor_user_id (FK users ON DELETE SET NULL) with the actor_email / actor_name snapshots, subject_email, target_type / target_id / target_label, project_id (no FK: the row outlives the project), ip (≤ 45), user_agent (≤ 255), origin (web / system), details (compact JSON text: reason, changes, items, context; credentials masked). Indexes ix_audit_log_created_at, ix_audit_log_category_created_at, ix_audit_log_action, ix_audit_log_actor_user_id, ix_audit_log_subject_email, ix_audit_log_ip, ix_audit_log_project_id
notifications Notification Per-recipient inbox: user_id (FK CASCADE), type CHECK(assigned/comment/mention/status_change/approval_requested/approval_decided/assignment_changed/project_changed — one constant, tenant_provisioner.NOTIFICATION_TYPES), actor_id (SET NULL), entity refs (entity_type phase/subphase/project), project_id (FK CASCADE; NULL on the change notification of a project delete), rendered title/body, read_at. Indexes: partial idx_notifications_user_unread + idx_notifications_user_created. Due-soon/overdue are derived client-side, never stored
staff_notes Note Notes pinned to a site/date. Class is Note but tablename is staff_notes. All schema sources now create staff_notes; a legacy notes table on old installs is migrated and dropped by migrations/add_staff_notes.sql / the tenant auto-migration
settings Settings Instance key-value settings (e.g. instance_title, show_weekends)
predefined_phases PredefinedPhase Phase name templates offered in the UI
project_presence ProjectPresence Active-viewer rows (60s timeout). Written by the WS layer; presence has no HTTP API

Master database tables (MASTER_DB_NAME, app default milestone_master)

Table Model Purpose
tenants Tenant Tenant registry: UUID id, name, slug (unique), database_name/user, status (active/suspended/pending/archived — TenantStatus Literal in app/schemas/tenant.py; create/update/status/delete/provision reset the tenant cache, and all but create also close the pool, so changes apply immediately), plan/limits, organization_id, required_group_ids (JSONB) + group_membership_mode (any/all) for SSO group gating
tenant_credentials TenantCredentials Per-tenant DB password, AES-256-GCM encrypted (iv:tag:ciphertext hex)
tenant_audit_log TenantAuditLog Admin actions on tenants (actor, action, JSONB details)
admin_users AdminUser Portal admins: email, PBKDF2-SHA512 password hash (pbkdf2_sha512$600000$salt$hash; legacy salt:hash upgraded on login), role (admin/superadmin, Literal-validated), must_change_password (enforced by get_current_admin)
admin_sessions AdminSession Admin-portal session store (same shape as tenant sessions)
organizations Organization Groups tenants for shared SSO
organization_sso_config OrganizationSSOConfig Org-level Entra SSO: tenant/client id, encrypted secret, redirect URI, auto-create + default role

Migrations

  • Raw idempotent SQL files in migrations/ — no Alembic. See migrations/README.md. Shell wrappers migrations/run_migration.sh and migrations/migrate_all_tenants.sh exist for container use.
  • Tenant migrations: python migrations/run_migration.py <name> — single-tenant: runs against DB_NAME; multi-tenant: iterates every active tenant from the master DB, connecting with PG_ADMIN_* (preferred) or the decrypted per-tenant credentials.
  • Master migrations: python migrations/run_migration_master.py <name> — statement-by-statement execution via split_sql_statements(), which correctly preserves DO $$ ... END $$; blocks (covered by tests/test_migration_parser.py).
  • The list of available migrations is the set of .sql files in migrations/ — run either runner with no argument to list them. One stray legacy migration lives at scripts/sql/migrations/001_add_max_capacity.sql.
  • Auto-migrations run in two places on top of the SQL files: master_db._apply_pending_migrations() (master schema drift, on startup) and tenant_manager._run_auto_migrations() (per-tenant drift, on first pool creation — and, in single-tenant mode, at startup via run_single_tenant_auto_migrations() in the lifespan). Both are idempotent. The tenant one adds users.is_resource on every pool creation (USERS_IS_RESOURCE_SQL, early, right after the is_system step; the DO block is its own gate), then the booking-segment columns (BOOKING_SEGMENT_COLUMN_STATEMENTS, unconditional, one statement per execute), then equipment_assignments.note (EQUIPMENT_ASSIGNMENTS_NOTE_SQL, its own gate, rolled back on failure), creates the dashboards tables with the one-shot seed of the two base dashboards + permission backfill right after the RBAC block (only when DASHBOARDS_PROBE_SQL finds a table missing, see the 2.3.0 add_dashboards.sql bullet), then the dashboard sharing tables in their own step (probe-gated, no seed) with the self-gated visibility block, also widens the notification-type CHECK on every pool creation (NOTIFICATIONS_TYPE_CHECK_SQL, after the RBAC block: the DO block is its own gate — it replaces the constraint only when the newest type, NOTIFICATION_TYPES[-1], is missing — so 1.13/1.14 tenants skipped by the RBAC probe get the 1.15 types), widens the card_comments entity-type CHECK with project (PROJECT_COMMENTS_CHECK_SQL, right after the card-comments step, its own gate like the notifications one, rolled back on failure), and ends with two non-DDL steps: encrypt_tenant_sso_secret() (legacy plaintext sso_config.client_secret → encrypted; needs the in-process key, so it cannot be a SQL file) and the Python data-migration hook run_data_migrations() (app/services/tenant_data_migrations.py: guarded FK rewrites projects.site_id → CASCADE, card_comments.author_id → nullable SET NULL, then orphan cleanup of custom_column_values / card_comments). Each step runs in its own transaction and never raises. The SQL lives in tenant_provisioner constants shared with the fresh-install schema and the .sql files — add new data fixes there, not inline.
  • 2.1.0 migration: add_project_field_decimals.sql (project_fields.decimals SMALLINT NULL with CHECK project_fields_decimals_check (decimals BETWEEN 0 AND 3), only when the column is missing; the DO block tenant_provisioner.PROJECT_FIELD_DECIMALS_SQL, a step of its own — never part of PROJECT_FIELDS_TABLE_SQL, which add_project_fields.sql carries verbatim — spliced right after CREATE TABLE project_fields in the provisioner schema, setup_databases.sql and the template, and run by the tenant auto-migration right after the project-fields step). Existing number fields get NULL (values kept as typed); stored values are never rewritten.
  • 2.4.0 migration: add_audit_log.sql (audit_log + its seven indexes, then a GRANT over the table and audit_log_id_seq and a notice; the statements of tenant_provisioner.AUDIT_LOG_SCHEMA_STATEMENTS, spliced into every fresh-schema source after the dashboard-sharing block). The tenant auto-migration runs them in their own probe-gated step, after the dashboard widget-kinds block and before the notification-types step: AUDIT_LOG_PROBE_SQL (pg_class, relname = 'audit_log' in public) finds no table → the DDL, then a commit; an up-to-date tenant pays the probe alone and commits nothing. Every other auto-migration test's fake connection answers the probe through tests/support.audit_log_step(sql) (a fake that does not shows an unexpected ROLLBACK).
  • 2.3.0 migration: add_dashboards.sql (dashboards, dashboard_roles, dashboard_widgets + their indexes, GRANT and notice blocks; the statements of tenant_provisioner.DASHBOARDS_SCHEMA_STATEMENTS, spliced into every fresh-schema source). The tenant auto-migration runs them in its own step right after the RBAC step (dashboard_roles references roles) when DASHBOARDS_PROBE_SQL finds a table missing, and in that same transaction only seeds the two base dashboards (app/services/dashboard_seed.py BASE_DASHBOARDS, bound parameters — no JSON literal inside SQL text): the Overview through DASHBOARD_SEED_SQL (ON CONFLICT (is_default) WHERE is_default DO NOTHING), Capacity and flows (heatmap, treemap, sankey) through DASHBOARD_NAMED_SEED_SQL (INSERT … SELECT … WHERE NOT EXISTS on the name, bound a second time as existing_name; dashboard_seed_statement / dashboard_seed_pg_statement pick the insert), each dashboard's widgets only when its insert returned an id, and backfills views.dashboards → superuser + user, dashboards.manage → superuser (DASHBOARD_PERMISSION_BACKFILL, system roles that exist, never over an existing row) — a later run never re-seeds, so an admin's removal of a key or of a seeded dashboard sticks, and a tenant whose tables already exist (a pre-release 2.3.0 database) never gets Capacity and flows. A brand-new tenant gets them from the provisioner (seed_base_dashboard, after the RBAC seed) and the catalogue defaults; init_db (AUTO_INIT_DB) probes before applying the schema and passes seed_dashboards=<tables were missing> so a restart never brings a deleted dashboard back; demo_seed (seed_demo and the portal's Seed demo data, which skip run_seed_data) writes the same two dashboards with the demo extras: the Overview's two field widgets Share of time by Project type per team / Booked weeks by Area, and on Capacity and flows a gauge (utilisation, target 85 — demo-only, because the measure needs views.staff) before the three base widgets (capacity_dashboard_rows(with_gauge=True)). ⚠ Running add_dashboards.sql by hand before 2.3.0 first starts on a tenant creates the tables, so the auto-migration then seeds neither dashboard nor the grants (an admin can add them in the app) — let the application upgrade the tenant. Likewise a database created by hand from setup_databases.sql or scripts/sql/tenant_schema_template.sql gets the tables and the key defaults (RBAC_SEED_ROLES_SQL) but no dashboard — an admin builds one.
  • 2.3.0 migration: add_dashboard_sharing.sql (dashboard_sites, dashboard_teams, dashboard_users + their indexes, then three DO blocks: the visibility block tenant_provisioner.DASHBOARD_VISIBILITY_CHECK_SQL, a GRANT over the three tables (no sequences), a notice). The tables are DASHBOARD_SHARING_SCHEMA_STATEMENTS, spliced into every fresh source after the dashboards block; the tenant auto-migration runs them in their own step right after the dashboards step when DASHBOARD_SHARING_PROBE_SQL finds one missing, no seed (DASHBOARD_TABLES stays three, so the dashboards seed never re-runs on a 2.3.0 tenant). The visibility block runs after the tables are committed, in its own transaction (a failing ALTER — the pool's user not owning dashboards — rolls back only the block, never the link tables), on every pool creation, and gates itself (dashboards exists and dashboards_visibility_check lacks shared → DROP CONSTRAINT, UPDATE … SET visibility = 'shared' WHERE visibility = 'roles', ADD CONSTRAINT): it exists only for databases created from a pre-release 2.3.0 build and lives only in the auto-migration and the .sql file — the fresh sources and add_dashboards.sql carry the ('private', 'shared', 'everyone') CHECK directly.
  • 2.3.0 migration: add_dashboard_widget_kinds.sql holds only the self-gated tenant_provisioner.DASHBOARD_WIDGET_KIND_CHECK_SQL (gate: dashboard_widgets exists and dashboard_widgets_kind_check lacks the newest kind, DASHBOARD_WIDGET_KINDS[-1] = sankey — so a new kind goes last in the tuple; then DROP / ADD with DASHBOARD_WIDGET_KIND_CHECK, no UPDATE) and a notice, for databases created from a pre-release 2.3.0 build (five kinds). The auto-migration runs it in its own try right after the visibility block, on every pool creation; a failure is logged at error level naming the file (a gauge, heatmap, treemap or sankey save would hit the old CHECK) and rolls back only that block. The fresh sources and add_dashboards.sql carry the nine kinds directly (the CHECK is spliced into DASHBOARD_WIDGETS_TABLE_SQL from DASHBOARD_WIDGET_KIND_CHECK). On an upgraded demo, the widened CHECK must exist (open /t/demo once) before insert_demo_dashboards writes the gauge.
  • 2.0.0 migration: add_equipment_assignment_note.sql (equipment_assignments.note TEXT NULL, only when the column is missing; the DO block tenant_provisioner.EQUIPMENT_ASSIGNMENTS_NOTE_SQL, spliced after CREATE TABLE equipment_assignments in the provisioner schema, an ADD COLUMN IF NOT EXISTS line in setup_databases.sql, and run by the tenant auto-migration right after the booking-segments step). Existing bookings get no note.
  • 2.0.0 migration: add_project_comments.sql (the card_comments entity-type CHECK gains project; the DO block tenant_provisioner.PROJECT_COMMENTS_CHECK_SQL, gated on the constraint lacking project, spliced verbatim after CREATE TABLE card_comments in every fresh-schema source and run by the tenant auto-migration). The unshipped add_rbac.sql / add_change_notifications.sql were edited in place when personal todos were removed (no todos table, no todo_assigned type); a database upgraded from a pre-release build keeps an unused todos table and the wider notification CHECK.
  • 2.0.0 migration: add_project_fields.sql (the six project-field tables, then — only while tag_groups exists — one DO block PROJECT_FIELDS_MIGRATION_SQL converting each tag group into a field (single_select → select, else multiselect; a clashing name gets (tags), (tags 2), …), each grouped tag into an item with its sites/teams, each of their project_tags rows into a selection, then deleting the grouped tags, renumbering the rest and dropping idx_tags_group, tags.group_id and tag_groups). The tenant auto-migration runs the same statements after the teams step when PROJECT_FIELDS_PROBE_SQL finds a table missing or tag_groups still there. The conversion block is not in the fresh-schema sources (it only ever acts on an upgrade). TAGS_UPGRADE_SQL keeps its group_id block for pre-1.6 databases (ruled for databases older than the 1.6 tag columns), guarded by tag_groups existing — unguarded it would fail on every 2.0.0 schema, which has no tag_groups — and no longer creates tag_groups.
  • 1.17.0 migration: add_booking_segments.sql (start_date / end_date DATE NULL on phase_staff_assignments / subphase_staff_assignments + the <table>_segment_dates_check CHECK, each added only when missing; the statements of tenant_provisioner.BOOKING_SEGMENT_COLUMN_STATEMENTS, also spliced into the fresh schema and run by the tenant auto-migration right after the is_resource step). Existing rows stay linked.
  • 1.16.0 migration: add_user_is_resource.sql (users.is_resource BOOLEAN NOT NULL DEFAULT TRUE, admins back-filled FALSE, only when the column is missing; the same DO block as tenant_provisioner.USERS_IS_RESOURCE_SQL, part of USERS_UPGRADE_SQL, also run by the tenant auto-migration on every pool creation).
  • 1.15.0 migration: add_change_notifications.sql (the notification-type CHECK widened to assignment_changed / project_changed; the same DO block as NOTIFICATIONS_TYPE_CHECK_SQL, idempotent, also applied by the tenant auto-migration step above). Adding a type means extending NOTIFICATION_TYPES — the DO block's marker is its last entry, so a new type must go at the end or upgraded tenants keep the old CHECK (removing a middle type, as 2.0.0 did with todo_assigned, leaves upgraded tenants on the wider CHECK — harmless).
  • 1.13.0 migration: add_rbac.sql (roles, role_permissions, approval_policies, approval_policy_roles, approval_requests, the assignment approval_status / approval_request_id columns, the widened notification types, users.role CHECK → FK; also applied by the tenant auto-migration, with the role/policy seed and the orphan cleanups — expired requests, orphan pending rows, stale pointers — in run_data_migrations()).
  • 1.12.0 migration: add_teams.sql (teams, team_members, project_teams, tag_teams, company_event_teams, equipment_teams; every FK cascades; also applied by the tenant auto-migration via the provisioner's TEAMS_SCHEMA_STATEMENTS).
  • 1.6.0 migration: add_tag_groups_and_sites.sql (tag_groups, tag_sites, the three new tags columns; the tenant auto-migration still applies tag_sites and the columns via TAGS_UPGRADE_SQL, no longer tag_groups — 2.0.0 converts and drops them).
  • 1.5.0 migrations: add_absence_types_and_event_sites.sql (absence_types, vacations.absence_type_id, company_event_sites), add_equipment_sites_and_site_closures.sql (equipment_sites, company_events.counts_as_unavailable), plus projects_site_fk_cascade.sql, card_comments_author_set_null.sql, cleanup_orphaned_values.sql (all also applied automatically by the tenant auto-migration and the hook above). migrations/migrate_all_tenants.sh now requires a migration file argument; the legacy run_migration_all_tenants.sql / generate_tenant_migrations.sql helpers (which created a wrong-shaped company_events) were removed.
  • 1.4.0 migration: add_kanban_tables.sql (status + CHECK on project_phases / project_subphases, card_comments, notifications).
  • upgrade_to_v90.sql is a legacy pre-1.0 catch-up script, superseded by the tenant auto-migrations; it adds nothing the models lack (tests/test_follow_up_defaults.py guards that).
  • setup_databases.sql is the canonical fresh-install schema and must stay in sync with the models (see the schema-change checklist in CLAUDE.md).