From 63ed921eff8271c245b425a29086cf817c1fa2c8 Mon Sep 17 00:00:00 2001 From: Genki Sugawara Date: Fri, 9 Jan 2015 22:18:53 +0900 Subject: [PATCH] Support activerecord-mysql-awesome --- .travis.yml | 4 + README.md | 6 + bin/ridgepole | 9 +- lib/ridgepole/client.rb | 7 +- lib/ridgepole/diff.rb | 2 +- lib/ridgepole/dumper.rb | 6 + lib/ridgepole/ext/mysql_awesome.rb | 8 + lib/ridgepole/version.rb | 2 +- ridgepole.gemspec | 1 + spec/0_diff/dump_disable_unsigned_spec.rb | 2 +- spec/bigint_pk/bigint_pkspec.rb | 24 ++ spec/cli/ridgepole_spec.rb | 3 + spec/collation/collation_spec.rb | 132 ++++++++ spec/comment/comment_spec.rb | 352 +++++++++++----------- spec/dump/dump_class_method_spec.rb | 15 +- spec/spec_helper.rb | 18 +- spec/~pkdump/pkdump_spec.rb | 4 +- 17 files changed, 409 insertions(+), 186 deletions(-) create mode 100644 lib/ridgepole/ext/mysql_awesome.rb create mode 100644 spec/bigint_pk/bigint_pkspec.rb create mode 100644 spec/collation/collation_spec.rb diff --git a/.travis.yml b/.travis.yml index 12126cf3..a02ba665 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,7 @@ rvm: script: - bundle install - bundle exec rake +env: + matrix: + - ENABLE_MYSQL_AWESOME=0 + - ENABLE_MYSQL_AWESOME=1 diff --git a/README.md b/README.md index 6ad68c63..e3ba1766 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations. * `>= 0.5.1` * Add `--enable-migration-comments` option ([migration_comments](https://github.com/pinnymz/migration_comments) is required) * Fix rails version `< 4.2.0` +* `>= 0.5.2` + * Add `--enable-mysql-awesome` option ([activerecord-mysql-awesome](https://github.com/kamipo/activerecord-mysql-awesome) is required) + * It is not possible to enable both `--enable-migration-comments` and `--enable-mysql-awesome` ## Installation @@ -55,6 +58,7 @@ Usage: ridgepole [options] -e, --export --split --split-with-dir + --without-table-options -d, --diff DSL1 DSL2 --reverse --with-apply @@ -65,7 +69,9 @@ Usage: ridgepole [options] --enable-mysql-pkdump --enable-foreigner --enable-migration-comments + --enable-mysql-awesome --normalize-mysql-float + -r, --require LIBS --log-file LOG_FILE --verbose --debug diff --git a/bin/ridgepole b/bin/ridgepole index 9433b4a1..6aae638f 100755 --- a/bin/ridgepole +++ b/bin/ridgepole @@ -74,6 +74,7 @@ ARGV.options do |opt| opt.on('-e', '--export') { set_mode[:export] } opt.on('', '--split') {|v| split = true } opt.on('', '--split-with-dir') {|v| split = :with_dir } + opt.on('', '--without-table-options') { options[:without_table_options] = true } opt.on('-d', '--diff DSL1 DSL2') {|diff_arg1| set_mode[:diff] diff_arg2 = ARGV.first @@ -94,8 +95,10 @@ ARGV.options do |opt| opt.on('', '--enable-mysql-unsigned') { options[:enable_mysql_unsigned] = true } opt.on('', '--enable-mysql-pkdump') { options[:enable_mysql_pkdump] = true } opt.on('', '--enable-foreigner') { options[:enable_foreigner] = true } - opt.on('', '--enable-migration-comments') { options[:migration_comments] = true } + opt.on('', '--enable-migration-comments') { options[:enable_migration_comments] = true } + opt.on('', '--enable-mysql-awesome') { options[:enable_mysql_awesome] = true } opt.on('', '--normalize-mysql-float') { options[:normalize_mysql_float] = true } + opt.on('-r' , '--require LIBS', Array) {|v| v.each {|i| require i } } opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v } opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true } opt.on('' , '--debug') { options[:debug] = true } @@ -118,6 +121,10 @@ ARGV.options do |opt| end begin + if options[:enable_migration_comments] and options[:enable_mysql_awesome] + raise "It is not possible to enable both `--enable-migration-comments` and `--enable-mysql-awesome`" + end + logger = Ridgepole::Logger.instance logger.set_debug(options[:debug]) diff --git a/lib/ridgepole/client.rb b/lib/ridgepole/client.rb index 8a4fc252..bae9ec72 100644 --- a/lib/ridgepole/client.rb +++ b/lib/ridgepole/client.rb @@ -15,10 +15,15 @@ def initialize(conn_spec, options = {}) require 'activerecord-mysql-pkdump' end - if @options[:migration_comments] + if @options[:enable_migration_comments] require 'migration_comments' end + if @options[:enable_mysql_awesome] + require 'activerecord/mysql/awesome/base' + require 'ridgepole/ext/mysql_awesome.rb' + end + if @options[:enable_foreigner] Ridgepole::ForeignKey.init end diff --git a/lib/ridgepole/diff.rb b/lib/ridgepole/diff.rb index 31140042..3e274152 100644 --- a/lib/ridgepole/diff.rb +++ b/lib/ridgepole/diff.rb @@ -255,7 +255,7 @@ def normalize_column_options!(attrs) end # XXX: MySQL only? - if @options[:enable_mysql_unsigned] + if @options[:enable_mysql_unsigned] or @options[:enable_mysql_awesome] opts[:unsigned] = false unless opts.has_key?(:unsigned) end diff --git a/lib/ridgepole/dumper.rb b/lib/ridgepole/dumper.rb index ebfcc1a7..681db556 100644 --- a/lib/ridgepole/dumper.rb +++ b/lib/ridgepole/dumper.rb @@ -34,6 +34,12 @@ def dump line !~ /\A#/ && line !~ /\AActiveRecord::Schema\.define/ && line !~ /\Aend/ + }.map {|line| + if @options[:without_table_options] and line =~ /\A create_table / + line.gsub(/, options: "[^"]*"/, '') + else + line + end }.join.strip_heredoc definitions = [] diff --git a/lib/ridgepole/ext/mysql_awesome.rb b/lib/ridgepole/ext/mysql_awesome.rb new file mode 100644 index 00000000..5ab0e834 --- /dev/null +++ b/lib/ridgepole/ext/mysql_awesome.rb @@ -0,0 +1,8 @@ +require 'active_record/connection_adapters/abstract/schema_definitions' + +# XXX: https://github.com/waka/activerecord-mysql-unsigned/blob/v0.3.1/lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract/schema_definitions.rb#L14 +class ActiveRecord::ConnectionAdapters::TableDefinition + def primary_key(name, type = :primary_key, options = {}) + column(name, type, options.merge(primary_key: true).reverse_merge(unsigned: true)) + end +end diff --git a/lib/ridgepole/version.rb b/lib/ridgepole/version.rb index 1e2bf2ea..b5e0fc9a 100644 --- a/lib/ridgepole/version.rb +++ b/lib/ridgepole/version.rb @@ -1,3 +1,3 @@ module Ridgepole - VERSION = '0.5.1' + VERSION = '0.5.2.beta' end diff --git a/ridgepole.gemspec b/ridgepole.gemspec index 0204d0d8..8f9232b1 100644 --- a/ridgepole.gemspec +++ b/ridgepole.gemspec @@ -28,4 +28,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'foreigner' spec.add_development_dependency 'activerecord-mysql-pkdump', '>= 0.1.0' spec.add_development_dependency 'migration_comments' + spec.add_development_dependency 'activerecord-mysql-awesome' end diff --git a/spec/0_diff/dump_disable_unsigned_spec.rb b/spec/0_diff/dump_disable_unsigned_spec.rb index 48b89ee8..35c4caae 100644 --- a/spec/0_diff/dump_disable_unsigned_spec.rb +++ b/spec/0_diff/dump_disable_unsigned_spec.rb @@ -1,7 +1,7 @@ describe 'Ridgepole::Client#dump' do context 'when there is a tables (disable unsigned)' do before { restore_tables } - subject { client(enable_mysql_unsigned: false) } + subject { client(enable_mysql_unsigned: false, enable_mysql_awesome: false) } it { expect(subject.dump).to eq <<-RUBY.strip_heredoc.strip diff --git a/spec/bigint_pk/bigint_pkspec.rb b/spec/bigint_pk/bigint_pkspec.rb new file mode 100644 index 00000000..3b978467 --- /dev/null +++ b/spec/bigint_pk/bigint_pkspec.rb @@ -0,0 +1,24 @@ +if mysql_awesome_enabled? + describe 'Ridgepole::Client (with bigint pk)' do + let(:dsl) { + <<-RUBY + create_table "books", id: :primary_key, limit: 8, force: true do |t| + t.string "title", null: false + t.integer "author_id", null: false + t.datetime "created_at" + t.datetime "updated_at" + end + RUBY + } + + context 'when dump with activerecord-mysql-pkdump' do + subject { client } + + before { subject.diff(dsl).migrate } + + it { + expect(show_create_table(:books)).to include '`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT' + } + end + end +end diff --git a/spec/cli/ridgepole_spec.rb b/spec/cli/ridgepole_spec.rb index d79b650c..67414ccc 100644 --- a/spec/cli/ridgepole_spec.rb +++ b/spec/cli/ridgepole_spec.rb @@ -23,6 +23,7 @@ -e, --export --split --split-with-dir + --without-table-options -d, --diff DSL1 DSL2 --reverse --with-apply @@ -33,7 +34,9 @@ --enable-mysql-pkdump --enable-foreigner --enable-migration-comments + --enable-mysql-awesome --normalize-mysql-float + -r, --require LIBS --log-file LOG_FILE --verbose --debug diff --git a/spec/collation/collation_spec.rb b/spec/collation/collation_spec.rb new file mode 100644 index 00000000..90523559 --- /dev/null +++ b/spec/collation/collation_spec.rb @@ -0,0 +1,132 @@ +if mysql_awesome_enabled? + describe 'Ridgepole::Client#diff -> migrate' do + context 'when change column (add collation)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false + t.text "text", null: false + end + RUBY + } + + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false, collation: "ascii_bin" + t.text "text", null: false, collation: "utf8mb4_bin" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when change column (delete collation)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false, collation: "ascii_bin" + t.text "text", null: false, collation: "utf8mb4_bin" + end + RUBY + } + + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false + t.text "text", null: false + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when change column (change collation)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false, collation: "ascii_bin" + t.text "text", null: false, collation: "utf8mb4_bin" + end + RUBY + } + + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false, collation: "utf8mb4_bin" + t.text "text", null: false, collation: "ascii_bin" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when change column (no change collation)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false, collation: "ascii_bin" + t.text "text", null: false, collation: "utf8mb4_bin" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client } + + it { + delta = subject.diff(actual_dsl) + expect(delta.differ?).to be_falsey + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + } + end + end +end diff --git a/spec/comment/comment_spec.rb b/spec/comment/comment_spec.rb index 5c8ef9c1..81175d45 100644 --- a/spec/comment/comment_spec.rb +++ b/spec/comment/comment_spec.rb @@ -1,177 +1,179 @@ -describe 'Ridgepole::Client#diff -> migrate' do - context 'when change column (add comment)' do - let(:actual_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false - t.integer "club_id", null: false, unsigned: true - t.string "string", null: false - t.text "text", null: false - end - RUBY - } - - let(:expected_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false, comment: "any comment" - t.integer "club_id", null: false, unsigned: true, comment: "any comment2" - t.string "string", null: false, comment: "any comment3" - t.text "text", null: false, comment: "any comment4" - end - RUBY - } - - before { subject.diff(actual_dsl).migrate } - subject { client(migration_comments: true) } - - it { - delta = subject.diff(expected_dsl) - expect(delta.differ?).to be_truthy - expect(subject.dump).to eq actual_dsl.strip_heredoc.strip - delta.migrate - expect(subject.dump).to eq expected_dsl.strip_heredoc.strip - } - end - - context 'when change column (delete comment)' do - let(:actual_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false, comment: "any comment" - t.integer "club_id", null: false, unsigned: true, comment: "any comment2" - t.string "string", null: false, comment: "any comment3" - t.text "text", null: false, comment: "any comment4" - end - RUBY - } - - let(:expected_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false - t.integer "club_id", null: false, unsigned: true - t.string "string", null: false - t.text "text", null: false - end - RUBY - } - - before { subject.diff(actual_dsl).migrate } - subject { client(migration_comments: true) } - - it { - delta = subject.diff(expected_dsl) - expect(delta.differ?).to be_truthy - expect(subject.dump).to eq actual_dsl.strip_heredoc.strip - delta.migrate - expect(subject.dump).to eq expected_dsl.strip_heredoc.strip - } - end - - context 'when change column (change comment)' do - let(:actual_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false, comment: "any comment" - t.integer "club_id", null: false, unsigned: true, comment: "any comment2" - t.string "string", null: false, comment: "any comment3" - t.text "text", null: false, comment: "any comment4" - end - RUBY - } - - let(:expected_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false, comment: "other comment" - t.integer "club_id", null: false, unsigned: true, comment: "other comment2" - t.string "string", null: false, comment: "other comment3" - t.text "text", null: false, comment: "other comment4" - end - RUBY - } - - before { subject.diff(actual_dsl).migrate } - subject { client(migration_comments: true) } - - it { - delta = subject.diff(expected_dsl) - expect(delta.differ?).to be_truthy - expect(subject.dump).to eq actual_dsl.strip_heredoc.strip - delta.migrate - expect(subject.dump).to eq expected_dsl.strip_heredoc.strip - } - end - - context 'when change column (no change comment)' do - let(:actual_dsl) { - <<-RUBY - create_table "employee_clubs", force: true do |t| - t.integer "emp_no", null: false, comment: "any comment" - t.integer "club_id", null: false, unsigned: true, comment: "any comment2" - t.string "string", null: false, comment: "any comment3" - t.text "text", null: false, comment: "any comment4" - end - RUBY - } - - before { subject.diff(actual_dsl).migrate } - subject { client(migration_comments: true) } - - it { - delta = subject.diff(actual_dsl) - expect(delta.differ?).to be_falsey - expect(subject.dump).to eq actual_dsl.strip_heredoc.strip - delta.migrate - expect(subject.dump).to eq actual_dsl.strip_heredoc.strip - } - end - - context 'when create table (with comment)' do - let(:expected_dsl) { - <<-RUBY - create_table "employee_clubs", force: true, comment: "table comment" do |t| - t.integer "emp_no", null: false, comment: "other comment" - t.integer "club_id", null: false, unsigned: true, comment: "other comment2" - t.string "string", null: false, comment: "other comment3" - t.text "text", null: false, comment: "other comment4" - end - RUBY - } - - subject { client(migration_comments: true) } - - it { - delta = subject.diff(expected_dsl) - expect(delta.differ?).to be_truthy - expect(subject.dump.strip).to be_empty - delta.migrate - expect(subject.dump).to eq expected_dsl.strip_heredoc.strip - } - end - - context 'when drop table (with comment)' do - let(:actual_dsl) { - <<-RUBY - create_table "employee_clubs", force: true, comment: "table comment" do |t| - t.integer "emp_no", null: false, comment: "other comment" - t.integer "club_id", null: false, unsigned: true, comment: "other comment2" - t.string "string", null: false, comment: "other comment3" - t.text "text", null: false, comment: "other comment4" - end - RUBY - } - - before { subject.diff(actual_dsl).migrate } - subject { client(migration_comments: true) } - - it { - delta = subject.diff('') - expect(delta.differ?).to be_truthy - expect(subject.dump).to eq actual_dsl.strip_heredoc.strip - delta.migrate - expect(subject.dump).to be_empty - } +unless mysql_awesome_enabled? + describe 'Ridgepole::Client#diff -> migrate' do + context 'when change column (add comment)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false + t.text "text", null: false + end + RUBY + } + + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false, comment: "any comment" + t.integer "club_id", null: false, unsigned: true, comment: "any comment2" + t.string "string", null: false, comment: "any comment3" + t.text "text", null: false, comment: "any comment4" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client(enable_migration_comments: true) } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when change column (delete comment)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false, comment: "any comment" + t.integer "club_id", null: false, unsigned: true, comment: "any comment2" + t.string "string", null: false, comment: "any comment3" + t.text "text", null: false, comment: "any comment4" + end + RUBY + } + + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false + t.integer "club_id", null: false, unsigned: true + t.string "string", null: false + t.text "text", null: false + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client(enable_migration_comments: true) } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when change column (change comment)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false, comment: "any comment" + t.integer "club_id", null: false, unsigned: true, comment: "any comment2" + t.string "string", null: false, comment: "any comment3" + t.text "text", null: false, comment: "any comment4" + end + RUBY + } + + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false, comment: "other comment" + t.integer "club_id", null: false, unsigned: true, comment: "other comment2" + t.string "string", null: false, comment: "other comment3" + t.text "text", null: false, comment: "other comment4" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client(enable_migration_comments: true) } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when change column (no change comment)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true do |t| + t.integer "emp_no", null: false, comment: "any comment" + t.integer "club_id", null: false, unsigned: true, comment: "any comment2" + t.string "string", null: false, comment: "any comment3" + t.text "text", null: false, comment: "any comment4" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client(enable_migration_comments: true) } + + it { + delta = subject.diff(actual_dsl) + expect(delta.differ?).to be_falsey + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + } + end + + context 'when create table (with comment)' do + let(:expected_dsl) { + <<-RUBY + create_table "employee_clubs", force: true, comment: "table comment" do |t| + t.integer "emp_no", null: false, comment: "other comment" + t.integer "club_id", null: false, unsigned: true, comment: "other comment2" + t.string "string", null: false, comment: "other comment3" + t.text "text", null: false, comment: "other comment4" + end + RUBY + } + + subject { client(enable_migration_comments: true) } + + it { + delta = subject.diff(expected_dsl) + expect(delta.differ?).to be_truthy + expect(subject.dump.strip).to be_empty + delta.migrate + expect(subject.dump).to eq expected_dsl.strip_heredoc.strip + } + end + + context 'when drop table (with comment)' do + let(:actual_dsl) { + <<-RUBY + create_table "employee_clubs", force: true, comment: "table comment" do |t| + t.integer "emp_no", null: false, comment: "other comment" + t.integer "club_id", null: false, unsigned: true, comment: "other comment2" + t.string "string", null: false, comment: "other comment3" + t.text "text", null: false, comment: "other comment4" + end + RUBY + } + + before { subject.diff(actual_dsl).migrate } + subject { client(enable_migration_comments: true) } + + it { + delta = subject.diff('') + expect(delta.differ?).to be_truthy + expect(subject.dump).to eq actual_dsl.strip_heredoc.strip + delta.migrate + expect(subject.dump).to be_empty + } + end end end diff --git a/spec/dump/dump_class_method_spec.rb b/spec/dump/dump_class_method_spec.rb index 1fc6a161..afb856e4 100644 --- a/spec/dump/dump_class_method_spec.rb +++ b/spec/dump/dump_class_method_spec.rb @@ -3,8 +3,21 @@ before { restore_tables } subject { Ridgepole::Client } + let(:options) { + opts = {} + + if mysql_awesome_enabled? + opts[:enable_mysql_awesome] = true + opts[:without_table_options] = true + else + opts[:enable_mysql_unsigned] = true + end + + opts + } + it { - expect(subject.dump(conn_spec, enable_mysql_unsigned: true)).to eq <<-RUBY.strip_heredoc.strip + expect(subject.dump(conn_spec, options)).to eq <<-RUBY.strip_heredoc.strip create_table "clubs", force: true do |t| t.string "name", default: "", null: false end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d9e882b7..b917fb7f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -49,10 +49,18 @@ def restore_tables def client(options = {}, config = {}) config = conn_spec(config) - options = { - :enable_mysql_unsigned => true, + default_options = { :debug => !!ENV['DEBUG'], - }.merge(options) + } + + if mysql_awesome_enabled? + default_options[:enable_mysql_awesome] = true + default_options[:without_table_options] = true + else + default_options[:enable_mysql_unsigned] = true + end + + options = default_options.merge(options) Ridgepole::Client.new(config, options) end @@ -129,3 +137,7 @@ def run_cli(options = {}) Open3.capture2e(cmd) end end + +def mysql_awesome_enabled? + ENV['ENABLE_MYSQL_AWESOME'] == '1' +end diff --git a/spec/~pkdump/pkdump_spec.rb b/spec/~pkdump/pkdump_spec.rb index 9e7297fa..31209fc2 100644 --- a/spec/~pkdump/pkdump_spec.rb +++ b/spec/~pkdump/pkdump_spec.rb @@ -27,7 +27,7 @@ end context 'when create with activerecord-mysql-pkdump' do - subject { client(enable_foreigner: true) } + subject { client(enable_mysql_pkdump: true) } it { delta = subject.diff(dsl) @@ -39,7 +39,7 @@ end context 'update create with activerecord-mysql-pkdump' do - subject { client(enable_foreigner: true) } + subject { client(enable_mysql_pkdump: true) } before { subject.diff(dsl).migrate }