planetscale_rails 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/README.md +2 -0
- data/lib/planetscale_rails/tasks/psdb.rake +23 -14
- data/lib/planetscale_rails/version.rb +1 -1
- data/planetscale_rails.gemspec +1 -3
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ed08836cfb00024906d50ede95a0237ee6fbce02ab89d138a812e939d1056c5
|
4
|
+
data.tar.gz: 8080c0fe4eaf9d00d8e851dfe087a55cdf4dbf741228b29aea1ebbb92706f463
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89b0dc3b6d77bcd9663b10706bcb82021dc15b6f15cb1b3446008eef71a22abd3af20f07b58a5b3cb4c590e2ca65c1a202e2cf364f3bd1f2e4b97fcd779432a
|
7
|
+
data.tar.gz: 13ac640ae92257eca79aa2d7462280f1361c4e275c9b7c490da8bba9ca4f15c58f32cf1738e15bbe59d23643bd301b6744c76232f6c5c7c246a8995444851659
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
planetscale_rails (0.1.
|
4
|
+
planetscale_rails (0.1.1)
|
5
|
+
colorize (~> 0.8.1)
|
5
6
|
rails (~> 7.0)
|
6
7
|
|
7
8
|
GEM
|
@@ -74,6 +75,7 @@ GEM
|
|
74
75
|
tzinfo (~> 2.0)
|
75
76
|
ast (2.4.2)
|
76
77
|
builder (3.2.4)
|
78
|
+
colorize (0.8.1)
|
77
79
|
concurrent-ruby (1.2.2)
|
78
80
|
crass (1.0.6)
|
79
81
|
date (3.3.3)
|
@@ -95,7 +97,7 @@ GEM
|
|
95
97
|
marcel (1.0.2)
|
96
98
|
method_source (1.0.0)
|
97
99
|
mini_mime (1.1.2)
|
98
|
-
minitest (5.
|
100
|
+
minitest (5.18.0)
|
99
101
|
net-imap (0.3.4)
|
100
102
|
date
|
101
103
|
net-protocol
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# PlanetScale Rails
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/planetscale_rails.svg)](https://badge.fury.io/rb/planetscale_rails)
|
4
|
+
|
3
5
|
Rake tasks for easily running Rails migrations against PlanetScale database branches.
|
4
6
|
|
5
7
|
For information on how to connect your Rails app to PlanetScale, please [see our guide here](https://planetscale.com/docs/tutorials/connect-rails-app).
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require "English"
|
4
4
|
require "yaml"
|
5
5
|
require "pty"
|
6
|
+
require "colorize"
|
6
7
|
|
7
8
|
databases = ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
|
8
9
|
|
@@ -11,6 +12,16 @@ def shared_deps(name = nil)
|
|
11
12
|
return %i[environment check_ci] if name.nil?
|
12
13
|
end
|
13
14
|
|
15
|
+
def puts_deploy_request_instructions
|
16
|
+
ps_config = YAML.load_file(".pscale.yml")
|
17
|
+
database = ps_config["database"]
|
18
|
+
branch = ps_config["branch"]
|
19
|
+
org = ps_config["org"]
|
20
|
+
|
21
|
+
puts "Create a deploy request for '#{branch}' by running:\n"
|
22
|
+
puts " pscale deploy-request create #{database} #{branch} --org #{org}\n\n"
|
23
|
+
end
|
24
|
+
|
14
25
|
def kill_pscale_process
|
15
26
|
Process.kill("TERM", ENV["PSCALE_PID"].to_i) if ENV["PSCALE_PID"]
|
16
27
|
end
|
@@ -35,15 +46,14 @@ namespace :psdb do
|
|
35
46
|
database = ps_config["database"]
|
36
47
|
branch = ps_config["branch"]
|
37
48
|
|
38
|
-
raise "You must have `pscale` installed on your computer" unless command?("pscale")
|
49
|
+
raise "You must have `pscale` installed on your computer" unless command?("pscale").colorize(:red)
|
39
50
|
if branch.blank? || database.blank?
|
40
|
-
raise "Your branch is not properly setup, please switch to a branch by using the CLI."
|
51
|
+
raise "Your branch is not properly setup, please switch to a branch by using the CLI.".colorize(:red)
|
41
52
|
end
|
42
|
-
raise "Unable to run migrations against the main branch" if branch == "main"
|
43
53
|
|
44
54
|
r, = PTY.open
|
45
55
|
|
46
|
-
puts "
|
56
|
+
puts "Connecting to PlanetScale..."
|
47
57
|
|
48
58
|
# Spawns the process in the background
|
49
59
|
pid = Process.spawn("pscale connect #{database} #{branch} --port 3305 #{ENV["SERVICE_TOKEN_CONFIG"]}", out: r)
|
@@ -59,10 +69,7 @@ namespace :psdb do
|
|
59
69
|
time_elapsed = Time.current - start_time
|
60
70
|
end
|
61
71
|
|
62
|
-
raise "Timed out waiting for PlanetScale connection to be established" if time_elapsed > 10.seconds
|
63
|
-
|
64
|
-
# Comment out for now, this messes up when running migrations.
|
65
|
-
# Kernel.system("bundle exec rails db:environment:set RAILS_ENV=development")
|
72
|
+
raise "Timed out waiting for PlanetScale connection to be established".colorize(:red) if time_elapsed > 10.seconds
|
66
73
|
ensure
|
67
74
|
r&.close
|
68
75
|
end
|
@@ -89,7 +96,7 @@ namespace :psdb do
|
|
89
96
|
|
90
97
|
r, = PTY.open
|
91
98
|
|
92
|
-
puts "
|
99
|
+
puts "Connecting to PlanetScale..."
|
93
100
|
|
94
101
|
# Spawns the process in the background
|
95
102
|
pid = Process.spawn("pscale connect #{database} #{branch} --port 3305 #{ENV["SERVICE_TOKEN_CONFIG"]}", out: r)
|
@@ -120,13 +127,13 @@ namespace :psdb do
|
|
120
127
|
db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
|
121
128
|
|
122
129
|
unless db_configs.size == 1
|
123
|
-
raise "Found multiple database configurations, please specify which database you want to migrate using `psdb:migrate:<database_name>`"
|
130
|
+
raise "Found multiple database configurations, please specify which database you want to migrate using `psdb:migrate:<database_name>`".colorize(:red)
|
124
131
|
end
|
125
132
|
|
126
133
|
puts "Running migrations..."
|
127
134
|
Kernel.system("bundle exec rails db:migrate")
|
128
|
-
puts "Finished running migrations"
|
129
|
-
|
135
|
+
puts "Finished running migrations\n".colorize(:green)
|
136
|
+
puts_deploy_request_instructions
|
130
137
|
ensure
|
131
138
|
kill_pscale_process
|
132
139
|
end
|
@@ -139,7 +146,9 @@ namespace :psdb do
|
|
139
146
|
# We run it using the Kernel.system here because this properly handles
|
140
147
|
# when exceptions occur whereas Rake::Task.invoke does not.
|
141
148
|
Kernel.system("bundle exec rake db:migrate:#{name}")
|
142
|
-
|
149
|
+
|
150
|
+
puts "Finished running migrations\n".colorize(:green)
|
151
|
+
puts_deploy_request_instructions
|
143
152
|
ensure
|
144
153
|
kill_pscale_process
|
145
154
|
end
|
@@ -186,7 +195,7 @@ namespace :psdb do
|
|
186
195
|
# We run it using the Kernel.system here because this properly handles
|
187
196
|
# when exceptions occur whereas Rake::Task.invoke does not.
|
188
197
|
Kernel.system("bundle exec rake db:rollback:#{name}")
|
189
|
-
puts "Finished rolling back migrations."
|
198
|
+
puts "Finished rolling back migrations.".colorize(:green)
|
190
199
|
ensure
|
191
200
|
kill_pscale_process
|
192
201
|
end
|
data/planetscale_rails.gemspec
CHANGED
@@ -28,8 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
+
spec.add_dependency "colorize", "~> 0.8.1"
|
31
32
|
spec.add_dependency "rails", "~> 7.0"
|
32
|
-
|
33
|
-
# For more information and examples about making a new gem, checkout our
|
34
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
35
33
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Coutermarsh
|
@@ -9,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.8.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.8.1
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: rails
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|