From 376a65dbb04279e499a01ce6be5aa520e87920f6 Mon Sep 17 00:00:00 2001 From: Mike Coutermarsh Date: Mon, 15 Jan 2024 09:26:02 -0500 Subject: [PATCH] Add env var to disable schema dump The previous solution of setting `schema_dump` via database_url does not work. Using an ENV var seems to be the most reliable solution. --- README.md | 12 ++++++++++++ lib/planetscale_rails/tasks/psdb.rake | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2feaf7..35e51ab 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/lib/planetscale_rails/tasks/psdb.rake b/lib/planetscale_rails/tasks/psdb.rake index 4e3574b..7f77c20 100644 --- a/lib/planetscale_rails/tasks/psdb.rake +++ b/lib/planetscale_rails/tasks/psdb.rake @@ -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) } @@ -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"