ridgepole 0.8.8 → 0.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +65 -0
- data/.rubocop.yml +11 -36
- data/Appraisals +4 -5
- data/README.md +27 -17
- data/bin/ridgepole +13 -1
- data/gemfiles/{activerecord_5.0.gemfile → activerecord_6.1.gemfile} +1 -2
- data/lib/ridgepole/client.rb +8 -3
- data/lib/ridgepole/default_limit.rb +1 -1
- data/lib/ridgepole/delta.rb +16 -1
- data/lib/ridgepole/diff.rb +55 -20
- data/lib/ridgepole/dsl_parser.rb +3 -4
- data/lib/ridgepole/dsl_parser/context.rb +1 -1
- data/lib/ridgepole/dsl_parser/table_definition.rb +51 -41
- data/lib/ridgepole/execute_expander.rb +10 -1
- data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +9 -1
- data/lib/ridgepole/external_sql_executer.rb +12 -1
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +5 -3
- data/spec/erb_helper.rb +9 -5
- data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +2 -2
- data/spec/mysql/cli/ridgepole_spec.rb +35 -1
- data/spec/mysql/collation/collation_spec.rb +8 -8
- data/spec/mysql/dump/dump_class_method_spec.rb +3 -3
- data/spec/mysql/dump/dump_spec.rb +3 -3
- data/spec/mysql/dump/dump_unknown_column_type_spec.rb +1 -1
- data/spec/mysql/dump/dump_without_table_options_spec.rb +2 -2
- data/spec/mysql/fk/migrate_create_fk_spec.rb +79 -10
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +88 -0
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +109 -18
- data/spec/mysql/migrate/migrate_change_column8_spec.rb +38 -5
- data/spec/mysql/migrate/migrate_change_index_spec.rb +7 -1
- data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_primary_key_spec.rb +30 -5
- data/spec/mysql/migrate/migrate_same_spec.rb +3 -3
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +5 -2
- data/spec/postgresql/dump/dump_spec.rb +1 -1
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +11 -4
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +4 -0
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +11 -4
- data/spec/postgresql/migrate/migrate_same_spec.rb +1 -1
- data/spec/spec_condition.rb +4 -0
- data/spec/spec_helper.rb +2 -1
- metadata +43 -20
- data/.travis.yml +0 -45
- data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +0 -31
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +0 -141
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df81adabc9afddf2d409c647190e217dd71a3948b8d3b9c3753f36c8519df701
|
4
|
+
data.tar.gz: 3df1478fbdaa3ef5ac2ac192cf1a022901753f1f4adac72f20b93f17b49dcb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae3fa69120a6ba5103f512092694abd151073ae3e7ed27c23677aa9f617b4a986565c29e6088fbb0f4ae1a0da0cfc425b5c67c8e8b1b19b956164dd8c7fcdf87
|
7
|
+
data.tar.gz: bce34561a3ac8489bbc3466e7d63fd0c4c4a557659e28751bfc06fe3f058d3725493c34426cab2a1171ea86e1e35d4fdde8be3b1e31186599a73748a3a2563a3
|
@@ -0,0 +1,65 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby:
|
14
|
+
- 2.4
|
15
|
+
- 2.5
|
16
|
+
- 2.6
|
17
|
+
- 2.7
|
18
|
+
env:
|
19
|
+
- MYSQL56=1
|
20
|
+
- MYSQL57=1
|
21
|
+
- POSTGRESQL=1
|
22
|
+
gemfile:
|
23
|
+
- gemfiles/activerecord_5.1.gemfile
|
24
|
+
- gemfiles/activerecord_5.2.gemfile
|
25
|
+
- gemfiles/activerecord_6.0.gemfile
|
26
|
+
- gemfiles/activerecord_6.1.gemfile
|
27
|
+
exclude:
|
28
|
+
- ruby: 2.4
|
29
|
+
gemfile: gemfiles/activerecord_6.0.gemfile
|
30
|
+
- ruby: 2.4
|
31
|
+
gemfile: gemfiles/activerecord_6.1.gemfile
|
32
|
+
|
33
|
+
steps:
|
34
|
+
- uses: actions/checkout@v2
|
35
|
+
- uses: actions/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
- uses: actions/cache@v2
|
39
|
+
with:
|
40
|
+
path: gemfiles/vendor/bundle
|
41
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles('ridgepole.gemspec', '**/Gemfile', '${{ matrix.gemfile }}') }}
|
42
|
+
restore-keys: |
|
43
|
+
${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-
|
44
|
+
|
45
|
+
- name: Setup dependencies
|
46
|
+
run: |
|
47
|
+
for i in {1..60}; do docker-compose up -d && break; sleep 1; done
|
48
|
+
|
49
|
+
gem install bundler
|
50
|
+
bundle config path vendor/bundle
|
51
|
+
bundle install --jobs 4 --retry 3
|
52
|
+
|
53
|
+
# Wait until database servers start
|
54
|
+
function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 13316 -ppassword ping; }
|
55
|
+
function mysql57_ping { mysqladmin -u root -h 127.0.0.1 -P 13317 -ppassword ping; }
|
56
|
+
function pg_ping { PGPASSWORD=password pg_isready -U postgres -h 127.0.0.1 -p 15442; }
|
57
|
+
for i in {1..60}; do mysql_ping && break; sleep 1; done
|
58
|
+
for i in {1..60}; do mysql57_ping && break; sleep 1; done
|
59
|
+
for i in {1..60}; do pg_ping && break; sleep 1; done
|
60
|
+
env:
|
61
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
62
|
+
|
63
|
+
- run: ${{ matrix.env }} bundle exec rake
|
64
|
+
env:
|
65
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
data/.rubocop.yml
CHANGED
@@ -3,6 +3,7 @@ AllCops:
|
|
3
3
|
- 'gemfiles/**/*'
|
4
4
|
- 'omnibus-ridgepole/**/*'
|
5
5
|
TargetRubyVersion: 2.4
|
6
|
+
NewCops: enable
|
6
7
|
Bundler/OrderedGems:
|
7
8
|
Include:
|
8
9
|
- 'Appraisals'
|
@@ -30,8 +31,6 @@ Style/Documentation:
|
|
30
31
|
Enabled: false
|
31
32
|
Style/GuardClause:
|
32
33
|
Enabled: false
|
33
|
-
Style/MethodMissingSuper:
|
34
|
-
Enabled: false
|
35
34
|
Style/MixinUsage:
|
36
35
|
Exclude:
|
37
36
|
- 'spec/**/*'
|
@@ -41,37 +40,13 @@ Layout/ClosingHeredocIndentation:
|
|
41
40
|
Enabled: false
|
42
41
|
Style/NumericPredicate:
|
43
42
|
Enabled: false
|
44
|
-
|
45
|
-
Enabled:
|
46
|
-
|
47
|
-
Enabled:
|
48
|
-
|
49
|
-
Enabled:
|
50
|
-
Lint/
|
51
|
-
Enabled:
|
52
|
-
|
53
|
-
Enabled:
|
54
|
-
Lint/StructNewOverride:
|
55
|
-
Enabled: true
|
56
|
-
Style/AccessorGrouping:
|
57
|
-
Enabled: true
|
58
|
-
Style/BisectedAttrAccessor:
|
59
|
-
Enabled: true
|
60
|
-
Style/ExponentialNotation:
|
61
|
-
Enabled: true
|
62
|
-
Style/HashEachMethods:
|
63
|
-
Enabled: true
|
64
|
-
Style/HashTransformKeys:
|
65
|
-
Enabled: true
|
66
|
-
Style/HashTransformValues:
|
67
|
-
Enabled: true
|
68
|
-
Style/RedundantAssignment:
|
69
|
-
Enabled: true
|
70
|
-
Style/RedundantFetchBlock:
|
71
|
-
Enabled: true
|
72
|
-
Style/RedundantRegexpCharacterClass:
|
73
|
-
Enabled: true
|
74
|
-
Style/RedundantRegexpEscape:
|
75
|
-
Enabled: true
|
76
|
-
Style/SlicingWithRange:
|
77
|
-
Enabled: true
|
43
|
+
Lint/MissingSuper:
|
44
|
+
Enabled: false
|
45
|
+
Style/StringConcatenation:
|
46
|
+
Enabled: false
|
47
|
+
Style/SoleNestedConditional:
|
48
|
+
Enabled: false
|
49
|
+
Lint/DuplicateBranch:
|
50
|
+
Enabled: false
|
51
|
+
Style/OptionalBooleanParameter:
|
52
|
+
Enabled: false
|
data/Appraisals
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
appraise 'activerecord-5.0' do
|
4
|
-
gem 'activerecord', '~> 5.0.1'
|
5
|
-
gem 'pg', '< 1.0.0'
|
6
|
-
end
|
7
|
-
|
8
3
|
appraise 'activerecord-5.1' do
|
9
4
|
gem 'activerecord', '~> 5.1.0'
|
10
5
|
end
|
@@ -17,3 +12,7 @@ end
|
|
17
12
|
appraise 'activerecord-6.0' do
|
18
13
|
gem 'activerecord', '~> 6.0.0'
|
19
14
|
end
|
15
|
+
|
16
|
+
appraise 'activerecord-6.1' do
|
17
|
+
gem 'activerecord', '~> 6.1.0'
|
18
|
+
end
|
data/README.md
CHANGED
@@ -6,8 +6,8 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
6
6
|
(like Chef/Puppet)
|
7
7
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
|
9
|
-
[![Build Status](https://
|
10
|
-
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.
|
9
|
+
[![Build Status](https://github.com/winebarrel/ridgepole/workflows/test/badge.svg?branch=0.9)](https://github.com/winebarrel/ridgepole/actions)
|
10
|
+
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.9)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.8)
|
11
11
|
|
12
12
|
<details><summary>ChangeLog</summary>
|
13
13
|
|
@@ -117,8 +117,32 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
117
117
|
* Support `require_relative` ([pull#298](https://github.com/winebarrel/ridgepole/pull/298))
|
118
118
|
* `>= 0.8.8`
|
119
119
|
* Fix keyword arguments warnings in Ruby 2.7 ([pull#303](https://github.com/winebarrel/ridgepole/pull/303))
|
120
|
+
* `>= 0.8.9`
|
121
|
+
* Fix unexpected differences on text types and blob types on Rails 6 ([pull#306](https://github.com/winebarrel/ridgepole/pull/306))
|
122
|
+
* Fix unexpected warning when a foreign key is added on the primary key ([pull#307](https://github.com/winebarrel/ridgepole/pull/307))
|
123
|
+
* `>= 0.8.10`
|
124
|
+
* Raise an error if an InnoDB column has a foreign key but no index ([pull#310](https://github.com/winebarrel/ridgepole/pull/310))
|
125
|
+
* `>= 0.8.11`
|
126
|
+
* Fix FK index check support multiple PK ([pull#315](https://github.com/winebarrel/ridgepole/pull/315))
|
127
|
+
* Support t.reference() foreign_key option ([pull#316](https://github.com/winebarrel/ridgepole/pull/316))
|
128
|
+
* `>= 0.8.12`
|
129
|
+
* Pluralize column specified by `references` ([pull#317](https://github.com/winebarrel/ridgepole/pull/317))
|
130
|
+
* `>= 0.9.0`
|
131
|
+
* Remove `--mysql-alter-index` option ([pull#330](https://github.com/winebarrel/ridgepole/pull/330))
|
132
|
+
* Add `--table-hash-options` option ([pull#331](https://github.com/winebarrel/ridgepole/pull/331))
|
133
|
+
* Support Rails 6.1 ([pull#323](https://github.com/winebarrel/ridgepole/pull/323))
|
134
|
+
* Disable Rails 5.0 support([pull#335](https://github.com/winebarrel/ridgepole/pull/335))
|
135
|
+
* Fix PK AUTO_INCREMENT change bug([pull#334](https://github.com/winebarrel/ridgepole/pull/334))
|
120
136
|
</details>
|
121
137
|
|
138
|
+
**Notice**
|
139
|
+
|
140
|
+
ActiveRecord 6.1 is supported in ridgepole v0.9, but the ActiveRecord dump has been changed, so there is a difference between ActiveRecord 5.x/6.0 format.
|
141
|
+
|
142
|
+
**If you use ActiveRecord 6.1, please modify Schemafile format**.
|
143
|
+
|
144
|
+
cf. https://github.com/winebarrel/ridgepole/pull/323
|
145
|
+
|
122
146
|
## Installation
|
123
147
|
|
124
148
|
Add this line to your application's Gemfile:
|
@@ -164,6 +188,7 @@ Usage: ridgepole [options]
|
|
164
188
|
-f, --file SCHEMAFILE
|
165
189
|
--dry-run
|
166
190
|
--table-options OPTIONS
|
191
|
+
--table-hash-options OPTIONS
|
167
192
|
--alter-extra ALTER_SPEC
|
168
193
|
--external-script SCRIPT
|
169
194
|
--bulk-change
|
@@ -184,7 +209,6 @@ Usage: ridgepole [options]
|
|
184
209
|
-o, --output SCHEMAFILE
|
185
210
|
-t, --tables TABLES
|
186
211
|
--ignore-tables REGEX_LIST
|
187
|
-
--mysql-use-alter
|
188
212
|
--dump-without-table-options
|
189
213
|
--dump-with-default-fk-name
|
190
214
|
--index-removed-drop-column
|
@@ -394,20 +418,6 @@ Apply `Schemafile`
|
|
394
418
|
-> 0.0471s
|
395
419
|
```
|
396
420
|
|
397
|
-
## Use ALTER instead of CREATE/DROP INDEX
|
398
|
-
|
399
|
-
```sh
|
400
|
-
$ ridgepole -a -c database.yml --mysql-use-alter --debug
|
401
|
-
Apply `Schemafile`
|
402
|
-
...
|
403
|
-
-- remove_index("dept_manager", {:name=>"emp_no"})
|
404
|
-
(19.2ms) ALTER TABLE `dept_manager` DROP INDEX `emp_no`
|
405
|
-
-> 0.0200s
|
406
|
-
-- add_index("dept_manager", ["emp_no"], {:name=>"emp_no2", :using=>:btree})
|
407
|
-
(23.4ms) ALTER TABLE `dept_manager` ADD INDEX `emp_no2` USING btree (`emp_no`)
|
408
|
-
-> 0.0243s
|
409
|
-
```
|
410
|
-
|
411
421
|
## Relation column type check
|
412
422
|
|
413
423
|
```ruby
|
data/bin/ridgepole
CHANGED
@@ -86,6 +86,19 @@ ARGV.options do |opt|
|
|
86
86
|
opt.on('-f', '--file SCHEMAFILE') { |v| file = v }
|
87
87
|
opt.on('', '--dry-run') { options[:dry_run] = true }
|
88
88
|
opt.on('', '--table-options OPTIONS') { |v| options[:table_options] = v }
|
89
|
+
opt.on('', '--table-hash-options OPTIONS') do |v|
|
90
|
+
# NOTE: Ruby2.4 doesn't support `symbolize_names: true`
|
91
|
+
hash = YAML.safe_load(v).deep_symbolize_keys
|
92
|
+
|
93
|
+
case hash[:id]
|
94
|
+
when String
|
95
|
+
hash[:id] = hash[:id].to_sym
|
96
|
+
when Hash
|
97
|
+
hash[:id][:type] = hash[:id][:type].to_sym if hash[:id][:type]
|
98
|
+
end
|
99
|
+
|
100
|
+
options[:table_hash_options] = hash
|
101
|
+
end
|
89
102
|
opt.on('', '--alter-extra ALTER_SPEC') { |v| options[:alter_extra] = v }
|
90
103
|
opt.on('', '--external-script SCRIPT') { |v| options[:external_script] = v }
|
91
104
|
opt.on('', '--bulk-change') do
|
@@ -121,7 +134,6 @@ ARGV.options do |opt|
|
|
121
134
|
opt.on('-o', '--output SCHEMAFILE') { |v| output_file = v }
|
122
135
|
opt.on('-t', '--tables TABLES', Array) { |v| options[:tables] = v }
|
123
136
|
opt.on('', '--ignore-tables REGEX_LIST', Array) { |v| options[:ignore_tables] = v.map { |i| Regexp.new(i) } }
|
124
|
-
opt.on('', '--mysql-use-alter') { options[:mysql_use_alter] = true }
|
125
137
|
opt.on('', '--dump-without-table-options') { options[:dump_without_table_options] = true }
|
126
138
|
opt.on('', '--dump-with-default-fk-name') { options[:dump_with_default_fk_name] = true }
|
127
139
|
opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
|
data/lib/ridgepole/client.rb
CHANGED
@@ -15,8 +15,6 @@ module Ridgepole
|
|
15
15
|
@parser = Ridgepole::DSLParser.new(@options)
|
16
16
|
@diff = Ridgepole::Diff.new(@options)
|
17
17
|
|
18
|
-
require 'ridgepole/ext/abstract_mysql_adapter/use_alter_index' if @options[:mysql_use_alter]
|
19
|
-
|
20
18
|
require 'ridgepole/ext/abstract_mysql_adapter/dump_auto_increment' if @options[:mysql_dump_auto_increment]
|
21
19
|
end
|
22
20
|
|
@@ -32,7 +30,7 @@ module Ridgepole
|
|
32
30
|
logger.verbose_info('# Parse DSL')
|
33
31
|
expected_definition, expected_execute = @parser.parse(dsl, opts)
|
34
32
|
expected_definition.each do |_table, definition|
|
35
|
-
definition
|
33
|
+
merge_table_options(definition)
|
36
34
|
end
|
37
35
|
logger.verbose_info('# Load tables')
|
38
36
|
current_definition, _current_execute = @parser.parse(@dumper.dump, opts)
|
@@ -40,6 +38,13 @@ module Ridgepole
|
|
40
38
|
@diff.diff(current_definition, expected_definition, execute: expected_execute)
|
41
39
|
end
|
42
40
|
|
41
|
+
private
|
42
|
+
|
43
|
+
def merge_table_options(definition)
|
44
|
+
definition[:options].reverse_merge!(@options[:table_hash_options]) if @options[:table_hash_options]
|
45
|
+
definition[:options][:options] ||= @options[:table_options] if @options[:table_options]
|
46
|
+
end
|
47
|
+
|
43
48
|
class << self
|
44
49
|
def diff(dsl_or_config1, dsl_or_config2, options = {})
|
45
50
|
logger = Ridgepole::Logger.instance
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -292,6 +292,19 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
292
292
|
buf.puts
|
293
293
|
end
|
294
294
|
|
295
|
+
def append_change_table_raw_options(table_name, raw_table_options, table_charset, table_collation, buf)
|
296
|
+
if raw_table_options.blank? && ActiveRecord.gem_version >= Gem::Version.new('6.1.0')
|
297
|
+
# Implicit engine is InnoDB in 6.1.0
|
298
|
+
# related: https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R441
|
299
|
+
raw_table_options = +'ENGINE=InnoDB'
|
300
|
+
end
|
301
|
+
|
302
|
+
raw_table_options << " DEFAULT CHARSET=#{table_charset}" if table_charset
|
303
|
+
raw_table_options << " COLLATE=#{table_collation}" if table_collation
|
304
|
+
|
305
|
+
append_change_table_options(table_name, raw_table_options, buf)
|
306
|
+
end
|
307
|
+
|
295
308
|
def append_change_table_comment(table_name, table_comment, buf)
|
296
309
|
comment_literal = "COMMENT=#{ActiveRecord::Base.connection.quote(table_comment)}"
|
297
310
|
append_change_table_options(table_name, comment_literal, buf)
|
@@ -303,6 +316,8 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
303
316
|
indices = attrs[:indices] || {}
|
304
317
|
foreign_keys = attrs[:foreign_keys] || {}
|
305
318
|
table_options = attrs[:table_options]
|
319
|
+
table_charset = attrs[:table_charset]
|
320
|
+
table_collation = attrs[:table_collation]
|
306
321
|
table_comment = attrs[:table_comment]
|
307
322
|
|
308
323
|
if !definition.empty? || !indices.empty? || !primary_key_definition.empty?
|
@@ -316,7 +331,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
316
331
|
|
317
332
|
append_change_foreign_keys(table_name, foreign_keys, pre_buf_for_fk, post_buf_for_fk, @options) unless foreign_keys.empty?
|
318
333
|
|
319
|
-
|
334
|
+
append_change_table_raw_options(table_name, table_options, table_charset, table_collation, buf) if table_options || table_charset || table_collation
|
320
335
|
|
321
336
|
append_change_table_comment(table_name, table_comment, buf) if table_comment
|
322
337
|
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -114,23 +114,33 @@ module Ridgepole
|
|
114
114
|
|
115
115
|
normalize_default_proc_options!(from, to)
|
116
116
|
|
117
|
-
from_options = from[:options] || {}
|
118
|
-
to_options = to[:options] || {}
|
119
|
-
|
120
117
|
if @options[:ignore_table_comment]
|
121
118
|
from.delete(:comment)
|
122
119
|
to.delete(:comment)
|
123
120
|
end
|
124
121
|
|
125
|
-
[from, to].each do |table_attrs|
|
126
|
-
table_attrs.delete(:default) if table_attrs.key?(:default) && table_attrs[:default].nil?
|
127
|
-
end
|
128
|
-
|
129
122
|
if Ridgepole::ConnectionAdapters.mysql?
|
130
|
-
if @options[:mysql_change_table_options]
|
131
|
-
from
|
132
|
-
to
|
133
|
-
|
123
|
+
if @options[:mysql_change_table_options]
|
124
|
+
from_options = from[:options] || {}
|
125
|
+
to_options = to[:options] || {}
|
126
|
+
|
127
|
+
if from_options != to_options
|
128
|
+
table_delta[:table_options] = to_options
|
129
|
+
from.delete(:options)
|
130
|
+
to.delete(:options)
|
131
|
+
end
|
132
|
+
|
133
|
+
if from[:charset] != to[:charset]
|
134
|
+
table_delta[:table_charset] = to[:charset]
|
135
|
+
from.delete(:charset)
|
136
|
+
to.delete(:charset)
|
137
|
+
end
|
138
|
+
|
139
|
+
if from[:collation] != to[:collation]
|
140
|
+
table_delta[:table_collation] = to[:collation]
|
141
|
+
from.delete(:collation)
|
142
|
+
to.delete(:collation)
|
143
|
+
end
|
134
144
|
end
|
135
145
|
|
136
146
|
if @options[:mysql_change_table_comment] && (from[:comment] != to[:comment])
|
@@ -142,7 +152,11 @@ module Ridgepole
|
|
142
152
|
|
143
153
|
if @options[:dump_without_table_options]
|
144
154
|
from.delete(:options)
|
155
|
+
from.delete(:charset)
|
156
|
+
from.delete(:collation)
|
145
157
|
to.delete(:options)
|
158
|
+
to.delete(:charset)
|
159
|
+
to.delete(:collation)
|
146
160
|
end
|
147
161
|
|
148
162
|
pk_attrs = build_primary_key_attrs_if_changed(from, to, table_name)
|
@@ -177,13 +191,16 @@ module Ridgepole
|
|
177
191
|
end
|
178
192
|
|
179
193
|
def convert_to_primary_key_attrs(column_options)
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
194
|
+
type = Ridgepole::DSLParser::TableDefinition::DEFAULT_PRIMARY_KEY_TYPE
|
195
|
+
options = column_options.deep_dup
|
196
|
+
|
197
|
+
if options[:id].is_a?(Hash)
|
198
|
+
options_id = options.delete(:id)
|
199
|
+
type = options_id.delete(:type) if options_id[:type]
|
200
|
+
options.merge!(options_id.slice(*PRIMARY_KEY_OPTIONS))
|
201
|
+
elsif options[:id]
|
202
|
+
type = options.delete(:id)
|
203
|
+
end
|
187
204
|
|
188
205
|
options[:auto_increment] = true if %i[integer bigint].include?(type) && !options.key?(:default) && !Ridgepole::ConnectionAdapters.postgresql?
|
189
206
|
|
@@ -386,6 +403,18 @@ module Ridgepole
|
|
386
403
|
attrs[:type] = :bigint
|
387
404
|
opts.delete(:limit)
|
388
405
|
end
|
406
|
+
|
407
|
+
if opts[:size] && (attrs[:type] == :text || attrs[:type] == :blob || attrs[:type] == :binary)
|
408
|
+
case opts.delete(:size)
|
409
|
+
when :tiny
|
410
|
+
attrs[:type] = :blob if attrs[:type] == :binary
|
411
|
+
opts[:limit] = 255
|
412
|
+
when :medium
|
413
|
+
opts[:limit] = 16_777_215
|
414
|
+
when :long
|
415
|
+
opts[:limit] = 4_294_967_295
|
416
|
+
end
|
417
|
+
end
|
389
418
|
end
|
390
419
|
end
|
391
420
|
|
@@ -539,9 +568,15 @@ module Ridgepole
|
|
539
568
|
table_options = parent_table_info.fetch(:options)
|
540
569
|
next if table_options[:id] == false
|
541
570
|
|
571
|
+
options_id = table_options[:id]
|
572
|
+
parent_type, parent_unsigned = if options_id.is_a?(Hash)
|
573
|
+
[options_id[:type], options_id[:unsigned]]
|
574
|
+
else
|
575
|
+
[table_options[:id], table_options[:unsigned]]
|
576
|
+
end
|
542
577
|
parent_column_info = {
|
543
|
-
type:
|
544
|
-
unsigned:
|
578
|
+
type: parent_type || @options[:check_relation_type].to_sym,
|
579
|
+
unsigned: parent_unsigned,
|
545
580
|
}
|
546
581
|
|
547
582
|
child_column_info = {
|