Skip to content

Commit

Permalink
misc: Add LAGO_CLICKHOUSE_MIGRATIONS_ENABLED env (#2281)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
vincent-pochet authored Jul 11, 2024
1 parent d15b8b9 commit e14c3e3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/migrations-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
LAGO_FROM_EMAIL: [email protected]
LAGO_CLICKHOUSE_ENABLED: true
LAGO_CLICKHOUSE_MIGRATIONS_ENABLED: true
LAGO_CLICKHOUSE_HOST: localhost
LAGO_CLICKHOUSE_DATABASE: default
LAGO_CLICKHOUSE_USERNAME: ""
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
LAGO_FROM_EMAIL: [email protected]
LAGO_CLICKHOUSE_ENABLED: true
LAGO_CLICKHOUSE_MIGRATIONS_ENABLED: true
LAGO_CLICKHOUSE_HOST: localhost
LAGO_CLICKHOUSE_DATABASE: default
LAGO_CLICKHOUSE_USERNAME: ""
Expand Down
8 changes: 4 additions & 4 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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 %>
2 changes: 1 addition & 1 deletion lib/tasks/lago.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e14c3e3

Please sign in to comment.