# Generates migrations_embedded.hpp from daemon/src/store/migrations/*.sql. # # cmake -DMIG_DIR= -DOUT= -P embed_migrations.cmake # # Each NNNN_name.sql becomes a Migration{ version = NNNN, name = "NNNN_name", sql = R"..." }. # The delimiter for the raw string literal is chosen to not collide with the file body. file(GLOB _sql_files "${MIG_DIR}/*.sql") list(SORT _sql_files) set(_entries "") foreach(_f ${_sql_files}) get_filename_component(_stem "${_f}" NAME_WE) # 0001_initial string(REGEX MATCH "^([0-9]+)_" _m "${_stem}") if(NOT _m) message(FATAL_ERROR "migration file '${_f}' does not start with NNNN_") endif() string(REGEX REPLACE "^0*([0-9]+)_.*$" "\\1" _ver "${_stem}") file(READ "${_f}" _body) # Pick a raw-string delimiter guaranteed absent from the body. set(_delim "MIGSQL") while(_body MATCHES "\\)${_delim}\"") set(_delim "${_delim}X") endwhile() string(APPEND _entries " Migration{ ${_ver}, \"${_stem}\", R\"${_delim}(\n${_body}\n)${_delim}\" },\n") endforeach() list(LENGTH _sql_files _count) set(_out "// GENERATED by embed_migrations.cmake — do not edit. Source: src/store/migrations/*.sql #pragma once #include #include \"store/migrations.hpp\" namespace velox::daemon::store { inline constexpr std::array kEmbeddedMigrations = {{ ${_entries}}}; } // namespace velox::daemon::store ") if(EXISTS "${OUT}") file(READ "${OUT}" _existing) if(_existing STREQUAL "${_out}") return() # unchanged — do not rewrite, keeps the build stable endif() endif() file(WRITE "${OUT}" "${_out}")