ridgepole 0.7.0.beta18 → 0.7.0.beta19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/docker-compose.yml +3 -3
- data/lib/ridgepole/client.rb +3 -8
- data/lib/ridgepole/delta.rb +0 -1
- data/lib/ridgepole/dumper.rb +11 -2
- data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +32 -0
- data/lib/ridgepole/ext/schema_dumper.rb +17 -0
- data/lib/ridgepole/version.rb +1 -1
- data/lib/ridgepole.rb +2 -0
- data/spec/mysql/migrate/migrate_change_column8_spec.rb +40 -0
- data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +28 -0
- data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +0 -1
- data/spec/spec_const.rb +2 -2
- metadata +5 -3
- data/lib/ridgepole/ext/abstract_mysql_adapter/disable_table_options.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d69dc66de98a5b2e1b71adc21896d9cfb54a153
|
4
|
+
data.tar.gz: 30cfacc9b97bb51ac60172a06c6ac157469210a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc8cbc9963b3334d7848c07a31c294e35a5ca352a7420cf4f94733179330ba74180c00178a60a43806f6968f40e273b65f5f02338158d47a6af5a17b5aa77c41
|
7
|
+
data.tar.gz: 5bae656215f07994b3da071953e9c7f82e2c95e49ffe3147f5bacbf5159fe9add6c34a8d428bb014b06829daf64ff9d6015bf6287aa2ac08dd171b1609d475cb
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
9
9
|
[![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.6)](https://travis-ci.org/winebarrel/ridgepole)
|
10
10
|
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.6)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.6)
|
11
11
|
|
12
|
-
[![Edge Version](https://img.shields.io/badge/edge_version-0.7.0.
|
12
|
+
[![Edge Version](https://img.shields.io/badge/edge_version-0.7.0.beta19-brightgreen.svg)](https://rubygems.org/gems/ridgepole/versions/0.7.0.beta19)
|
13
13
|
[![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.7)](https://travis-ci.org/winebarrel/ridgepole)
|
14
14
|
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.7)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.7)
|
15
15
|
|
@@ -391,6 +391,7 @@ bundle install
|
|
391
391
|
bundle exec appraisal install
|
392
392
|
bundle exec appraisal activerecord-5.1 rake
|
393
393
|
# POSTGRESQL=1 bundle exec appraisal activerecord-5.1 rake
|
394
|
+
# MYSQL57=1 bundle exec appraisal activerecord-5.1 rake
|
394
395
|
```
|
395
396
|
|
396
397
|
**Notice:** mysql-client/postgresql-client is required.
|
data/docker-compose.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
mysql:
|
2
2
|
image: "mysql:5.6"
|
3
3
|
ports:
|
4
|
-
- "
|
4
|
+
- "13316:3306"
|
5
5
|
environment:
|
6
6
|
MYSQL_ROOT_PASSWORD: password
|
7
7
|
mysql57:
|
8
8
|
image: "mysql:5.7"
|
9
9
|
ports:
|
10
|
-
- "
|
10
|
+
- "13317:3306"
|
11
11
|
environment:
|
12
12
|
MYSQL_ROOT_PASSWORD: password
|
13
13
|
postgres:
|
14
14
|
image: "postgres:9.5"
|
15
15
|
ports:
|
16
|
-
- "
|
16
|
+
- "15442:5432"
|
17
17
|
environment:
|
18
18
|
POSTGRES_PASSWORD: password
|
data/lib/ridgepole/client.rb
CHANGED
@@ -17,14 +17,6 @@ class Ridgepole::Client
|
|
17
17
|
if @options[:mysql_use_alter]
|
18
18
|
require 'ridgepole/ext/abstract_mysql_adapter/use_alter_index'
|
19
19
|
end
|
20
|
-
|
21
|
-
if @options[:dump_with_default_fk_name]
|
22
|
-
require 'ridgepole/ext/schema_dumper'
|
23
|
-
end
|
24
|
-
|
25
|
-
if @options[:dump_without_table_options]
|
26
|
-
require 'ridgepole/ext/abstract_mysql_adapter/disable_table_options'
|
27
|
-
end
|
28
20
|
end
|
29
21
|
|
30
22
|
def dump(&block)
|
@@ -38,6 +30,9 @@ class Ridgepole::Client
|
|
38
30
|
|
39
31
|
logger.verbose_info('# Parse DSL')
|
40
32
|
expected_definition, expected_execute = @parser.parse(dsl, opts)
|
33
|
+
expected_definition.each do |table, definition|
|
34
|
+
definition[:options][:options] ||= @options[:table_options] if @options[:table_options]
|
35
|
+
end
|
41
36
|
logger.verbose_info('# Load tables')
|
42
37
|
current_definition, _current_execute = @parser.parse(@dumper.dump, opts)
|
43
38
|
logger.verbose_info('# Compare definitions')
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -218,7 +218,6 @@ class Ridgepole::Delta
|
|
218
218
|
|
219
219
|
def append_create_table(table_name, attrs, buf, post_buf_for_fk)
|
220
220
|
options = attrs[:options] || {}
|
221
|
-
options[:options] ||= @options[:table_options] if @options[:table_options]
|
222
221
|
definition = attrs[:definition] || {}
|
223
222
|
indices = attrs[:indices] || {}
|
224
223
|
|
data/lib/ridgepole/dumper.rb
CHANGED
@@ -4,7 +4,6 @@ class Ridgepole::Dumper
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def dump
|
7
|
-
stream = StringIO.new
|
8
7
|
conn = ActiveRecord::Base.connection
|
9
8
|
target_tables = @options[:tables]
|
10
9
|
ignore_tables = @options[:ignore_tables]
|
@@ -24,7 +23,7 @@ class Ridgepole::Dumper
|
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
stream = dump_from(conn)
|
28
27
|
|
29
28
|
if target_tables or ignore_tables
|
30
29
|
ActiveRecord::SchemaDumper.ignore_tables.clear
|
@@ -80,4 +79,14 @@ class Ridgepole::Dumper
|
|
80
79
|
def target?(table_name)
|
81
80
|
not @options[:tables] or @options[:tables].include?(table_name)
|
82
81
|
end
|
82
|
+
|
83
|
+
def dump_from(conn)
|
84
|
+
stream = StringIO.new
|
85
|
+
conn.without_table_options(@options[:dump_without_table_options]) do
|
86
|
+
ActiveRecord::SchemaDumper.with_default_fk_name(@options[:dump_with_default_fk_name]) do
|
87
|
+
ActiveRecord::SchemaDumper.dump(conn, stream)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
stream
|
91
|
+
end
|
83
92
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
2
|
+
|
3
|
+
module Ridgepole
|
4
|
+
module Ext
|
5
|
+
module AbstractAdapter
|
6
|
+
module DisableTableOptions
|
7
|
+
def without_table_options(value)
|
8
|
+
@__without_table_options = value
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
remove_instance_variable(:@__without_table_options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def table_options(table_name)
|
15
|
+
options = super
|
16
|
+
options.delete(:options) if options && @__without_table_options
|
17
|
+
options
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ActiveRecord
|
25
|
+
module ConnectionAdapters
|
26
|
+
class AbstractAdapter
|
27
|
+
def self.inherited(subclass)
|
28
|
+
subclass.prepend Ridgepole::Ext::AbstractAdapter::DisableTableOptions
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -3,7 +3,24 @@ require 'active_record/schema_dumper'
|
|
3
3
|
module Ridgepole
|
4
4
|
module Ext
|
5
5
|
module SchemaDumper
|
6
|
+
def self.prepended(klass)
|
7
|
+
klass.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
attr_reader :__with_default_fk_name
|
12
|
+
|
13
|
+
def with_default_fk_name(value)
|
14
|
+
@__with_default_fk_name = value
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
remove_instance_variable(:@__with_default_fk_name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
6
21
|
def foreign_keys(table, stream)
|
22
|
+
return super unless self.class.__with_default_fk_name
|
23
|
+
|
7
24
|
if (foreign_keys = @connection.foreign_keys(table)).any?
|
8
25
|
add_foreign_key_statements = foreign_keys.map do |foreign_key|
|
9
26
|
parts = [
|
data/lib/ridgepole/version.rb
CHANGED
data/lib/ridgepole.rb
CHANGED
@@ -13,7 +13,9 @@ require 'diffy'
|
|
13
13
|
|
14
14
|
module Ridgepole; end
|
15
15
|
|
16
|
+
require 'ridgepole/ext/abstract_adapter/disable_table_options'
|
16
17
|
require 'ridgepole/ext/pp_sort_hash'
|
18
|
+
require 'ridgepole/ext/schema_dumper'
|
17
19
|
require 'ridgepole/client'
|
18
20
|
require 'ridgepole/connection_adapters'
|
19
21
|
require 'ridgepole/default_limit'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
before { subject.diff(actual_dsl).migrate }
|
3
|
+
subject { client(:table_options => table_options, :dump_without_table_options => false) }
|
4
|
+
|
5
|
+
let(:warning_regexp) { /table options differ/ }
|
6
|
+
|
7
|
+
let(:actual_dsl) {
|
8
|
+
erbh(<<-EOS)
|
9
|
+
create_table "employees", primary_key: "emp_no", force: :cascade, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' do |t|
|
10
|
+
end
|
11
|
+
EOS
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:expected_dsl) {
|
15
|
+
erbh(<<-EOS)
|
16
|
+
create_table :employees, primary_key: :emp_no, force: :cascade do |t|
|
17
|
+
end
|
18
|
+
EOS
|
19
|
+
}
|
20
|
+
|
21
|
+
context 'when change options (no change)' do
|
22
|
+
let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8' }
|
23
|
+
|
24
|
+
it {
|
25
|
+
expect(Ridgepole::Logger.instance).to_not receive(:warn).with(warning_regexp)
|
26
|
+
delta = subject.diff(expected_dsl)
|
27
|
+
expect(delta.differ?).to be_falsey
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when change options (change)' do
|
32
|
+
let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4' }
|
33
|
+
|
34
|
+
it {
|
35
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(warning_regexp)
|
36
|
+
delta = subject.diff(expected_dsl)
|
37
|
+
expect(delta.differ?).to be_falsey
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
@@ -26,4 +26,32 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
26
26
|
EOS
|
27
27
|
}
|
28
28
|
end
|
29
|
+
|
30
|
+
context 'when create table (table definition options takes precedence)' do
|
31
|
+
let(:expected_dsl) {
|
32
|
+
<<-EOS
|
33
|
+
create_table "employee_clubs", force: :cascade, options: "ENGINE=InnoDB CHARSET=utf8mb4" do |t|
|
34
|
+
t.integer "emp_no", null: false, unsigned: true
|
35
|
+
t.integer "club_id", null: false, unsigned: true
|
36
|
+
end
|
37
|
+
|
38
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
39
|
+
EOS
|
40
|
+
}
|
41
|
+
|
42
|
+
subject { client(table_options: 'ENGINE=MyISAM CHARSET=utf8') }
|
43
|
+
|
44
|
+
it {
|
45
|
+
delta = subject.diff(expected_dsl)
|
46
|
+
expect(delta.differ?).to be_truthy
|
47
|
+
|
48
|
+
expect(delta.script).to match_fuzzy <<-EOS
|
49
|
+
create_table("employee_clubs", {:options=>"ENGINE=InnoDB CHARSET=utf8mb4"}) do |t|
|
50
|
+
t.column("emp_no", :"integer", {:null=>false, :unsigned=>true, :limit=>4})
|
51
|
+
t.column("club_id", :"integer", {:null=>false, :unsigned=>true, :limit=>4})
|
52
|
+
end
|
53
|
+
add_index("employee_clubs", ["emp_no", "club_id"], {:name=>"idx_emp_no_club_id", :using=>:btree})
|
54
|
+
EOS
|
55
|
+
}
|
56
|
+
end
|
29
57
|
end
|
data/spec/spec_const.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
TEST_MYSQL_HOST = '127.0.0.1'
|
2
|
-
TEST_MYSQL_PORT = ENV['MYSQL57'] == '1' ?
|
2
|
+
TEST_MYSQL_PORT = ENV['MYSQL57'] == '1' ? 13317 : 13316
|
3
3
|
TEST_MYSQL_USER = 'root'
|
4
4
|
TEST_MYSQL_PASS = 'password'
|
5
5
|
|
6
6
|
MYSQL_CLI = "mysql -h #{TEST_MYSQL_HOST} -P #{TEST_MYSQL_PORT} -u #{TEST_MYSQL_USER} -p#{TEST_MYSQL_PASS} 2>/dev/null"
|
7
7
|
|
8
8
|
TEST_PG_HOST = '127.0.0.1'
|
9
|
-
TEST_PG_PORT =
|
9
|
+
TEST_PG_PORT = 15442
|
10
10
|
TEST_PG_USER = 'postgres'
|
11
11
|
TEST_PG_PASS = 'password'
|
12
12
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridgepole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.beta19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -231,7 +231,7 @@ files:
|
|
231
231
|
- lib/ridgepole/dsl_parser/table_definition.rb
|
232
232
|
- lib/ridgepole/dumper.rb
|
233
233
|
- lib/ridgepole/execute_expander.rb
|
234
|
-
- lib/ridgepole/ext/
|
234
|
+
- lib/ridgepole/ext/abstract_adapter/disable_table_options.rb
|
235
235
|
- lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb
|
236
236
|
- lib/ridgepole/ext/pp_sort_hash.rb
|
237
237
|
- lib/ridgepole/ext/schema_dumper.rb
|
@@ -274,6 +274,7 @@ files:
|
|
274
274
|
- spec/mysql/migrate/migrate_change_column5_spec.rb
|
275
275
|
- spec/mysql/migrate/migrate_change_column6_spec.rb
|
276
276
|
- spec/mysql/migrate/migrate_change_column7_spec.rb
|
277
|
+
- spec/mysql/migrate/migrate_change_column8_spec.rb
|
277
278
|
- spec/mysql/migrate/migrate_change_column_default_spec.rb
|
278
279
|
- spec/mysql/migrate/migrate_change_column_float_spec.rb
|
279
280
|
- spec/mysql/migrate/migrate_change_column_spec.rb
|
@@ -420,6 +421,7 @@ test_files:
|
|
420
421
|
- spec/mysql/migrate/migrate_change_column5_spec.rb
|
421
422
|
- spec/mysql/migrate/migrate_change_column6_spec.rb
|
422
423
|
- spec/mysql/migrate/migrate_change_column7_spec.rb
|
424
|
+
- spec/mysql/migrate/migrate_change_column8_spec.rb
|
423
425
|
- spec/mysql/migrate/migrate_change_column_default_spec.rb
|
424
426
|
- spec/mysql/migrate/migrate_change_column_float_spec.rb
|
425
427
|
- spec/mysql/migrate/migrate_change_column_spec.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
2
|
-
|
3
|
-
module Ridgepole
|
4
|
-
module Ext
|
5
|
-
module AbstractMysqlAdapter
|
6
|
-
module DisableTableOptions
|
7
|
-
def table_options(table_name)
|
8
|
-
options = super
|
9
|
-
options.delete(:options)
|
10
|
-
options
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module ActiveRecord
|
18
|
-
module ConnectionAdapters
|
19
|
-
class AbstractMysqlAdapter
|
20
|
-
prepend Ridgepole::Ext::AbstractMysqlAdapter::DisableTableOptions
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|