Skip to content

Commit

Permalink
Add env var to disable schema dump
Browse files Browse the repository at this point in the history
The previous solution of setting `schema_dump` via database_url does not work.

Using an ENV var seems to be the most reliable solution.
  • Loading branch information
mscoutermarsh committed Jan 15, 2024
1 parent 99220c5 commit 376a65d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ bundle install

Make sure you have the [`pscale` CLI installed](https://github.com/planetscale/cli#installation).

### Disable schema dump

Add the following to your `config/application.rb`.

```ruby
if ENV["DISABLE_SCHEMA_DUMP"]
config.active_record.dump_schema_after_migration = false
end
```

This will allow the gem to disable schema dumping after running `psdb:migrate`.

## Usage

1. Using pscale, create a new branch. This command will create a local `.pscale.yml` file. You should add it to your `.gitignore`.
Expand Down
4 changes: 2 additions & 2 deletions lib/planetscale_rails/tasks/psdb.rake
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ namespace :psdb do
adapter = "trilogy"
end

# Setting schema_dump to nil is intentional. It prevents Rails from creating a dump after running migrations.
url = "#{adapter}://#{username}:#{password}@#{host}:3306/#{database}?ssl_mode=VERIFY_IDENTITY&schema_dump="
url = "#{adapter}://#{username}:#{password}@#{host}:3306/#{database}?ssl_mode=VERIFY_IDENTITY"

# Check common CA paths for certs.
ssl_ca_path = %w[/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/ca-bundle.pem /etc/ssl/cert.pem].find { |f| File.exist?(f) }
Expand All @@ -108,6 +107,7 @@ namespace :psdb do
desc "Create credentials for PlanetScale and sets them to ENV['PSCALE_DATABASE_URL']"
task "create_creds" => %i[environment check_ci] do
ENV["PSCALE_DATABASE_URL"] = create_connection_string
ENV["DISABLE_SCHEMA_DUMP"] = "true"
end

desc "Connects to the current PlanetScale branch and runs rails db:migrate"
Expand Down

0 comments on commit 376a65d

Please sign in to comment.