Skip to main content

Migrations

golang-migrate, file order, dev reset, and PR checklist.
6 min read

Location#

Tooling: golang-migrate. Control table: agata_schema_migrations.

Latest migration in the repository tree: 000101_pomodoro_ai_revision. See Schema changelog for 000097–000101 and earlier history.

Current order#

#NameContents
001platform_coreusers, workspaces, members, feedback, audit, billing audit
002better_authuser, session, account, verification, subscription
003platformblobs, tags, projects
004taskstasks + documents + task_count triggers
005domainsgoals…nutrition (large file)
006notebooknotes / documents
007financefull ledger
009scheduled_notificationssend queue
010finance_debt_groupsdebt groups + group_id
011agentagent
012eve_chateve chat
013drop_entity_visibilitydrop visibility on notes/projects; scrub defaultProjectVisibility
014drop_nutrition_water_logsdrop nutrition_water_logs
015entity_assigneestask_assignees / activity_assignees / reminder_assignees; backfill tasks from assigned_to then drop column
016nutrition_assigneesmeal/recipe/inventory/shopping/plan assignee junctions; backfill from member_user_ids then drop
017finance_categories_to_workspace_tagsfinance categories → workspace tags
018perf_list_indexeslist indexes: health metric defs, checkins, invitations
019archive_done_tasksbackfill archived_at for existing status = done tasks
020archive_canceled_tasksbackfill archived_at for existing status = canceled tasks
021drop_task_recurrencedrop task recurrence columns + series unique index
022task_search_blobtasks.search_blob + GIN FTS (name + document body)
023normalize_shared_linkscanonical finance tag entity types + Pomodoro project links
024finance_plannerplanner scenarios + scenario items (what-if projection)
025agent_credits_addonsextra capacity, monthly Agent credit projection, reservations, Metronome outbox and inbox
027eve_chat_pinned_atEve chat pin
028workspace_tags_domain_scope_generaldomain_scope NOT NULL default general; unique (workspace, scope, name)
029recount_tag_link_countsrecompute workspace_tags.link_count from workspace_tag_links
030finance_recurring_transfersallows recurring transfer rules between two accounts
031calendar_eventsreminders.kind + inclusive range for all-day events
032finance_budget_namefinance_budgets.name + backfill from tag
033qstash_deliveryQStash delivery metadata and indexes for notifications and Metronome outbox
034drop_nutrition_shopping_remindersdrop reminder columns on nutrition_shopping_items; purge scheduled_notifications domain nutrition
035finance_debt_savings_accountoptional account_id on debts and savings goals
036finance_debt_account_detailfinance_debts.settled_at; statement_day, is_primary, mask_last4 on accounts
037finance_transaction_debt_paymentssyncs payments with debt movements, recovers skipped payments, and guarantees one payment per transaction
038remove_pre_creation_activity_logssoft-delete of activity logs before the creation day (including Unix epoch logs created by clients without dateMs)
039eve_privacy_memory_proactiveeve_chats.visibility + author FK; eve_chat_share_events; eve_user_memories; (historical) proactive settings/deliveries
040eve_proactive_last_read(historical) eve_proactive_settings.last_read_at
041task_subpagessubtasks as task pages (parent_task_id)
042recipe_steps_toolsnutrition_recipe_steps + nutrition_recipe_tools
043drop_eve_proactivedrop eve_proactive_*; purge jobs domain=agent; delete chats eve-proactive-%
044week_planweek_plans + week_plan_items (Mon–Sun week plan)
045reminder_all_day_email_each_daydrop reminders.kind; all_day + email_each_day; optional range on reminders
046billing_pending_planworkspaces.billing_pending_plan + billing_pending_interval for scheduled downgrades
047recount_workspace_project_countsworkspaces.project_count = custom projects (excluding General); default 0
048week_plan_intent_linksweek_plans.intent + optional calendar/task links on items
049feedback_kindfeedback_submissions.kind (bug | idea | praise)
050drop_unused_redundant_indexesdrop leftover/redundant indexes: idx_goals_workspace, idx_eve_chat_events_chat, idx_finance_accounts_workspace
051week_plan_seriesweek_plan_series + week_plan_items.series_id (repeat every week)
052week_plan_laterweek_plan_items.date_key nullable (Later)
053week_plan_activity_linksource_activity_id on items and series (optional habit)
054week_plan_series_startstarts_on_week_start_date_key; weekly does not fill past weeks
055workspace_member_favoriteworkspace_members.is_favorite (user's personal favorite)
056drop_activity_project_linksdeletes workspace_project_links with entity_type = activity
057goal_imagesgoal_images (goals cover blob)
058vision_boardsvision_boards + items + links to goals
059purge_orphan_project_linksdeletes workspace_project_links rows whose linked entity is gone
060workspace_plan_free_procollapse stored plans to base / pro
061better_auth_account_issueraccount.issuer for Better Auth credential/OAuth lookup
062task_attention_pinsper-user task attention pins
063document_schema_versionschema_version on task_documents and note_documents
064finance_coherencesavings-goal linkage, unique contribution ownership, currency on budgets/savings/planner, currency-scoped daily summaries
065drop_redundant_indexesdrop left-prefix indexes: idx_nutrition_meal_logs_workspace, idx_week_plans_workspace, idx_workspace_tags_workspace, idx_workspace_tags_scope
066workspace_plan_businesspermit business as a current or pending workspace plan without reclassifying existing Pro rows
067workspace_plan_entitlementsproject 5/10/25 included member capacity and 100/1,000/5,000 monthly AI credits onto existing workspace billing rows
068entitlement_v2_usage_accountsentitlement versions and billing-scope Agent usage accounts
069index_eve_chat_sessionEve session ownership claims, event CAS revision, atomic voice persistence, one-time voice approval challenges, and fail-closed API idempotency
070redact_eve_reasoning_eventsirreversibly remove legacy reasoning.* stream rows after write/read redaction ships
071eve_turn_correlationscontent-free accepted-reservation → Eve turn join for pseudonymous quality metrics and feedback
072checkin_sleep_qualityreplace sleep duration and pressure with three-point sleep quality and day ratings
079workspace_to_profileworkspaces → profiles, workspace_members → profile_members, workspace_id → profile_id. Written, not applied.
083feedback_source_profile_namefeedback_submissions.source_workspace_name → source_profile_name
084share_visibility_notes_routines_boards_activitiesvisibility on notes, exercise routines, vision boards, and activities
085agent_usage_accounts_scope_profileagent_usage_accounts.scope_kind: workspace → profile. Written, not applied.
086share_subscribers_membershipShare visibility gains subscribers. Connect, plans, fan billing, subscriptions, webhook inbox, owner-chat tables
091drop_task_placeRemoves the obsolete tasks.place_id association and index. Local migrate-up applied 2026-09-19 (90 → 91).
092drop_placesRemoves the discarded geographic Places table, remaining associations, and health route data. Local migrate-up applied 2026-09-19 (91 → 92).

(There is no 000008 in the repo. Intermediate rows are missing from this table on purpose if they were not documented.)

Commands#

Deploy (API on Vercel)#

The API container (Dockerfile.vercel) runs migrate up in the entrypoint before starting the server. With MIGRATE_DATABASE_URL (or DATABASE_URL) in the Vercel project, every deploy (and every container cold start) applies pending migrations so the prod schema does not lag behind dev.

cmd/migrate up is a fast no-op when the DB is already at the head version (log status=noop), so there is no need to skip migrations in the entrypoint to save CPU — the drift risk is not worth it.

If the control table is dirty, migrate up forces that version clean (status=dirty-reset) and continues. A failed version is transactional, so this unblocks boot and later files instead of panicking every cold start. The container entrypoint also starts the API if migrate up still exits non-zero.

bun run api:build also runs migrate up at the end (useful locally if there is a DSN in .env.local).

Dev reset (destructive)#

Or manually:

Verify#

Schema PR checklist#

  1. Reviewed up/down pair
  2. Indexes for real listing queries
  3. CHECKs for domain enums
  4. FKs with the correct ON DELETE (CASCADE only where it applies)
  5. Docs in apps/docs/database/… updated
  6. Dev seed if it introduces required tables

Expand / contract#

In prod with data: prefer nullable columns → backfill → constraints, instead of destructive rewrites.