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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e758beb05db7ba2729b599570f430312bfe8c133a83e7bf5cc9403e4c6d768a9
4
- data.tar.gz: b24ed790565dc4c19e9d20c6a4a89e3bc518ea8402c9b2e685d6fcf051b5ef26
3
+ metadata.gz: fee3961cfdf8fe1ad8c3afbf5fa606c142bd647e318c256ec20c7e8d2d34d168
4
+ data.tar.gz: db9d38d31fd26ef299f42ef48c2457bef2fcdb29de9a942b007437efeba26b25
5
5
  SHA512:
6
- metadata.gz: efa52a6f8061cf4fa5047b74b704849a2534a2c76f616f981b6f966269eeab295e012e1287c3912a459f1282055f4447edecd1145a8d912d6833db2912ed31e3
7
- data.tar.gz: aa22a6034264f82d77ebdc2584fdbf96743a9b62fc49f3f2ec9e76319c5f3c611267f62ac3da9f083a00cfc02e7fc5a027bf88281707c736b9f6874ac9fc5201
6
+ metadata.gz: 47316b6a2c73fd55fe3ea64a0abd1086d10e959dc10eff0e986b493f221a6a439adc2a65a203c4438a6fc14191864880372cad19561c57177118bad767a35009
7
+ data.tar.gz: 89a78de250e9a5fe952d1fc795bc87ec4cce8dd2f442b584a547d48044aa12b0832d7edafc79141afa4e4ca6681ee2f87281bd36548c3b99bf17ecec3845753d
@@ -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
- One exception is changing a `varchar` column to `text`, which is safe in Postgres.
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
- # assume Postgres 9.1+ since previous versions are EOL
108
- if postgresql? && type.to_s == "text"
109
- found_column = connection.columns(table).find { |c| c.name.to_s == column.to_s }
110
- safe = found_column && found_column.type == :string
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
- @migration.stop!(message.gsub(/%(?!{)/, "%%") % vars, header: header || "Dangerous operation detected")
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)
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
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.2
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-02-03 00:00:00.000000000 Z
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