# Storage migrations Storage upgrades run at daemon startup before sessions open. Core and extension migrations have separate owners. The [extension runtime](../src/albedo/harness/runtime.gleam) exposes `migrate` for extension data migrations. ## Startup order [server.start](../src/albedo/daemon/server.gleam) calls `registry.prepare_storage` before serving sessions. [Core migrations.run](../src/albedo/daemon/migrations.gleam) runs image storage, transcript classification, session profiles, prompts, titles, and usage-hour upgrades in that order. Each result is checked, so an error stops the sequence. [Paperclips extension](../src/albedo/harness/extensions/paperclips/extension.gleam) contributes schema migrations alongside its table initializer. Extension-owned schema changes belong with their owner. See [extensions](extensions.md) and [paperclips](paperclips.md). ## Compatibility and interruption [session_prompts.run](../src/albedo/daemon/migrations/session_prompts.gleam) moves older session prompt columns into the prompt table. [transcript_classes.run](../src/albedo/daemon/migrations/transcript_classes.gleam) handles older transcript rows. Inspect each migration's transaction and marker logic before changing its restart behavior. These upgrades do not all share one transaction. ## Foreign-key indexes Make each foreign key's child columns the leading columns of an index. For a composite key, the index prefix must contain all child columns. An `INTEGER PRIMARY KEY` needs no separate index. Deletion looks up referencing child rows. Without an index, that lookup scans the child table for each deleted parent row and can block the store writer. [`test_every_foreign_key_column_is_indexed`](../test/e2e/session_delete_test.py) checks this invariant across the schema. Preserve it when adding or changing extension tables as well as core tables. ## Migration test inventory [test/e2e/migrations_test.py](../test/e2e/migrations_test.py) exercises startup with older data. Keep an upgrade scenario while its old format remains supported. A fresh database does not exercise that path. The normal test gate is described in [test execution](testing.md). ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Durable operation admission](operations.md) - [Test execution](testing.md)