planetscale_rails 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1c96f1384c6bcee4a33e81124384b80ce8cff99823b1d5fc77ad926967087a4
4
- data.tar.gz: '0880e54628a3c0b22a98f1883dce8fd6ac4aee57315fffab014d07c9da66e014'
3
+ metadata.gz: a94c9bffa66e63c43ca885083022c938fd8d36f2b61f221b5a6b55456db04ec2
4
+ data.tar.gz: 48d42fccafd3a78f526e334f3db0579efe2f08dfbb7fb69f6d01dd5a9dfc2197
5
5
  SHA512:
6
- metadata.gz: c4fabd32053c4456bdd002729f21fd9548905a7fc8472a97dd23fb0f1aed9df5798381cae839fd4495b0acacdc97170c47b92312cc38c78a0a31df3911097765
7
- data.tar.gz: 2f50ab3be8305f60c81c11d625f470775678bf311d103c1301d982fb1aa5f6c39ac8b176f21bd8eb4ea511098f22e8a77a3b09cdb459130ea60bdddcee37ae57
6
+ metadata.gz: b5fadeddff7396b8d6347c07549a24979e5766fc9207b140ed44ee055b1e1d73ed04966892052f440efe5f82d133c7fb7107a0bf7987739e2421d7f9d25fcead
7
+ data.tar.gz: cfe46c69ed1b3366c1ac3a98f8298c9c73e5e8213a6ff1dcc29dc16c4f675965ccd363b4e903342a2a6ee487c4fef18dc74f7746d39704ee75565977c8170f2f
data/README.md CHANGED
@@ -35,6 +35,18 @@ bundle install
35
35
 
36
36
  Make sure you have the [`pscale` CLI installed](https://github.com/planetscale/cli#installation).
37
37
 
38
+ ### Disable schema dump
39
+
40
+ Add the following to your `config/application.rb`.
41
+
42
+ ```ruby
43
+ if ENV["DISABLE_SCHEMA_DUMP"]
44
+ config.active_record.dump_schema_after_migration = false
45
+ end
46
+ ```
47
+
48
+ This will allow the gem to disable schema dumping after running `psdb:migrate`.
49
+
38
50
  ## Usage
39
51
 
40
52
  1. Using pscale, create a new branch. This command will create a local `.pscale.yml` file. You should add it to your `.gitignore`.
@@ -78,6 +90,15 @@ We recommend using GitHub Actions to automate the creation of PlanetScale branch
78
90
 
79
91
  If your application has minimal data and schema changes are a low risk event, then running `psdb:migrate` directly against production is perfectly fine. As your datasize grows and your application becomes busier, the risk of schema changes increase and we highly recommend using the deploy request flow. It's the best way available to safely migrate your schema.
80
92
 
93
+ ## How to safely drop a column
94
+
95
+ Before dropping the column in your database, there are a couple steps to take in your application to safely remove the column without any risk to your production application.
96
+
97
+ 1. Remove all references to the column in your code.
98
+ 2. Add the column name to `self.ignored_columns += %w(column_name)` in the model. [More on ignored_columns](https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-ignored_columns-3D).
99
+ 3. Deploy this code to production. This ensures your application is no longer making use of the column in production and it's removed from the schema cache.
100
+ 4. Follow the PlanetScale deploy request flow to drop the column.
101
+
81
102
  ## Usage with GitHub Actions
82
103
 
83
104
  See the [GitHub Actions examples](actions-example.md) doc for ways to automate your schema migrations with PlanetScale + Actions.
@@ -7,8 +7,35 @@ require "colorize"
7
7
 
8
8
  databases = ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
9
9
 
10
+ def find_git_directory
11
+ return ENV["GIT_DIR"] if ENV["GIT_DIR"] && !ENV["GIT_DIR"].empty?
12
+
13
+ # it's not set as an env, so let's try to find it
14
+ current_path = Pathname.new(Dir.pwd)
15
+
16
+ until current_path.root?
17
+ git_dir = current_path.join(".git")
18
+ return current_path.to_s if git_dir.exist? # this can be a directory or a file (worktree)
19
+
20
+ current_path = current_path.parent
21
+ end
22
+
23
+ nil
24
+ end
25
+
26
+ def load_pscale_config
27
+ if File.exist?(".pscale.yml")
28
+ return YAML.load_file(".pscale.yml")
29
+ end
30
+
31
+ # otherwise, look for a git root directory and load it from there
32
+ git_dir = find_git_directory
33
+ pscale_yaml_path = File.join(git_dir, ".pscale.yml")
34
+ YAML.load_file(pscale_yaml_path)
35
+ end
36
+
10
37
  def puts_deploy_request_instructions
11
- ps_config = YAML.load_file(".pscale.yml")
38
+ ps_config = load_pscale_config
12
39
  database = ps_config["database"]
13
40
  branch = ps_config["branch"]
14
41
  org = ps_config["org"]
@@ -25,7 +52,7 @@ def delete_password
25
52
  password_id = ENV["PSCALE_PASSWORD_ID"]
26
53
  return unless password_id
27
54
 
28
- ps_config = YAML.load_file(".pscale.yml")
55
+ ps_config = load_pscale_config
29
56
  database = ps_config["database"]
30
57
  branch = ps_config["branch"]
31
58
 
@@ -56,7 +83,7 @@ namespace :psdb do
56
83
  end
57
84
 
58
85
  def create_connection_string
59
- ps_config = YAML.load_file(".pscale.yml")
86
+ ps_config = load_pscale_config
60
87
  database = ps_config["database"]
61
88
  branch = ps_config["branch"]
62
89
 
@@ -85,8 +112,7 @@ namespace :psdb do
85
112
  adapter = "trilogy"
86
113
  end
87
114
 
88
- # Setting schema_dump to nil is intentional. It prevents Rails from creating a dump after running migrations.
89
- url = "#{adapter}://#{username}:#{password}@#{host}:3306/#{database}?ssl_mode=VERIFY_IDENTITY&schema_dump="
115
+ url = "#{adapter}://#{username}:#{password}@#{host}:3306/#{database}?ssl_mode=VERIFY_IDENTITY"
90
116
 
91
117
  # Check common CA paths for certs.
92
118
  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 +134,7 @@ namespace :psdb do
108
134
  desc "Create credentials for PlanetScale and sets them to ENV['PSCALE_DATABASE_URL']"
109
135
  task "create_creds" => %i[environment check_ci] do
110
136
  ENV["PSCALE_DATABASE_URL"] = create_connection_string
137
+ ENV["DISABLE_SCHEMA_DUMP"] = "true"
111
138
  end
112
139
 
113
140
  desc "Connects to the current PlanetScale branch and runs rails db:migrate"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlanetscaleRails
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: planetscale_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Coutermarsh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-01-12 00:00:00.000000000 Z
12
+ date: 2024-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize