From e14c3e34909578b558442fe8aa8738dea6aa4a0b Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Thu, 11 Jul 2024 16:22:19 +0200 Subject: [PATCH] misc: Add LAGO_CLICKHOUSE_MIGRATIONS_ENABLED env (#2281) ## Description This PR introduce a new `LAGO_CLICKHOUSE_MIGRATIONS_ENABLED` environment variable to enable or disable the Clickhouse migration. This variable completes the existing `LAGO_CLICKHOUSE_ENABLED` that enable the Clickhouse event stores in API It should fix some issue we had recently in deploy on US/EU clusters with migration performed at startup --- .github/workflows/migrations-test.yml | 1 + .github/workflows/spec.yml | 1 + config/database.yml | 8 ++++---- lib/tasks/lago.rake | 2 +- scripts/start.sh | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/migrations-test.yml b/.github/workflows/migrations-test.yml index 62506132934..b32c428dd89 100644 --- a/.github/workflows/migrations-test.yml +++ b/.github/workflows/migrations-test.yml @@ -31,6 +31,7 @@ jobs: SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }} LAGO_FROM_EMAIL: noreply@getlago.com LAGO_CLICKHOUSE_ENABLED: true + LAGO_CLICKHOUSE_MIGRATIONS_ENABLED: true LAGO_CLICKHOUSE_HOST: localhost LAGO_CLICKHOUSE_DATABASE: default LAGO_CLICKHOUSE_USERNAME: "" diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml index 0b790f2142d..d7241e43f94 100644 --- a/.github/workflows/spec.yml +++ b/.github/workflows/spec.yml @@ -39,6 +39,7 @@ jobs: SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }} LAGO_FROM_EMAIL: noreply@getlago.com LAGO_CLICKHOUSE_ENABLED: true + LAGO_CLICKHOUSE_MIGRATIONS_ENABLED: true LAGO_CLICKHOUSE_HOST: localhost LAGO_CLICKHOUSE_DATABASE: default LAGO_CLICKHOUSE_USERNAME: "" diff --git a/config/database.yml b/config/database.yml index c8de706e314..dc9bdf00e4e 100644 --- a/config/database.yml +++ b/config/database.yml @@ -26,7 +26,7 @@ development: password: default migrations_paths: db/clickhouse_migrate debug: true - database_tasks: <% if ENV['LAGO_CLICKHOUSE_ENABLED'].present? %> true <% else %> false <% end %> + database_tasks: <% if ENV['LAGO_CLICKHOUSE_MIGRATIONS_ENABLED'].present? %> true <% else %> false <% end %> test: primary: @@ -46,7 +46,7 @@ test: password: <%= ENV.fetch('LAGO_CLICKHOUSE_PASSWORD', 'default') %> migrations_paths: db/clickhouse_migrate debug: true - database_tasks: <% if ENV['LAGO_CLICKHOUSE_ENABLED'].present? %> true <% else %> false <% end %> + database_tasks: <% if ENV['LAGO_CLICKHOUSE_MIGRATIONS_ENABLED'].present? %> true <% else %> false <% end %> schema_dump: <% if ENV['LAGO_DISABLE_SCHEMA_DUMP'].present? %> false <% else %> clickhouse_schema.rb <% end %> staging: @@ -66,7 +66,7 @@ staging: password: <%= ENV['LAGO_CLICKHOUSE_PASSWORD'] %> migrations_paths: db/clickhouse_migrate debug: false - database_tasks: <% if ENV['LAGO_CLICKHOUSE_ENABLED'].present? %> true <% else %> false <% end %> + database_tasks: <% if ENV['LAGO_CLICKHOUSE_MIGRATIONS_ENABLED'].present? %> true <% else %> false <% end %> production: primary: @@ -92,4 +92,4 @@ production: ssl: <%= ENV.fetch('LAGO_CLICKHOUSE_SSL', false) %> migrations_paths: db/clickhouse_migrate debug: false - database_tasks: <% if ENV['LAGO_CLICKHOUSE_ENABLED'].present? %> true <% else %> false <% end %> + database_tasks: <% if ENV['LAGO_CLICKHOUSE_MIGRATIONS_ENABLED'].present? %> true <% else %> false <% end %> diff --git a/lib/tasks/lago.rake b/lib/tasks/lago.rake index 477a114e8f8..a4f13d254b8 100644 --- a/lib/tasks/lago.rake +++ b/lib/tasks/lago.rake @@ -9,7 +9,7 @@ namespace :lago do schema_version: ApplicationRecord.connection.migration_context.current_version } - if ENV['LAGO_CLICKHOUSE_ENABLED'] == "true" + if ENV['LAGO_CLICKHOUSE_MIGRATIONS_ENABLED'] == "true" output[:clickhouse_schema_version] = Clickhouse::BaseRecord.connection.migration_context.current_version end diff --git a/scripts/start.sh b/scripts/start.sh index d848617ad8b..e78cc323085 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -7,10 +7,10 @@ fi rm -f ./tmp/pids/server.pid -if [ -v LAGO_CLICKHOUSE_ENABLED ] && [ "$LAGO_CLICKHOUSE_ENABLED" == "true" ] +if [ -v LAGO_CLICKHOUSE_MIGRATIONS_ENABLED ] && [ "$LAGO_CLICKHOUSE_MIGRATIONS_ENABLED" == "true" ] then bundle exec rails db:migrate:primary - bundle exec rake db:migrate:clickhouse + bundle exec rails db:migrate:clickhouse else bundle exec rails db:migrate fi