ridgepole 0.6.0.beta2 → 0.6.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +2 -0
- data/bin/ridgepole +16 -16
- data/lib/ridgepole/client.rb +6 -9
- data/lib/ridgepole/default_limit.rb +26 -0
- data/lib/ridgepole/delta.rb +2 -8
- data/lib/ridgepole/diff.rb +14 -10
- data/lib/ridgepole/version.rb +1 -1
- data/lib/ridgepole.rb +2 -10
- data/ridgepole.gemspec +1 -0
- data/spec/{bigint_pk → mysql/bigint_pk}/bigint_pkspec.rb +0 -0
- data/spec/{cli → mysql/cli}/config_spec.rb +3 -1
- data/spec/{cli → mysql/cli}/ridgepole_spec.rb +3 -0
- data/spec/{collation → mysql/collation}/collation_spec.rb +2 -0
- data/spec/{diff → mysql/diff}/diff2_spec.rb +2 -0
- data/spec/{diff → mysql/diff}/diff_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_class_method_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_some_tables_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_without_table_options_spec.rb +2 -0
- data/spec/{migrate_0 → mysql/fk}/migrate_change_fk_spec.rb +5 -3
- data/spec/{migrate_0 → mysql/fk}/migrate_create_fk_spec.rb +7 -5
- data/spec/{migrate_0 → mysql/fk}/migrate_drop_fk_spec.rb +6 -4
- data/spec/{migrate → mysql/migrate}/check_orphan_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_add_column2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_add_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column3_spec.rb +2 -0
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +83 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column_float_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index3_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index4_spec.rb +2 -0
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +78 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_table_option_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_create_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_create_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_create_table_with_options_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_column_and_index_2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_column_and_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_duplicate_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_duplicate_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_empty_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_execute_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_merge_mode_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_noop_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_rename_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_rename_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_same_default_null_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_same_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_script_error_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_skip_rename_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_skip_rename_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_with_ignore_tables_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_with_pre_post_query_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_with_tables_spec.rb +2 -0
- data/spec/{ridgepole_test_database.sql → mysql/ridgepole_test_database.sql} +0 -0
- data/spec/{ridgepole_test_tables.sql → mysql/ridgepole_test_tables.sql} +0 -0
- data/spec/postgresql/diff/diff_spec.rb +153 -0
- data/spec/postgresql/dump/dump_spec.rb +76 -0
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +62 -0
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +173 -0
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +114 -0
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +220 -0
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +203 -0
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +193 -0
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +103 -0
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +185 -0
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +180 -0
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +125 -0
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +116 -0
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +179 -0
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +199 -0
- data/spec/postgresql/migrate/migrate_same_spec.rb +84 -0
- data/spec/postgresql/ridgepole_test_database.sql +15 -0
- data/spec/postgresql/ridgepole_test_tables.sql +74 -0
- data/spec/spec_helper.rb +63 -7
- metadata +159 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3f7ab0526aeeb91e3a59961689faac1fe121581
|
4
|
+
data.tar.gz: 17600a9bd516754b1a07a71884a485130fdd2fa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe473047299f94e4dfec5666fa178ce69c9582b7eb9e18e40efae6369d284e4471c935889d7f9c833fc1c50dfb84e001cce78a34fde16bbe63c3a76ac85ec9f
|
7
|
+
data.tar.gz: 6601bd9271465052f305a0e4321ecb0cf90a870f267412f651341f082ab05011a836aa050ec18e21f1c00641ddbdd5bef695b58b203afdf9f02c49534b8ea9e0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
34
34
|
* migration_comments
|
35
35
|
* foreigner
|
36
36
|
* Disable sqlite support
|
37
|
+
* Add PostgreSQL test
|
37
38
|
|
38
39
|
## Installation
|
39
40
|
|
@@ -79,6 +80,7 @@ Usage: ridgepole [options]
|
|
79
80
|
--enable-mysql-awesome
|
80
81
|
--mysql-awesome-unsigned-pk
|
81
82
|
--dump-without-table-options
|
83
|
+
--index-removed-drop-column
|
82
84
|
-r, --require LIBS
|
83
85
|
--log-file LOG_FILE
|
84
86
|
--verbose
|
data/bin/ridgepole
CHANGED
@@ -66,22 +66,21 @@ ARGV.options do |opt|
|
|
66
66
|
raise "Cannot use `bulk-change` in `merge`" if options[:merge]
|
67
67
|
options[:bulk_change] = true
|
68
68
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
69
|
+
opt.on('', "--default-bool-limit LIMIT", Integer) {|v|
|
70
|
+
options[:default_boolean_limit] = v
|
71
|
+
}
|
72
|
+
opt.on('', "--default-int-limit LIMIT", Integer) {|v|
|
73
|
+
options[:"default_integer_limit"] = v
|
74
|
+
}
|
75
|
+
opt.on('', "--default-float-limit LIMIT", Integer) {|v|
|
76
|
+
options[:"default_float_limit"] = v
|
77
|
+
}
|
78
|
+
opt.on('', "--default-string-limit LIMIT", Integer) {|v|
|
79
|
+
options[:"default_string_limit"] = v
|
80
|
+
}
|
81
|
+
opt.on('', "--default-text-limit LIMIT", Integer) {|v|
|
82
|
+
options[:"default_text_limit"] = v
|
83
|
+
}
|
85
84
|
opt.on('', '--pre-query QUERY') {|v| options[:pre_query] = v }
|
86
85
|
opt.on('', '--post-query QUERY') {|v| options[:post_query] = v }
|
87
86
|
opt.on('-e', '--export') { set_mode[:export] }
|
@@ -107,6 +106,7 @@ ARGV.options do |opt|
|
|
107
106
|
opt.on('', '--enable-mysql-awesome') { options[:enable_mysql_awesome] = true }
|
108
107
|
opt.on('', '--mysql-awesome-unsigned-pk') { options[:mysql_awesome_unsigned_pk] = true }
|
109
108
|
opt.on('', '--dump-without-table-options') { options[:dump_without_table_options] = true }
|
109
|
+
opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
|
110
110
|
opt.on('-r' , '--require LIBS', Array) {|v| v.each {|i| require i } }
|
111
111
|
opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
|
112
112
|
opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
|
data/lib/ridgepole/client.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
class Ridgepole::Client
|
2
2
|
def initialize(conn_spec, options = {})
|
3
|
-
Ridgepole::Client.normalize_options(options)
|
4
3
|
@options = options
|
5
4
|
|
6
5
|
ActiveRecord::Base.establish_connection(conn_spec)
|
6
|
+
|
7
|
+
# XXX: If the required processing in class method?
|
8
|
+
if not @options.has_key?(:index_removed_drop_column) and Ridgepole::DefaultsLimit.adapter == :postgresql
|
9
|
+
@options[:index_removed_drop_column] = true
|
10
|
+
end
|
11
|
+
|
7
12
|
Ridgepole::ExecuteExpander.expand_execute(ActiveRecord::Base.connection)
|
8
13
|
@dumper = Ridgepole::Dumper.new(@options)
|
9
14
|
@parser = Ridgepole::DSLParser.new(@options)
|
@@ -37,7 +42,6 @@ class Ridgepole::Client
|
|
37
42
|
|
38
43
|
class << self
|
39
44
|
def diff(dsl_or_config1, dsl_or_config2, options = {})
|
40
|
-
normalize_options(options)
|
41
45
|
logger = Ridgepole::Logger.instance
|
42
46
|
|
43
47
|
logger.verbose_info('# Parse DSL1')
|
@@ -51,17 +55,10 @@ class Ridgepole::Client
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def dump(conn_spec, options = {}, &block)
|
54
|
-
normalize_options(options)
|
55
58
|
client = self.new(conn_spec, options)
|
56
59
|
client.dump(&block)
|
57
60
|
end
|
58
61
|
|
59
|
-
def normalize_options(options)
|
60
|
-
Ridgepole::DEFAULTS_LIMITS.each do |column_type, limit|
|
61
|
-
options[:"default_#{column_type}_limit"] ||= limit
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
62
|
private
|
66
63
|
|
67
64
|
def load_definition(dsl_or_config, options = {})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Ridgepole::DefaultsLimit
|
2
|
+
DEFAULTS_LIMITS = {
|
3
|
+
:mysql2 => {
|
4
|
+
:boolean => 1,
|
5
|
+
:integer => 4,
|
6
|
+
:float => 24,
|
7
|
+
:string => 255,
|
8
|
+
:text => 65535,
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def default_limit(column_type, options)
|
14
|
+
defaults = DEFAULTS_LIMITS[adapter] || {}
|
15
|
+
option_key = :"default_#{column_type}_limit"
|
16
|
+
default_limit = options[option_key] || defaults[column_type] || 0
|
17
|
+
default_limit.zero? ? nil : default_limit
|
18
|
+
end
|
19
|
+
|
20
|
+
def adapter
|
21
|
+
ActiveRecord::Base.connection_config.fetch(:adapter).to_sym
|
22
|
+
rescue ActiveRecord::ConnectionNotEstablished
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end # of class methods
|
26
|
+
end
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -421,13 +421,7 @@ remove_foreign_key(#{table_name.inspect}, #{target.inspect})
|
|
421
421
|
end
|
422
422
|
|
423
423
|
def normalize_limit(column_type, column_options)
|
424
|
-
Ridgepole::
|
425
|
-
|
426
|
-
next if default_limit <= 0
|
427
|
-
|
428
|
-
if column_type == default_column_type
|
429
|
-
column_options[:limit] ||= default_limit
|
430
|
-
end
|
431
|
-
end
|
424
|
+
default_limit = Ridgepole::DefaultsLimit.default_limit(column_type, @options)
|
425
|
+
column_options[:limit] ||= default_limit if default_limit
|
432
426
|
end
|
433
427
|
end
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -134,8 +134,19 @@ class Ridgepole::Diff
|
|
134
134
|
definition_delta[:delete][column_name] = from_attrs
|
135
135
|
|
136
136
|
if from_indices
|
137
|
+
modified_indices = []
|
138
|
+
|
137
139
|
from_indices.each do |name, attrs|
|
138
|
-
attrs[:column_name].delete(column_name)
|
140
|
+
if attrs[:column_name].delete(column_name)
|
141
|
+
modified_indices << name
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# In PostgreSQL, the index is deleted when the column is deleted
|
146
|
+
if @options[:index_removed_drop_column]
|
147
|
+
from_indices.reject! do |name, attrs|
|
148
|
+
modified_indices.include?(name)
|
149
|
+
end
|
139
150
|
end
|
140
151
|
|
141
152
|
from_indices.reject! do |name, attrs|
|
@@ -239,15 +250,8 @@ class Ridgepole::Diff
|
|
239
250
|
def normalize_column_options!(attrs)
|
240
251
|
opts = attrs[:options]
|
241
252
|
opts[:null] = true unless opts.has_key?(:null)
|
242
|
-
|
243
|
-
|
244
|
-
default_limit = @options[:"default_#{column_type}_limit"]
|
245
|
-
next if default_limit <= 0
|
246
|
-
|
247
|
-
if attrs[:type] == column_type and opts[:limit] == default_limit
|
248
|
-
opts.delete(:limit)
|
249
|
-
end
|
250
|
-
end
|
253
|
+
default_limit = Ridgepole::DefaultsLimit.default_limit(attrs[:type], @options)
|
254
|
+
opts.delete(:limit) if opts[:limit] == default_limit
|
251
255
|
|
252
256
|
# XXX: MySQL only?
|
253
257
|
if not opts.has_key?(:default) and opts[:null]
|
data/lib/ridgepole/version.rb
CHANGED
data/lib/ridgepole.rb
CHANGED
@@ -6,18 +6,10 @@ require 'active_record'
|
|
6
6
|
require 'active_support'
|
7
7
|
require 'active_support/core_ext'
|
8
8
|
|
9
|
-
module Ridgepole
|
10
|
-
# for MySQL
|
11
|
-
DEFAULTS_LIMITS = {
|
12
|
-
:boolean => 1,
|
13
|
-
:integer => 4,
|
14
|
-
:float => 24,
|
15
|
-
:string => 255,
|
16
|
-
:text => 65535,
|
17
|
-
}
|
18
|
-
end
|
9
|
+
module Ridgepole; end
|
19
10
|
|
20
11
|
require 'ridgepole/client'
|
12
|
+
require 'ridgepole/default_limit'
|
21
13
|
require 'ridgepole/delta'
|
22
14
|
require 'ridgepole/diff'
|
23
15
|
require 'ridgepole/dsl_parser'
|
data/ridgepole.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
25
25
|
spec.add_development_dependency 'mysql2'
|
26
|
+
spec.add_development_dependency 'pg'
|
26
27
|
spec.add_development_dependency 'coveralls'
|
27
28
|
spec.add_development_dependency 'activerecord-mysql-awesome', '>= 0.0.7'
|
28
29
|
end
|
File without changes
|
@@ -1,3 +1,4 @@
|
|
1
|
+
unless postgresql?
|
1
2
|
describe Ridgepole::Config do
|
2
3
|
subject { Ridgepole::Config.load(config, env) }
|
3
4
|
|
@@ -81,7 +82,8 @@ describe Ridgepole::Config do
|
|
81
82
|
it {
|
82
83
|
expect {
|
83
84
|
subject
|
84
|
-
}.to raise_error
|
85
|
+
}.to raise_error Errno::ENOENT
|
85
86
|
}
|
86
87
|
end
|
87
88
|
end
|
89
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
unless postgresql?
|
1
2
|
describe 'ridgepole' do
|
2
3
|
let(:differ) { false }
|
3
4
|
let(:conf) { "'" + JSON.dump(conn_spec) + "'" }
|
@@ -36,6 +37,7 @@ describe 'ridgepole' do
|
|
36
37
|
--enable-mysql-awesome
|
37
38
|
--mysql-awesome-unsigned-pk
|
38
39
|
--dump-without-table-options
|
40
|
+
--index-removed-drop-column
|
39
41
|
-r, --require LIBS
|
40
42
|
--log-file LOG_FILE
|
41
43
|
--verbose
|
@@ -390,3 +392,4 @@ describe 'ridgepole' do
|
|
390
392
|
end
|
391
393
|
end
|
392
394
|
end
|
395
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
unless postgresql?
|
1
2
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
3
|
context 'when change fk' do
|
3
4
|
let(:actual_dsl) {
|
@@ -9,7 +10,7 @@ create_table "child", force: :cascade do |t|
|
|
9
10
|
t.integer "parent_id"#{unsigned_if_enabled}
|
10
11
|
end
|
11
12
|
|
12
|
-
add_index "child", ["parent_id"], name: "
|
13
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
13
14
|
|
14
15
|
add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
|
15
16
|
RUBY
|
@@ -21,7 +22,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
21
22
|
t.integer "parent_id", limit: 4#{unsigned_if_enabled}
|
22
23
|
end
|
23
24
|
|
24
|
-
add_index "child", ["parent_id"], name: "
|
25
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
25
26
|
|
26
27
|
create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
|
27
28
|
end
|
@@ -36,7 +37,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
36
37
|
t.integer "parent_id", limit: 4#{unsigned_if_enabled}
|
37
38
|
end
|
38
39
|
|
39
|
-
add_index "child", ["parent_id"], name: "
|
40
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
40
41
|
|
41
42
|
create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
|
42
43
|
end
|
@@ -58,3 +59,4 @@ add_foreign_key "child", "parent", name: "child_ibfk_1"
|
|
58
59
|
}
|
59
60
|
end
|
60
61
|
end
|
62
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
unless postgresql?
|
1
2
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
3
|
context 'when create fk' do
|
3
4
|
let(:actual_dsl) {
|
@@ -6,7 +7,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
6
7
|
t.integer "parent_id", limit: 4#{unsigned_if_enabled}
|
7
8
|
end
|
8
9
|
|
9
|
-
add_index "child", ["parent_id"], name: "
|
10
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
10
11
|
|
11
12
|
create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
|
12
13
|
end
|
@@ -62,7 +63,7 @@ create_table "child", force: :cascade do |t|
|
|
62
63
|
t.integer "parent_id", unsigned: true
|
63
64
|
end
|
64
65
|
|
65
|
-
add_index "child", ["parent_id"], name: "
|
66
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
66
67
|
|
67
68
|
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
68
69
|
RUBY
|
@@ -75,7 +76,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
75
76
|
t.integer "parent_id", limit: 4#{unsigned_if_enabled}
|
76
77
|
end
|
77
78
|
|
78
|
-
add_index "child", ["parent_id"], name: "
|
79
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
79
80
|
|
80
81
|
create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
|
81
82
|
end
|
@@ -106,7 +107,7 @@ create_table "child", force: :cascade do |t|
|
|
106
107
|
t.integer "parent_id", unsigned: true
|
107
108
|
end
|
108
109
|
|
109
|
-
add_index "child", ["parent_id"], name: "
|
110
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
110
111
|
|
111
112
|
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
112
113
|
|
@@ -134,7 +135,7 @@ create_table "child", force: :cascade do |t|
|
|
134
135
|
t.integer "parent_id", unsigned: true
|
135
136
|
end
|
136
137
|
|
137
|
-
add_index "child", ["parent_id"], name: "
|
138
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
138
139
|
|
139
140
|
add_foreign_key "child", "parent"
|
140
141
|
RUBY
|
@@ -169,3 +170,4 @@ add_foreign_key "child", "parent", name: "child_ibfk_1"
|
|
169
170
|
}
|
170
171
|
end
|
171
172
|
end
|
173
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
unless postgresql?
|
1
2
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
3
|
context 'when drop fk' do
|
3
4
|
let(:actual_dsl) {
|
@@ -9,7 +10,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
9
10
|
t.integer "parent_id"#{unsigned_if_enabled}
|
10
11
|
end
|
11
12
|
|
12
|
-
add_index "child", ["parent_id"], name: "
|
13
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
13
14
|
|
14
15
|
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
15
16
|
RUBY
|
@@ -28,7 +29,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
28
29
|
t.integer "parent_id", limit: 4#{unsigned_if_enabled}
|
29
30
|
end
|
30
31
|
|
31
|
-
add_index "child", ["parent_id"], name: "
|
32
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
32
33
|
|
33
34
|
create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
|
34
35
|
end
|
@@ -77,7 +78,7 @@ create_table "child", force: :cascade do |t|
|
|
77
78
|
t.integer "parent_id", unsigned: true
|
78
79
|
end
|
79
80
|
|
80
|
-
add_index "child", ["parent_id"], name: "
|
81
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
81
82
|
|
82
83
|
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
83
84
|
RUBY
|
@@ -89,7 +90,7 @@ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
|
|
89
90
|
t.integer "parent_id", limit: 4#{unsigned_if_enabled}
|
90
91
|
end
|
91
92
|
|
92
|
-
add_index "child", ["parent_id"], name: "
|
93
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
93
94
|
|
94
95
|
create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
|
95
96
|
end
|
@@ -110,3 +111,4 @@ add_foreign_key "child", "parent", name: "child_ibfk_1"
|
|
110
111
|
}
|
111
112
|
end
|
112
113
|
end
|
114
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
unless postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when change column (boolean without limit)' do
|
4
|
+
let(:actual_dsl) {
|
5
|
+
<<-RUBY
|
6
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
7
|
+
t.date "birth_date", null: false
|
8
|
+
t.string "first_name", limit: 14, null: false
|
9
|
+
t.string "last_name", limit: 16, null: false
|
10
|
+
t.string "gender", limit: 1, null: false
|
11
|
+
t.date "hire_date", null: false
|
12
|
+
t.datetime "created_at", null: false
|
13
|
+
t.datetime "updated_at", null: false
|
14
|
+
t.boolean "registered"
|
15
|
+
end
|
16
|
+
RUBY
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:expected_dsl) {
|
20
|
+
<<-RUBY
|
21
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
22
|
+
t.date "birth_date", null: false
|
23
|
+
t.string "first_name", limit: 14, null: false
|
24
|
+
t.string "last_name", limit: 16, null: false
|
25
|
+
t.string "gender", limit: 1, null: false
|
26
|
+
t.date "hire_date", null: false
|
27
|
+
t.datetime "created_at", null: false
|
28
|
+
t.datetime "updated_at", null: false
|
29
|
+
t.boolean "registered"
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
}
|
33
|
+
|
34
|
+
before { subject.diff(actual_dsl).migrate }
|
35
|
+
subject { client }
|
36
|
+
|
37
|
+
it {
|
38
|
+
delta = subject.diff(expected_dsl)
|
39
|
+
expect(delta.differ?).to be_falsey
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when change column (boolean with limit)' do
|
44
|
+
let(:actual_dsl) {
|
45
|
+
<<-RUBY
|
46
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
47
|
+
t.date "birth_date", null: false
|
48
|
+
t.string "first_name", limit: 14, null: false
|
49
|
+
t.string "last_name", limit: 16, null: false
|
50
|
+
t.string "gender", limit: 1, null: false
|
51
|
+
t.date "hire_date", null: false
|
52
|
+
t.datetime "created_at", null: false
|
53
|
+
t.datetime "updated_at", null: false
|
54
|
+
t.boolean "registered"
|
55
|
+
end
|
56
|
+
RUBY
|
57
|
+
}
|
58
|
+
|
59
|
+
let(:expected_dsl) {
|
60
|
+
<<-RUBY
|
61
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
62
|
+
t.date "birth_date", null: false
|
63
|
+
t.string "first_name", limit: 14, null: false
|
64
|
+
t.string "last_name", limit: 16, null: false
|
65
|
+
t.string "gender", limit: 1, null: false
|
66
|
+
t.date "hire_date", null: false
|
67
|
+
t.datetime "created_at", null: false
|
68
|
+
t.datetime "updated_at", null: false
|
69
|
+
t.boolean "registered", limit: 1
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
}
|
73
|
+
|
74
|
+
before { subject.diff(actual_dsl).migrate }
|
75
|
+
subject { client }
|
76
|
+
|
77
|
+
it {
|
78
|
+
delta = subject.diff(expected_dsl)
|
79
|
+
expect(delta.differ?).to be_falsey
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|