ridgepole 0.7.3.beta → 0.7.3.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -0
- data/Appraisals +2 -2
- data/README.md +3 -9
- data/Rakefile +7 -1
- data/bin/ridgepole +97 -108
- data/gemfiles/activerecord_5.2.gemfile +1 -1
- data/lib/ridgepole/cli/config.rb +43 -43
- data/lib/ridgepole/client.rb +65 -63
- data/lib/ridgepole/default_limit.rb +26 -24
- data/lib/ridgepole/delta.rb +367 -369
- data/lib/ridgepole/diff.rb +366 -377
- data/lib/ridgepole/dsl_parser.rb +22 -20
- data/lib/ridgepole/dsl_parser/context.rb +95 -93
- data/lib/ridgepole/dsl_parser/table_definition.rb +125 -123
- data/lib/ridgepole/dumper.rb +73 -71
- data/lib/ridgepole/execute_expander.rb +55 -55
- data/lib/ridgepole/ext/abstract_mysql_adapter/dump_auto_increment.rb +3 -3
- data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +1 -1
- data/lib/ridgepole/ext/pp_sort_hash.rb +14 -14
- data/lib/ridgepole/ext/schema_dumper.rb +1 -1
- data/lib/ridgepole/external_sql_executer.rb +20 -20
- data/lib/ridgepole/logger.rb +17 -15
- data/lib/ridgepole/migration_ext.rb +6 -8
- data/lib/ridgepole/schema_statements_ext.rb +3 -3
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +11 -10
- data/spec/cli_helper.rb +2 -2
- data/spec/erb_helper.rb +6 -2
- data/spec/hide_pending_formatter.rb +5 -4
- data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +8 -8
- data/spec/mysql/bigint_pk/bigint_pk_spec.rb +8 -8
- data/spec/mysql/bigint_pk/int_pk_spec.rb +13 -13
- data/spec/mysql/cli/config_spec.rb +52 -53
- data/spec/mysql/cli/ridgepole_spec.rb +111 -111
- data/spec/mysql/collation/collation_spec.rb +39 -39
- data/spec/mysql/comment/comment_spec.rb +36 -36
- data/spec/mysql/default_lambda/default_lambda_spec.rb +30 -30
- data/spec/mysql/diff/diff2_spec.rb +18 -18
- data/spec/mysql/diff/diff_spec.rb +11 -11
- data/spec/mysql/dump/dump_class_method_spec.rb +2 -2
- data/spec/mysql/dump/dump_some_tables_spec.rb +14 -14
- data/spec/mysql/dump/dump_spec.rb +2 -2
- data/spec/mysql/dump/dump_unknown_column_type_spec.rb +3 -3
- data/spec/mysql/dump/dump_without_table_options_spec.rb +8 -8
- data/spec/mysql/fk/migrate_change_fk_spec.rb +40 -40
- data/spec/mysql/fk/migrate_create_fk_spec.rb +40 -40
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +60 -60
- data/spec/mysql/migrate/check_orphan_index_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_add_column2_spec.rb +43 -43
- data/spec/mysql/migrate/migrate_add_column_order_spec.rb +50 -50
- data/spec/mysql/migrate/migrate_add_column_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_change_column2_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +60 -60
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_column5_spec.rb +24 -24
- data/spec/mysql/migrate/migrate_change_column6_spec.rb +40 -40
- data/spec/mysql/migrate/migrate_change_column7_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_change_column8_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_change_column_default_spec.rb +48 -48
- data/spec/mysql/migrate/migrate_change_column_float_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_column_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_change_index2_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_index3_spec.rb +43 -43
- data/spec/mysql/migrate/migrate_change_index4_spec.rb +24 -24
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_index6_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_change_index7_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_index8_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_index_spec.rb +17 -17
- data/spec/mysql/migrate/migrate_change_table_comment_spec.rb +10 -10
- data/spec/mysql/migrate/migrate_change_table_option_spec.rb +18 -18
- data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +37 -37
- data/spec/mysql/migrate/migrate_create_index2_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_create_index_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_create_table_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +10 -10
- data/spec/mysql/migrate/migrate_drop_column_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_drop_index_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_drop_table_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_empty_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_execute_spec.rb +55 -55
- data/spec/mysql/migrate/migrate_log_file_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_merge_mode_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_noop_spec.rb +19 -19
- data/spec/mysql/migrate/migrate_primary_key_spec.rb +18 -18
- data/spec/mysql/migrate/migrate_rename_column_spec.rb +17 -17
- data/spec/mysql/migrate/migrate_rename_table_spec.rb +26 -26
- data/spec/mysql/migrate/migrate_same_default_null_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_same_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_script_error_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +64 -64
- data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_with_tables_spec.rb +29 -29
- data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +18 -18
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +8 -8
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +8 -8
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +8 -8
- data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +12 -12
- data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +30 -30
- data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +22 -22
- data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +7 -7
- data/spec/mysql57/json/add_json_column_spec.rb +8 -8
- data/spec/mysql57/json/change_json_column_spec.rb +24 -24
- data/spec/mysql57/json/drop_json_column_spec.rb +8 -8
- data/spec/mysql57/virtual/add_virtual_column_spec.rb +9 -9
- data/spec/mysql57/virtual/change_virtual_column_spec.rb +9 -9
- data/spec/mysql57/virtual/drop_virtual_column_spec.rb +9 -9
- data/spec/postgresql/diff/diff_spec.rb +18 -18
- data/spec/postgresql/dump/dump_spec.rb +2 -2
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +24 -24
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +40 -40
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +44 -44
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +21 -21
- data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +2 -2
- data/spec/postgresql/migrate/migrate_bigint_spec.rb +12 -12
- data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +19 -19
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +13 -13
- data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +19 -19
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +18 -18
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +11 -11
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +12 -12
- data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +11 -11
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_primary_key_spec.rb +97 -0
- data/spec/postgresql/migrate/migrate_references_spec.rb +24 -24
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +11 -11
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +16 -16
- data/spec/postgresql/migrate/migrate_same_spec.rb +4 -4
- data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +12 -12
- data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +30 -30
- data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +22 -22
- data/spec/processing_for_travis.rb +1 -1
- data/spec/spec_condition.rb +2 -2
- data/spec/spec_const.rb +9 -9
- data/spec/spec_helper.rb +21 -23
- metadata +54 -37
data/lib/ridgepole/logger.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Ridgepole
|
2
|
+
class Logger < ::Logger
|
3
|
+
include Singleton
|
4
|
+
cattr_accessor :verbose
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
def initialize
|
7
|
+
super($stdout)
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
self.formatter = proc do |_severity, _datetime, _progname, msg|
|
10
|
+
"#{msg}\n"
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
self.level = Logger::INFO
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def verbose_info(msg)
|
17
|
+
info(msg) if verbose
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
def debug=(value)
|
21
|
+
self.level = value ? Logger::DEBUG : Logger::INFO
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
@@ -13,7 +13,7 @@ module Ridgepole
|
|
13
13
|
begin
|
14
14
|
self.time_recorder = TimeRecorder.new
|
15
15
|
yield
|
16
|
-
result =
|
16
|
+
result = time_recorder.result
|
17
17
|
ensure
|
18
18
|
self.time_recorder = nil
|
19
19
|
end
|
@@ -25,18 +25,18 @@ module Ridgepole
|
|
25
25
|
|
26
26
|
def write(text = '')
|
27
27
|
logger = Ridgepole::Logger.instance
|
28
|
-
logger.info(text) unless
|
28
|
+
logger.info(text) unless disable_logging
|
29
29
|
parse_text(text)
|
30
30
|
end
|
31
31
|
|
32
32
|
def parse_text(text)
|
33
|
-
return unless
|
33
|
+
return unless time_recorder
|
34
34
|
|
35
35
|
case text
|
36
36
|
when /\A--\s+(.+)\Z/
|
37
|
-
|
37
|
+
time_recorder.add_key(Regexp.last_match(1))
|
38
38
|
when /\A\s+->\s+(\d+\.\d+)s\Z/
|
39
|
-
|
39
|
+
time_recorder.add_value(Regexp.last_match(1).to_f)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -52,9 +52,7 @@ module Ridgepole
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def add_value(value)
|
55
|
-
if @key
|
56
|
-
@result[@key] = value
|
57
|
-
end
|
55
|
+
@result[@key] = value if @key
|
58
56
|
|
59
57
|
@key = nil
|
60
58
|
end
|
@@ -4,10 +4,10 @@ module Ridgepole
|
|
4
4
|
module SchemaStatementsExt
|
5
5
|
def index_name_exists?(*)
|
6
6
|
if Ridgepole::ExecuteExpander.noop
|
7
|
-
caller_methods = caller.map {|i| i =~ /:\d+:in `(.+)'/ ?
|
8
|
-
if caller_methods.any? {|i| i
|
7
|
+
caller_methods = caller.map { |i| i =~ /:\d+:in `(.+)'/ ? Regexp.last_match(1) : '' }
|
8
|
+
if caller_methods.any? { |i| i.start_with?('remove_index') }
|
9
9
|
true
|
10
|
-
elsif caller_methods.any? {|i| i
|
10
|
+
elsif caller_methods.any? { |i| i.start_with?('add_index') }
|
11
11
|
false
|
12
12
|
else
|
13
13
|
super
|
data/lib/ridgepole/version.rb
CHANGED
data/ridgepole.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'ridgepole/version'
|
5
4
|
|
@@ -8,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
8
7
|
spec.version = Ridgepole::VERSION
|
9
8
|
spec.authors = ['Genki Sugawara']
|
10
9
|
spec.email = ['sugawara@cookpad.com']
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
10
|
+
spec.summary = 'Ridgepole is a tool to manage DB schema.'
|
11
|
+
spec.description = 'Ridgepole is a tool to manage DB schema. It defines DB schema using Rails DSL, and updates DB schema according to DSL.'
|
13
12
|
spec.homepage = 'https://github.com/winebarrel/ridgepole'
|
14
13
|
spec.license = 'MIT'
|
15
14
|
|
@@ -22,16 +21,18 @@ Gem::Specification.new do |spec|
|
|
22
21
|
|
23
22
|
spec.add_dependency 'activerecord', '>= 5.0.1', '< 6'
|
24
23
|
spec.add_dependency 'diffy'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'appraisal', '>= 2.2.0'
|
25
26
|
spec.add_development_dependency 'bundler'
|
26
|
-
spec.add_development_dependency 'rake'
|
27
|
-
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
28
|
-
spec.add_development_dependency 'mysql2', '~> 0.3.20'
|
29
|
-
spec.add_development_dependency 'pg'
|
30
27
|
spec.add_development_dependency 'coveralls'
|
31
|
-
spec.add_development_dependency 'appraisal', '>= 2.2.0'
|
32
|
-
spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
|
33
28
|
spec.add_development_dependency 'erbh', '>= 0.1.2'
|
34
29
|
spec.add_development_dependency 'hash_modern_inspect', '>= 0.1.1'
|
35
30
|
spec.add_development_dependency 'hash_order_helper', '>= 0.1.6'
|
31
|
+
spec.add_development_dependency 'mysql2', '~> 0.3.20'
|
32
|
+
spec.add_development_dependency 'pg'
|
33
|
+
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
35
|
+
spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
|
36
36
|
spec.add_development_dependency 'rspec-match_ruby', '>= 0.1.3'
|
37
|
+
spec.add_development_dependency 'rubocop', '>= 0.57.1'
|
37
38
|
end
|
data/spec/cli_helper.rb
CHANGED
@@ -48,9 +48,9 @@ module CLIHelper
|
|
48
48
|
def run_cli(options = {})
|
49
49
|
args = options[:args] || []
|
50
50
|
hook = options[:hook] || default_cli_hook
|
51
|
-
path = File.expand_path('
|
51
|
+
path = File.expand_path('../bin/ridgepole', __dir__)
|
52
52
|
|
53
|
-
Tempfile.open(["#{File.basename __FILE__}.#{
|
53
|
+
Tempfile.open(["#{File.basename __FILE__}.#{$PROCESS_ID}", '.rb']) do |f|
|
54
54
|
f.puts(hook)
|
55
55
|
f.puts(File.read(path))
|
56
56
|
f.flush
|
data/spec/erb_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
include ERBh
|
2
2
|
|
3
3
|
ERBh.define_method(:i) do |obj|
|
4
|
-
if obj.nil?
|
4
|
+
if obj.nil? || (obj.respond_to?(:empty?) && obj.empty?)
|
5
5
|
@_erbout.sub!(/,\s*\z/, '')
|
6
6
|
''
|
7
7
|
elsif obj.is_a?(Hash)
|
@@ -15,6 +15,10 @@ ERBh.define_method(:cond) do |conds, m, e = nil|
|
|
15
15
|
if condition(*Array(conds))
|
16
16
|
m
|
17
17
|
else
|
18
|
-
e || (
|
18
|
+
e || (begin
|
19
|
+
m.class.new
|
20
|
+
rescue StandardError
|
21
|
+
nil
|
22
|
+
end)
|
19
23
|
end
|
20
24
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class HidePendingFormatter < RSpec::Core::Formatters::ProgressFormatter
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
RSpec::Core::Formatters.register self, :example_pending
|
3
|
+
RSpec::Core::Formatters.register self, :dump_pending
|
4
|
+
def example_pending(notification); end
|
5
|
+
|
6
|
+
def dump_pending(notification); end
|
6
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when change mysql table options' do
|
3
|
-
let(:actual_dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:actual_dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "employees", primary_key: "emp_no", force: :cascade, options: "ENGINE=MyISAM DEFAULT CHARSET=utf8" do |t|
|
6
6
|
t.date "birth_date", null: false
|
7
7
|
t.string "first_name", limit: 14, null: false
|
@@ -9,11 +9,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
9
9
|
t.string "gender", limit: 1, null: false
|
10
10
|
t.date "hire_date", null: false
|
11
11
|
end
|
12
|
-
|
13
|
-
|
12
|
+
ERB
|
13
|
+
end
|
14
14
|
|
15
|
-
let(:expected_dsl)
|
16
|
-
erbh(<<-
|
15
|
+
let(:expected_dsl) do
|
16
|
+
erbh(<<-ERB)
|
17
17
|
create_table "employees", primary_key: "emp_no", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii" do |t|
|
18
18
|
t.date "birth_date", null: false
|
19
19
|
t.string "first_name", limit: 14, null: false, <%= i cond(5.2, collation: "utf8_general_ci") %>
|
@@ -21,8 +21,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
21
21
|
t.string "gender", limit: 1, null: false, <%= i cond(5.2, collation: "utf8_general_ci") %>
|
22
22
|
t.date "hire_date", null: false
|
23
23
|
end
|
24
|
-
|
25
|
-
|
24
|
+
ERB
|
25
|
+
end
|
26
26
|
|
27
27
|
before { subject.diff(actual_dsl).migrate }
|
28
28
|
subject { client(dump_without_table_options: false, mysql_change_table_options: true) }
|
@@ -1,25 +1,25 @@
|
|
1
1
|
describe 'Ridgepole::Client (with bigint pk)', condition: 5.0 do
|
2
|
-
let(:id_primary_key_create_table)
|
3
|
-
<<-
|
2
|
+
let(:id_primary_key_create_table) do
|
3
|
+
<<-RUBY
|
4
4
|
create_table "books", id: :primary_key, limit: 8, force: :cascade do |t|
|
5
5
|
t.string "title", null: false
|
6
6
|
t.integer "author_id", null: false
|
7
7
|
t.datetime "created_at"
|
8
8
|
t.datetime "updated_at"
|
9
9
|
end
|
10
|
-
|
11
|
-
|
10
|
+
RUBY
|
11
|
+
end
|
12
12
|
|
13
|
-
let(:id_bigint_create_table)
|
14
|
-
<<-
|
13
|
+
let(:id_bigint_create_table) do
|
14
|
+
<<-RUBY
|
15
15
|
create_table "books", id: :bigint, force: :cascade do |t|
|
16
16
|
t.string "title", null: false
|
17
17
|
t.integer "author_id", null: false
|
18
18
|
t.datetime "created_at"
|
19
19
|
t.datetime "updated_at"
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
RUBY
|
22
|
+
end
|
23
23
|
|
24
24
|
context 'when with limit:8' do
|
25
25
|
subject { client }
|
@@ -1,45 +1,45 @@
|
|
1
|
-
describe 'Ridgepole::Client (with integer pk)', condition: 5.1 do
|
1
|
+
describe 'Ridgepole::Client (with integer pk)', condition: '>= 5.1.0' do
|
2
2
|
context 'when with id:integer' do
|
3
|
-
let(:dsl)
|
4
|
-
<<-
|
3
|
+
let(:dsl) do
|
4
|
+
<<-RUBY
|
5
5
|
create_table "books", id: :integer, force: :cascade do |t|
|
6
6
|
t.string "title", null: false
|
7
7
|
t.integer "author_id", null: false
|
8
8
|
t.datetime "created_at"
|
9
9
|
t.datetime "updated_at"
|
10
10
|
end
|
11
|
-
|
12
|
-
|
11
|
+
RUBY
|
12
|
+
end
|
13
13
|
|
14
14
|
subject { client }
|
15
15
|
|
16
16
|
before { subject.diff(dsl).migrate }
|
17
17
|
|
18
|
-
specify
|
18
|
+
specify do
|
19
19
|
expect(show_create_table(:books)).to include '`id` int(11) NOT NULL AUTO_INCREMENT'
|
20
20
|
expect(subject.dump).to match_ruby dsl
|
21
|
-
|
21
|
+
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'when without id:integer' do
|
25
|
-
let(:dsl)
|
26
|
-
<<-
|
25
|
+
let(:dsl) do
|
26
|
+
<<-RUBY
|
27
27
|
create_table "books", force: :cascade do |t|
|
28
28
|
t.string "title", null: false
|
29
29
|
t.integer "author_id", null: false
|
30
30
|
t.datetime "created_at"
|
31
31
|
t.datetime "updated_at"
|
32
32
|
end
|
33
|
-
|
34
|
-
|
33
|
+
RUBY
|
34
|
+
end
|
35
35
|
|
36
36
|
subject { client }
|
37
37
|
|
38
38
|
before { subject.diff(dsl).migrate }
|
39
39
|
|
40
|
-
specify
|
40
|
+
specify do
|
41
41
|
expect(show_create_table(:books)).to include '`id` bigint(20) NOT NULL AUTO_INCREMENT'
|
42
42
|
expect(subject.dump).to match_ruby dsl
|
43
|
-
|
43
|
+
end
|
44
44
|
end
|
45
45
|
end
|
@@ -2,43 +2,43 @@ describe Ridgepole::Config do
|
|
2
2
|
subject { Ridgepole::Config.load(config, env) }
|
3
3
|
|
4
4
|
context 'when passed toplevel yaml' do
|
5
|
-
let(:config)
|
5
|
+
let(:config) do
|
6
6
|
<<-YAML.strip_heredoc
|
7
7
|
adapter: mysql2
|
8
8
|
encoding: utf8
|
9
9
|
database: blog
|
10
10
|
username: root
|
11
11
|
YAML
|
12
|
-
|
12
|
+
end
|
13
13
|
let(:env) { 'development' }
|
14
|
-
specify
|
15
|
-
expect(subject['adapter']).to eq
|
16
|
-
expect(subject['encoding']).to eq
|
17
|
-
expect(subject['database']).to eq
|
18
|
-
expect(subject['username']).to eq
|
19
|
-
|
14
|
+
specify do
|
15
|
+
expect(subject['adapter']).to eq 'mysql2'
|
16
|
+
expect(subject['encoding']).to eq 'utf8'
|
17
|
+
expect(subject['database']).to eq 'blog'
|
18
|
+
expect(subject['username']).to eq 'root'
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when passed dynamic yaml' do
|
23
|
-
let(:config)
|
23
|
+
let(:config) do
|
24
24
|
<<-YAML.strip_heredoc
|
25
25
|
adapter: mysql2
|
26
26
|
encoding: utf8
|
27
27
|
database: blog_<%= 1 + 2 %>
|
28
28
|
username: user_<%= 3 * 4 %>
|
29
29
|
YAML
|
30
|
-
|
30
|
+
end
|
31
31
|
let(:env) { 'development' }
|
32
|
-
specify
|
33
|
-
expect(subject['adapter']).to eq
|
34
|
-
expect(subject['encoding']).to eq
|
35
|
-
expect(subject['database']).to eq
|
36
|
-
expect(subject['username']).to eq
|
37
|
-
|
32
|
+
specify do
|
33
|
+
expect(subject['adapter']).to eq 'mysql2'
|
34
|
+
expect(subject['encoding']).to eq 'utf8'
|
35
|
+
expect(subject['database']).to eq 'blog_3'
|
36
|
+
expect(subject['username']).to eq 'user_12'
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'when passed rails database.yml style yaml' do
|
41
|
-
let(:config)
|
41
|
+
let(:config) do
|
42
42
|
<<-YAML.strip_heredoc
|
43
43
|
development:
|
44
44
|
adapter: sqlspecifye
|
@@ -49,63 +49,63 @@ describe Ridgepole::Config do
|
|
49
49
|
database: blog
|
50
50
|
username: root
|
51
51
|
YAML
|
52
|
-
|
52
|
+
end
|
53
53
|
|
54
54
|
context 'in development env' do
|
55
55
|
let(:env) { 'development' }
|
56
|
-
specify
|
57
|
-
expect(subject['adapter']).to eq
|
58
|
-
expect(subject['database']).to eq
|
56
|
+
specify do
|
57
|
+
expect(subject['adapter']).to eq 'sqlspecifye'
|
58
|
+
expect(subject['database']).to eq 'db/sample.db'
|
59
59
|
expect(subject['username']).to be_nil
|
60
|
-
|
60
|
+
end
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'in production env' do
|
64
64
|
let(:env) { 'production' }
|
65
|
-
specify
|
66
|
-
expect(subject['adapter']).to eq
|
67
|
-
expect(subject['encoding']).to eq
|
68
|
-
expect(subject['database']).to eq
|
69
|
-
expect(subject['username']).to eq
|
70
|
-
|
65
|
+
specify do
|
66
|
+
expect(subject['adapter']).to eq 'mysql2'
|
67
|
+
expect(subject['encoding']).to eq 'utf8'
|
68
|
+
expect(subject['database']).to eq 'blog'
|
69
|
+
expect(subject['username']).to eq 'root'
|
70
|
+
end
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'when passed yaml file' do
|
75
|
-
let(:config)
|
75
|
+
let(:config) do
|
76
76
|
<<-YAML.strip_heredoc
|
77
77
|
adapter: mysql2
|
78
78
|
encoding: utf8
|
79
79
|
database: blog
|
80
80
|
username: root
|
81
81
|
YAML
|
82
|
-
|
82
|
+
end
|
83
83
|
let(:env) { 'development' }
|
84
84
|
it {
|
85
|
-
Tempfile.create(
|
85
|
+
Tempfile.create('database.yml') do |f|
|
86
86
|
f.puts config
|
87
87
|
f.flush
|
88
88
|
|
89
|
-
expect(subject['adapter']).to eq
|
90
|
-
expect(subject['encoding']).to eq
|
91
|
-
expect(subject['database']).to eq
|
92
|
-
expect(subject['username']).to eq
|
89
|
+
expect(subject['adapter']).to eq 'mysql2'
|
90
|
+
expect(subject['encoding']).to eq 'utf8'
|
91
|
+
expect(subject['database']).to eq 'blog'
|
92
|
+
expect(subject['username']).to eq 'root'
|
93
93
|
end
|
94
94
|
}
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'when passed unexisting yaml' do
|
98
|
-
let(:config)
|
98
|
+
let(:config) do
|
99
99
|
'database.yml'
|
100
|
-
|
100
|
+
end
|
101
101
|
|
102
102
|
let(:env) { 'development' }
|
103
103
|
|
104
|
-
specify
|
105
|
-
expect
|
104
|
+
specify do
|
105
|
+
expect do
|
106
106
|
subject
|
107
|
-
|
108
|
-
|
107
|
+
end.to raise_error 'Invalid config: "database.yml"'
|
108
|
+
end
|
109
109
|
end
|
110
110
|
|
111
111
|
context 'when passed DATABASE_URL' do
|
@@ -113,10 +113,10 @@ describe Ridgepole::Config do
|
|
113
113
|
let(:env) { 'development' }
|
114
114
|
|
115
115
|
it {
|
116
|
-
expect(subject['adapter']).to eq
|
117
|
-
expect(subject['database']).to eq
|
118
|
-
expect(subject['username']).to eq
|
119
|
-
expect(subject['password']).to eq
|
116
|
+
expect(subject['adapter']).to eq 'mysql2'
|
117
|
+
expect(subject['database']).to eq 'blog'
|
118
|
+
expect(subject['username']).to eq 'root'
|
119
|
+
expect(subject['password']).to eq 'pass'
|
120
120
|
expect(subject['port']).to eq 3307
|
121
121
|
}
|
122
122
|
end
|
@@ -125,16 +125,15 @@ describe Ridgepole::Config do
|
|
125
125
|
let(:config) { 'env:DATABASE_URL' }
|
126
126
|
let(:env) { 'development' }
|
127
127
|
|
128
|
-
before
|
129
|
-
allow(ENV).to receive(:fetch).with('DATABASE_URL').
|
130
|
-
|
131
|
-
}
|
128
|
+
before do
|
129
|
+
allow(ENV).to receive(:fetch).with('DATABASE_URL').and_return('mysql2://root:pass@127.0.0.1:3307/blog')
|
130
|
+
end
|
132
131
|
|
133
132
|
it {
|
134
|
-
expect(subject['adapter']).to eq
|
135
|
-
expect(subject['database']).to eq
|
136
|
-
expect(subject['username']).to eq
|
137
|
-
expect(subject['password']).to eq
|
133
|
+
expect(subject['adapter']).to eq 'mysql2'
|
134
|
+
expect(subject['database']).to eq 'blog'
|
135
|
+
expect(subject['username']).to eq 'root'
|
136
|
+
expect(subject['password']).to eq 'pass'
|
138
137
|
expect(subject['port']).to eq 3307
|
139
138
|
}
|
140
139
|
end
|