Skip to content

Commit

Permalink
fix: Startup script does not always perform migrations (#2246)
Browse files Browse the repository at this point in the history
## Context

This PR is a fix for
#1945 (comment)

## Description

Lago startup script is relying on the `rails db:migrate:primary` to
perform the migration at startup.

Since in some situation, only one database is configured in the
`database.yml` file, the command is failing with the following error:
```
Unrecognized command "db:migrate:primary" (Rails::Command::UnrecognizedCommandError)
Did you mean?  db:migrate:up
```

This PR fixes this by using `rails db:migrate` instead when only one
database is present.
  • Loading branch information
vincent-pochet committed Jul 5, 2024
1 parent d0aa9d5 commit 98b4dcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ development:
password: changeme
database: lago
port: 5432
schema_search_path: "public"
events:
<<: *default
host: db
Expand Down Expand Up @@ -73,6 +74,7 @@ production:
url: <%= ENV['DATABASE_URL'] %>
pool: <%= ENV.fetch('DATABASE_POOL', 10) %>
prepared_statements: <%= ENV.fetch('DATABASE_PREPARED_STATEMENTS', true) %>
schema_search_path: <%= ENV.fetch('POSTGRES_SCHEMA', 'public') %>
events:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
Expand Down
4 changes: 3 additions & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ then
fi

rm -f ./tmp/pids/server.pid
bundle exec rails db:migrate:primary

if [ -v LAGO_CLICKHOUSE_ENABLED ] && [ "$LAGO_CLICKHOUSE_ENABLED" == "true" ]
then
bundle exec rails db:migrate:primary
bundle exec rake db:migrate:clickhouse
else
bundle exec rails db:migrate
fi

bundle exec rails signup:seed_organization
Expand Down

0 comments on commit 98b4dcc

Please sign in to comment.