From f3691a803bbabe6909f61937686e0d57740872fe Mon Sep 17 00:00:00 2001 From: Mike Coutermarsh Date: Fri, 12 Jan 2024 18:17:24 -0500 Subject: [PATCH] Fix sslca param + disable schema dumps for psdb - sslca doesnt need an underscore For the schema dump. I've found that when rails generates schema.rb or structure.sql, it runs an incredible amount of queries to construct dump. Normally, with local mysql this is fine because there is nearly no latency per query. When running this against a cloud database, it adds up very quickly. One of our example databases takes a full minute to dump (my laptop is 30ms from the database). By adding `schema_dump=`, this sets the Rails config for schema_dump to nil. Telling Rails not to run the dump. `schema_dump=false` does not work because this sets it to a string, which rails interprets at the filename where we want the dump stored. --- lib/planetscale_rails/tasks/psdb.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/planetscale_rails/tasks/psdb.rake b/lib/planetscale_rails/tasks/psdb.rake index e9ee179..d4aafd6 100644 --- a/lib/planetscale_rails/tasks/psdb.rake +++ b/lib/planetscale_rails/tasks/psdb.rake @@ -85,12 +85,14 @@ 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=" + # 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) } - url = "#{adapter}://#{username}:#{password}@#{host}:3306/#{database}?ssl_mode=VERIFY_IDENTITY" if ssl_ca_path - url += "&ssl_ca=#{ssl_ca_path}" + url += "&sslca=#{ssl_ca_path}" end url