#pragma once // The schema migrator. Numbered SQL files in store/migrations/ are embedded at build time // (see embed_migrations.cmake). On startup the daemon calls migrate_to_head(db): every // migration whose version exceeds PRAGMA user_version is applied in order, each in its own // transaction, and user_version is advanced to match. // // Forward-only: a released migration is immutable. The forward-only test in // daemon/tests replays from every prior released user_version to head. #include #include #include #include "store/sqlite.hpp" namespace velox::daemon::store { struct Migration { std::int64_t version; // 1, 2, 3, ... ; matches the NNNN_ prefix std::string_view name; // e.g. "0001_initial" std::string_view sql; // the file body }; // The embedded set, sorted by version ascending. Defined in the generated header. std::span embedded_migrations(); struct MigrationOutcome { std::int64_t from_version = 0; std::int64_t to_version = 0; int applied = 0; }; // Apply every migration newer than db.user_version(). A no-op (applied == 0) when the DB // is already at or beyond the highest embedded version. DbResult migrate_to_head(Db& db); } // namespace velox::daemon::store