planetscale_rails 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a729aacf558e6da145241a597684adb4d29955b6eeab42f29240b770c8a3408a
4
- data.tar.gz: c87ade0cd8a1cb10439d1d59fbeb9337b242ec2ad1c5ce3b5dc49ab7c18e7c61
3
+ metadata.gz: 2931af7118563daf471a6cb841092414d1f97f30d63422f9b820793263514505
4
+ data.tar.gz: da1a9e9be575f8b700a9bc03f89a7e2ea37965fdbcccef8d10503575b69f8bd2
5
5
  SHA512:
6
- metadata.gz: c9a2a1aef31f58431a6bbfe557b7daafb25964c87eb264b41bd00b32ac8e646cc1d5f6c3aa349701446bb468d7ed0e1b5eac4043c1dd7bf0fbf3b3d023625980
7
- data.tar.gz: 9d6c76a0c66b8137af59292c897952dbe2e8e261aeb0f2ae7a4cfe082a6fff332b09878df8861153d747a46259f0cb65c478787c3c92aaf9e3053c5ece674ddd
6
+ metadata.gz: 9ff57fc84afdec5532f9cf64b7303f29132697669480946897339adc3b05fc69de7d960ac2ab7f8e0d36667c0d9d97fc4cf3a1bb3a649e5ecce8672dd1f3e5a9
7
+ data.tar.gz: aedbf2e8e9be49963a76cab44b0c4791496ad8a6924734d61002b24ffb3c1407df27ead18900816dbb818048151894f63782adaece35beb28fe1e5fe28796d37
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- planetscale_rails (0.2.7)
4
+ planetscale_rails (0.2.9)
5
5
  colorize (~> 1.0)
6
6
  rails (>= 6.0, < 9)
7
7
 
data/actions-example.md CHANGED
@@ -79,8 +79,8 @@ jobs:
79
79
  run: |
80
80
  bundle exec rails psdb:migrate > migration-output.txt
81
81
  env:
82
- PSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
83
- PSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}
82
+ PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
83
+ PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}
84
84
  - name: Open DR if migrations
85
85
  run: |
86
86
  if grep -q "migrated" migration-output.txt; then
@@ -72,11 +72,20 @@ end
72
72
 
73
73
  namespace :psdb do
74
74
  task check_ci: :environment do
75
- use_service_token = ENV["PSCALE_SERVICE_TOKEN"] && ENV["PSCALE_SERVICE_TOKEN_ID"]
75
+ service_token = ENV["PSCALE_SERVICE_TOKEN"] || ENV["PLANETSCALE_SERVICE_TOKEN"]
76
+ service_token_id = ENV["PSCALE_SERVICE_TOKEN_ID"] || ENV["PLANETSCALE_SERVICE_TOKEN_ID"]
77
+ service_token_available = service_token && service_token_id
78
+
76
79
  if ENV["CI"]
77
- raise "For CI, you can only authenticate using service tokens." unless use_service_token
80
+ unless service_token_available
81
+ missing_vars = []
82
+ missing_vars << "PLANETSCALE_SERVICE_TOKEN" unless service_token
83
+ missing_vars << "PLANETSCALE_SERVICE_TOKEN_ID" unless service_token_id
84
+
85
+ raise "Unable to authenticate to PlanetScale. Missing environment variables: #{missing_vars.join(", ")}"
86
+ end
78
87
 
79
- service_token_config = "--service-token #{ENV["PSCALE_SERVICE_TOKEN"]} --service-token-id #{ENV["PSCALE_SERVICE_TOKEN_ID"]}"
88
+ service_token_config = "--service-token #{service_token} --service-token-id #{service_token_id}"
80
89
 
81
90
  ENV["SERVICE_TOKEN_CONFIG"] = service_token_config
82
91
  end
@@ -191,6 +200,30 @@ namespace :psdb do
191
200
  end
192
201
 
193
202
  namespace :schema do
203
+ desc "Connects to the current PlanetScale branch and runs rails db:schema:load"
204
+ task load: %i[environment check_ci create_creds] do
205
+ db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
206
+
207
+ unless db_configs.size == 1
208
+ raise "Found multiple database configurations, please specify which database you want to load schema for using `psdb:schema:load:<database_name>`".colorize(:red)
209
+ end
210
+
211
+ puts "Loading schema..."
212
+
213
+ command = "DATABASE_URL=\"#{ENV["PSCALE_DATABASE_URL"]}\" bundle exec rails db:schema:load"
214
+ IO.popen(command) do |io|
215
+ io.each_line do |line|
216
+ puts line
217
+ end
218
+ end
219
+
220
+ unless $CHILD_STATUS.success?
221
+ puts "Failed to load schema".colorize(:red)
222
+ end
223
+ ensure
224
+ delete_password
225
+ end
226
+
194
227
  namespace :load do
195
228
  ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
196
229
  desc "Connects to the current PlanetScale branch and runs rails db:schema:load:#{name}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlanetscaleRails
4
- VERSION = "0.2.8"
4
+ VERSION = "0.2.10"
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.8
4
+ version: 0.2.10
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-12-19 00:00:00.000000000 Z
12
+ date: 2025-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize