From 0f1cd9c02c51241ebc088be7db0171c904d042c9 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sat, 13 Jun 2020 19:20:07 +0200 Subject: [PATCH] fix: sql migration handling in make --- CMakeLists.txt | 2 ++ compile_migrations.sh | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c6a05e..44b53b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ aux_source_directory(endpoints ENDPOINTS_SRC) configure_file("core.ini" "core.ini" COPYONLY) +add_dependencies(core migrations) + target_sources(core PRIVATE ${VENDOR_SRC} ${SRC_DIR} ${HANDLERS_SRC} ${HELPERS_SRC} ${MODELS_SRC} ${ENDPOINTS_SRC}) target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor) diff --git a/compile_migrations.sh b/compile_migrations.sh index 17c7f78..15cae61 100755 --- a/compile_migrations.sh +++ b/compile_migrations.sh @@ -4,10 +4,19 @@ cd "$(dirname "$0")"; migration_num=0; -while [ -f sql/migration_$migration_num.sql ] +while [ -f ./sql/migration_$migration_num.sql ] do - xxd -i sql/migration_$migration_num.sql | sed 's/\([0-9a-f]\)$/\0, 0x00/' > include/migrations/$migration_num.sql.h - ((migration_num++)); -done; + if [ -f ./include/migrations/$migration_num.sql.h ] + then + if [ -z $(find ./sql/migration_$migration_num.sql -newer ./include/migrations/$migration_num.sql.h -print) ] + then + ((migration_num++)) + continue + fi + fi + echo "Recompiling migration $migration_num" + xxd -i sql/migration_$migration_num.sql | sed 's/\([0-9a-f]\)$/\0, 0x00/' > ./include/migrations/$migration_num.sql.h + ((migration_num++)) +done cd $PWD;