strong_migrations 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +18 -1
- data/lib/strong_migrations/checker.rb +44 -6
- data/lib/strong_migrations/version.rb +1 -1
- 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: fee3961cfdf8fe1ad8c3afbf5fa606c142bd647e318c256ec20c7e8d2d34d168
|
4
|
+
data.tar.gz: db9d38d31fd26ef299f42ef48c2457bef2fcdb29de9a942b007437efeba26b25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47316b6a2c73fd55fe3ea64a0abd1086d10e959dc10eff0e986b493f221a6a439adc2a65a203c4438a6fc14191864880372cad19561c57177118bad767a35009
|
7
|
+
data.tar.gz: 89a78de250e9a5fe952d1fc795bc87ec4cce8dd2f442b584a547d48044aa12b0832d7edafc79141afa4e4ca6681ee2f87281bd36548c3b99bf17ecec3845753d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.6.3 (2020-04-04)
|
2
|
+
|
3
|
+
- Increasing precision of `decimal` or `numeric` column is safe in Postgres 9.2+
|
4
|
+
- Making `decimal` or `numeric` column unconstrained is safe in Postgres 9.2+
|
5
|
+
- Changing between `timestamp` and `timestamptz` when session time zone is UTC in Postgres 12+
|
6
|
+
- Increasing the length of a `varchar` column from under 255 up to 255 in MySQL and MariaDB
|
7
|
+
- Increasing the length of a `varchar` column over 255 in MySQL and MariaDB
|
8
|
+
|
1
9
|
## 0.6.2 (2020-02-03)
|
2
10
|
|
3
11
|
- Fixed PostgreSQL version check
|
data/README.md
CHANGED
@@ -303,7 +303,17 @@ class ChangeSomeColumnType < ActiveRecord::Migration[6.0]
|
|
303
303
|
end
|
304
304
|
```
|
305
305
|
|
306
|
-
|
306
|
+
A few changes are safe in Postgres:
|
307
|
+
|
308
|
+
- Changing between `varchar` and `text` columns
|
309
|
+
- Increasing the precision of a `decimal` or `numeric` column
|
310
|
+
- Making a `decimal` or `numeric` column unconstrained
|
311
|
+
- Changing between `timestamp` and `timestamptz` columns when session time zone is UTC in Postgres 12+
|
312
|
+
|
313
|
+
And a few in MySQL and MariaDB:
|
314
|
+
|
315
|
+
- Increasing the length of a `varchar` column from under 255 up to 255
|
316
|
+
- Increasing the length of a `varchar` column over 255
|
307
317
|
|
308
318
|
#### Good
|
309
319
|
|
@@ -690,5 +700,12 @@ To get started with development:
|
|
690
700
|
git clone https://github.com/ankane/strong_migrations.git
|
691
701
|
cd strong_migrations
|
692
702
|
bundle install
|
703
|
+
|
704
|
+
# Postgres
|
705
|
+
createdb strong_migrations_test
|
693
706
|
bundle exec rake test
|
707
|
+
|
708
|
+
# MySQL and MariaDB
|
709
|
+
mysqladmin create strong_migrations_test
|
710
|
+
ADAPTER=mysql2 bundle exec rake test
|
694
711
|
```
|
@@ -101,13 +101,50 @@ Then add the NOT NULL constraint."
|
|
101
101
|
raise_error :add_column_json
|
102
102
|
end
|
103
103
|
when :change_column
|
104
|
-
table, column, type = args
|
104
|
+
table, column, type, options = args
|
105
|
+
options ||= {}
|
105
106
|
|
106
107
|
safe = false
|
107
|
-
|
108
|
-
if
|
109
|
-
|
110
|
-
|
108
|
+
existing_column = connection.columns(table).find { |c| c.name.to_s == column.to_s }
|
109
|
+
if existing_column
|
110
|
+
sql_type = existing_column.sql_type.split("(").first
|
111
|
+
if postgresql?
|
112
|
+
case type.to_s
|
113
|
+
when "string", "text"
|
114
|
+
# safe to change limit for varchar
|
115
|
+
safe = ["character varying", "text"].include?(sql_type)
|
116
|
+
when "numeric", "decimal"
|
117
|
+
# numeric and decimal are equivalent and can be used interchangably
|
118
|
+
safe = ["numeric", "decimal"].include?(sql_type) &&
|
119
|
+
(
|
120
|
+
(
|
121
|
+
# unconstrained
|
122
|
+
!options[:precision] && !options[:scale]
|
123
|
+
) || (
|
124
|
+
# increased precision, same scale
|
125
|
+
options[:precision] && existing_column.precision &&
|
126
|
+
options[:precision] >= existing_column.precision &&
|
127
|
+
options[:scale] == existing_column.scale
|
128
|
+
)
|
129
|
+
)
|
130
|
+
when "datetime", "timestamp", "timestamptz"
|
131
|
+
safe = ["timestamp without time zone", "timestamp with time zone"].include?(sql_type) &&
|
132
|
+
postgresql_version >= Gem::Version.new("12") &&
|
133
|
+
connection.select_all("SHOW timezone").first["TimeZone"] == "UTC"
|
134
|
+
end
|
135
|
+
elsif mysql? || mariadb?
|
136
|
+
case type.to_s
|
137
|
+
when "string"
|
138
|
+
# https://dev.mysql.com/doc/refman/5.7/en/innodb-online-ddl-operations.html
|
139
|
+
# https://mariadb.com/kb/en/innodb-online-ddl-operations-with-the-instant-alter-algorithm/#changing-the-data-type-of-a-column
|
140
|
+
# increased limit, but doesn't change number of length bytes
|
141
|
+
# 1-255 = 1 byte, 256-65532 = 2 bytes, 65533+ = too big for varchar
|
142
|
+
limit = options[:limit] || 255
|
143
|
+
safe = ["varchar"].include?(sql_type) &&
|
144
|
+
limit >= existing_column.limit &&
|
145
|
+
(limit <= 255 || existing_column.limit > 255)
|
146
|
+
end
|
147
|
+
end
|
111
148
|
end
|
112
149
|
raise_error :change_column unless safe
|
113
150
|
when :create_table
|
@@ -325,7 +362,8 @@ Then add the NOT NULL constraint."
|
|
325
362
|
end
|
326
363
|
|
327
364
|
# escape % not followed by {
|
328
|
-
|
365
|
+
message = message.gsub(/%(?!{)/, "%%") % vars if message.include?("%")
|
366
|
+
@migration.stop!(message, header: header || "Dangerous operation detected")
|
329
367
|
end
|
330
368
|
|
331
369
|
def constraint_str(statement, identifiers)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -82,6 +82,20 @@ dependencies:
|
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: mysql2
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
85
99
|
description:
|
86
100
|
email:
|
87
101
|
- andrew@chartkick.com
|