planetscale_rails 0.2.10 → 0.2.11
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 +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -16
- data/README.md +8 -1
- data/Rakefile +7 -3
- data/lib/planetscale_rails/migration.rb +21 -3
- data/lib/planetscale_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56a56bc95da2ab1e339ccdac47072265744ad53472f8a664c742082d29465c7c
|
4
|
+
data.tar.gz: 11a52c1b39e61fb3ef8a78a696941a1d8adb7efe9090627cbd81ead910844d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b622c8c6b439258f765584d7fb733fd83e2340b0b99153bcb0091e02ec73653b81738c6ff5ca4a3aaf6540204f9ca694a76e09580fce803b89a23204af62f50a
|
7
|
+
data.tar.gz: 492acf71a0b36e47d115949cfbf1c500fb05a1ad9c1e7633f1a3b2f36f4c873036419c34385ea7cda43aaeaf501bd4ac2a0dc10a7b99e87e49e7eb88fe850bc1
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
planetscale_rails (0.2.
|
4
|
+
planetscale_rails (0.2.10)
|
5
5
|
colorize (~> 1.0)
|
6
6
|
rails (>= 6.0, < 9)
|
7
7
|
|
@@ -89,7 +89,6 @@ GEM
|
|
89
89
|
connection_pool (2.4.1)
|
90
90
|
crass (1.0.6)
|
91
91
|
date (3.4.1)
|
92
|
-
diff-lcs (1.5.0)
|
93
92
|
drb (2.2.1)
|
94
93
|
erubi (1.13.0)
|
95
94
|
globalid (1.2.1)
|
@@ -180,19 +179,6 @@ GEM
|
|
180
179
|
reline (0.6.0)
|
181
180
|
io-console (~> 0.5)
|
182
181
|
rexml (3.2.5)
|
183
|
-
rspec (3.12.0)
|
184
|
-
rspec-core (~> 3.12.0)
|
185
|
-
rspec-expectations (~> 3.12.0)
|
186
|
-
rspec-mocks (~> 3.12.0)
|
187
|
-
rspec-core (3.12.1)
|
188
|
-
rspec-support (~> 3.12.0)
|
189
|
-
rspec-expectations (3.12.2)
|
190
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
191
|
-
rspec-support (~> 3.12.0)
|
192
|
-
rspec-mocks (3.12.3)
|
193
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
194
|
-
rspec-support (~> 3.12.0)
|
195
|
-
rspec-support (3.12.0)
|
196
182
|
rubocop (1.47.0)
|
197
183
|
json (~> 2.3)
|
198
184
|
parallel (~> 1.10)
|
@@ -228,9 +214,9 @@ PLATFORMS
|
|
228
214
|
x86_64-linux
|
229
215
|
|
230
216
|
DEPENDENCIES
|
217
|
+
minitest (~> 5.0)
|
231
218
|
planetscale_rails!
|
232
219
|
rake (~> 13.0)
|
233
|
-
rspec (~> 3.0)
|
234
220
|
rubocop (~> 1.7)
|
235
221
|
|
236
222
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -86,7 +86,7 @@ This gem supports working with multi-keyspace PlanetScale databases. When runnin
|
|
86
86
|
|
87
87
|
**Creating new tables**
|
88
88
|
|
89
|
-
For adding a new table, you must specify the `keyspace` for the table. When running `psdb:migrate`, this gem will create the table in the correct keyspace. When running the migration locally against plain MySQL,
|
89
|
+
For adding a new table, you must specify the `keyspace` for the table either as part of create_table or by setting an environment variable. When running `psdb:migrate`, this gem will create the table in the correct keyspace. When running the migration locally against plain MySQL,
|
90
90
|
the keyspace will be ignored and the table will be created as normal within the same database.
|
91
91
|
|
92
92
|
```ruby
|
@@ -95,6 +95,13 @@ create_table(:new_table, id: { type: :bigint, unsigned: true }, keyspace: "keysp
|
|
95
95
|
end
|
96
96
|
```
|
97
97
|
|
98
|
+
_Optionally_: You can set a default keyspace for all new tables by setting `PLANETSCALE_DEFAULT_KEYSPACE` to the keyspace name. If a keyspace is not present in the `create_table` call, then the ENV var will be used when set.
|
99
|
+
|
100
|
+
The keyspace resolution follows this precedence:
|
101
|
+
1. Explicit `keyspace:` option in create_table
|
102
|
+
2. `PLANETSCALE_DEFAULT_KEYSPACE` environment variable
|
103
|
+
3. No keyspace (standard behavior)
|
104
|
+
|
98
105
|
## Using PlanetScale deploy requests vs `psdb:migrate` directly in production.
|
99
106
|
|
100
107
|
PlanetScale's deploy requests [solve the schema change problem](https://planetscale.com/docs/learn/how-online-schema-change-tools-work). They make a normally high risk operation, safe. This is done by running your schema change using [Vitess's online schema change](https://vitess.io/docs/18.0/user-guides/schema-changes/) tools. Once the change is made, a deploy request is [also revertible without data loss](https://planetscale.com/blog/revert-a-migration-without-losing-data). None of this is possible when running `rails db:migrate` directly against your production database.
|
data/Rakefile
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "
|
4
|
+
require "rake/testtask"
|
5
5
|
|
6
|
-
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
7
11
|
|
8
12
|
require "rubocop/rake_task"
|
9
13
|
|
10
14
|
RuboCop::RakeTask.new
|
11
15
|
|
12
|
-
task default: %i[
|
16
|
+
task default: %i[test rubocop]
|
@@ -3,16 +3,34 @@
|
|
3
3
|
module PlanetscaleRails
|
4
4
|
module Migration
|
5
5
|
module Current
|
6
|
-
# Allows users to set the `keyspace` option in their migration file.
|
6
|
+
# Allows users to set the `keyspace` option in their migration file or via an ENV var PLANETSCALE_DEFAULT_KEYSPACE.
|
7
7
|
# If the migration is being run against PlanetScale (i.e. `ENABLE_PSDB` is set), then we prepend the keyspace to the table name.
|
8
8
|
#
|
9
9
|
# For local MySQL databases, the keyspace is ignored.
|
10
10
|
def create_table(table_name, **options)
|
11
|
-
|
12
|
-
|
11
|
+
keyspace = options[:keyspace]
|
12
|
+
|
13
|
+
if keyspace.blank? && ENV["PLANETSCALE_DEFAULT_KEYSPACE"].present?
|
14
|
+
keyspace = ENV["PLANETSCALE_DEFAULT_KEYSPACE"]
|
15
|
+
log_keyspace_usage(keyspace)
|
16
|
+
end
|
17
|
+
|
18
|
+
if ENV["ENABLE_PSDB"] && keyspace.present?
|
19
|
+
table_name = "#{keyspace}.#{table_name}"
|
13
20
|
end
|
14
21
|
super(table_name, **options.except(:keyspace))
|
15
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def log_keyspace_usage(keyspace)
|
27
|
+
message = "Using keyspace '#{keyspace}' from PLANETSCALE_DEFAULT_KEYSPACE environment variable"
|
28
|
+
if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
|
29
|
+
Rails.logger.info(message)
|
30
|
+
else
|
31
|
+
puts message
|
32
|
+
end
|
33
|
+
end
|
16
34
|
end
|
17
35
|
end
|
18
36
|
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.
|
4
|
+
version: 0.2.11
|
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: 2025-06-
|
12
|
+
date: 2025-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|