planetscale_rails 0.1.1 → 0.1.3

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: 619e3ba38ea708a2a1a9e3f2fd568ff0da6c03bd197f387ae73a392fc70027cc
4
- data.tar.gz: 74f418e63ea9c62f460f97621ddc0bd3de2bf52cf75bc99eab961d8078a3869b
3
+ metadata.gz: f38096cc4396fecb1efbfba9ea4bfe7f72b39c915990fb7036f8ab4ef1a1aaa2
4
+ data.tar.gz: c609fbd59e9caf5682fddd1367533c3a99a80fe1bbd7c93591da6047f8ff22cf
5
5
  SHA512:
6
- metadata.gz: bfe2af22a409d717347a2a929a19b59e5b2a03d40cf1ce3dd0ce92c7504edc81ed6781bc5992449662aacd95ec48802cbc0c3a55a6cad9d9dfb1713d3268a72d
7
- data.tar.gz: 98c020da66de785b9a7984d521aedec6bd57798a7bf106695e97bf698067ef7afa0cccab3ada6aed4b477601d3c9b5361abe8b95285371f1f0cd1b29da228014
6
+ metadata.gz: b4e11cfda4e78884bd30fe672b06517320f74a36244d96c61688d5d339478c99cff30050e31f049578fa27e5358692697b9019d0032108223d4c6dbb2e9a7c97
7
+ data.tar.gz: d236ee3a8a70d8e37be836e344c8e1a565c99149d7f301760810c8efc03ebea30e1cdb1e78458fc788b9fd9f41b1fe98fdaa4f9fc9e29cad1fb64636bf6d579f
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- planetscale_rails (0.1.0)
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.17.0)
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).
@@ -10,10 +12,10 @@ The rake tasks allow you to use local MySQL for development. When you're ready t
10
12
  against it. See [usage](#usage) for details.
11
13
 
12
14
  ```
13
- rake psdb:migrate # Migrate the database for current environment
14
- rake psdb:rollback # Rollback primary database for current environment
15
- rake psdb:schema:load # Load the current schema into the database
16
- rake psdb:setup_pscale # Setup a proxy to connect to PlanetScale
15
+ rake psdb:migrate # Migrate the database for current environment
16
+ rake psdb:rollback # Rollback primary database for current environment
17
+ rake psdb:schema:load # Load the current schema into the database
18
+ rake psdb:setup_pscale # Setup a proxy to connect to PlanetScale
17
19
  ```
18
20
 
19
21
  ## Installation
@@ -26,19 +28,23 @@ group :development do
26
28
  end
27
29
  ```
28
30
 
29
- And then execute:
31
+ And then execute in your terminal:
30
32
 
31
- $ bundle install
33
+ ```
34
+ bundle install
35
+ ```
32
36
 
33
37
  ## Usage
34
38
 
35
39
  First, make sure you have the [`pscale` CLI installed](https://github.com/planetscale/cli#installation). You'll use `pscale` to create a new branch.
36
40
 
37
- 1. `pscale branch switch my-new-branch-name --database my-db-name --create`
38
-
39
- Run this locally, it will create a new branch off of `main`. The `switch` command will update a `.pscale.yml` file to track
41
+ 1. Run this locally, it will create a new branch off of `main`. The `switch` command will update a `.pscale.yml` file to track
40
42
  that this is the branch you want to migrate.
41
43
 
44
+ ```
45
+ pscale branch switch my-new-branch-name --database my-db-name --create
46
+ ```
47
+
42
48
  **Tip:** In your database settings. Enable "Automatically copy migration data." Select "Rails/Phoenix" as the migration framework. This will auto copy your `schema_migrations` table between branches.
43
49
 
44
50
  2. Once your branch is ready, you can then use the `psdb` rake task to connect to your branch and run `db:migrate`.
@@ -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".colorize(:red) unless command?("pscale")
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 "Spawning background connect process..."
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 "Spawning background connect process..."
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
- puts "Finished running migrations."
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlanetscaleRails
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -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.1
4
+ version: 0.1.3
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-09 00:00:00.000000000 Z
12
+ date: 2023-03-18 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