Skip to content

Commit

Permalink
Merge pull request #440 from alpaca-tc/1.3-drop-rails-6-0
Browse files Browse the repository at this point in the history
Drop older rails
  • Loading branch information
winebarrel committed Oct 14, 2023
2 parents 8c7f6ea + cc0ab4d commit 2509abc
Show file tree
Hide file tree
Showing 30 changed files with 53 additions and 117 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -32,7 +32,6 @@ jobs:
- MYSQL80=1
- POSTGRESQL=1
gemfile:
- gemfiles/activerecord_6.0.gemfile
- gemfiles/activerecord_6.1.gemfile
- gemfiles/activerecord_7.0.gemfile
env:
Expand Down
4 changes: 0 additions & 4 deletions Appraisals
@@ -1,9 +1,5 @@
# frozen_string_literal: true

appraise 'activerecord-6.0' do
gem 'activerecord', '~> 6.0.6'
end

appraise 'activerecord-6.1' do
gem 'activerecord', '~> 6.1.7'
end
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -312,7 +312,7 @@ end
```

```sh
$ ridgepole -a -c database.yml --check-relation-type bigint # default primary key type (e.g. `<5.1`: integer, `>=5.1`: bigint for MySQL)
$ ridgepole -a -c database.yml --check-relation-type bigint # default primary key type (e.g. bigint for MySQL)
Apply `Schemafile`
...
[WARNING] Relation column type is different.
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activerecord_7.0.gemfile
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

gem "activerecord", "~> 7.0.4"
gem "activerecord", "~> 7.0.7"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/ridgepole/delta.rb
Expand Up @@ -299,7 +299,7 @@ def append_change_table_options(table_name, table_options, buf)
end

def append_change_table_raw_options(table_name, raw_table_options, table_charset, table_collation, buf)
if raw_table_options.blank? && ActiveRecord.gem_version >= Gem::Version.new('6.1.0')
if raw_table_options.blank?
# Implicit engine is InnoDB in 6.1.0
# related: https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R441
raw_table_options = +'ENGINE=InnoDB'
Expand Down
2 changes: 0 additions & 2 deletions lib/ridgepole/ext/abstract_adapter/disable_table_options.rb
Expand Up @@ -18,8 +18,6 @@ def table_options(table_name)

if options && @__without_table_options
options.delete(:options)

# For >= AR 6.1.0
options.delete(:charset)
options.delete(:collation)
end
Expand Down
13 changes: 1 addition & 12 deletions lib/ridgepole/external_sql_executer.rb
Expand Up @@ -8,7 +8,7 @@ def initialize(script, logger)
end

def execute(sql)
cmd = Shellwords.join([@script, sql, JSON.dump(connection_configuration_hash)])
cmd = Shellwords.join([@script, sql, JSON.dump(ActiveRecord::Base.connection_db_config.configuration_hash)])
@logger.info("Execute #{@script}")
script_basename = File.basename(@script)

Expand Down Expand Up @@ -46,16 +46,5 @@ def execute(sql)
raise "`#{@script}` execution failed" unless wait_thr.value.success?
end
end

private

def connection_configuration_hash
if ActiveRecord.gem_version < Gem::Version.new('6.1.0')
# NOTE: Remove code when stopping support for versions below 6.1
ActiveRecord::Base.connection_config
else
ActiveRecord::Base.connection_db_config.configuration_hash
end
end
end
end
2 changes: 1 addition & 1 deletion ridgepole.gemspec
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = Gem::Requirement.new('>= 2.7')

spec.add_dependency 'activerecord', '>= 5.1', '< 7.1'
spec.add_dependency 'activerecord', '>= 6.1', '< 7.1'
spec.add_dependency 'diffy'

spec.add_development_dependency 'appraisal', '>= 2.2.0'
Expand Down
4 changes: 2 additions & 2 deletions spec/mysql/_migrate/migrate_change_table_option_spec.rb
Expand Up @@ -4,7 +4,7 @@
context 'when change mysql table options' do
let(:actual_dsl) do
erbh(<<-ERB, utf8: condition(:mysql80) ? 'utf8mb3' : 'utf8')
create_table "employees", primary_key: "emp_no", force: :cascade, <%= i cond(">= 6.1", { charset: @utf8, options: "ENGINE=MyISAM" }, { options: "ENGINE=MyISAM DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "employees", primary_key: "emp_no", force: :cascade, charset: "<%= @utf8 %>", options: "ENGINE=MyISAM" do |t|
t.date "birth_date", null: false
t.string "first_name", limit: 14, null: false
t.string "last_name", limit: 16, null: false
Expand All @@ -16,7 +16,7 @@

let(:expected_dsl) do
erbh(<<-ERB)
create_table "employees", primary_key: "emp_no", force: :cascade, <%= i cond(">= 6.1", { charset: "ascii" }, { options: "ENGINE=InnoDB DEFAULT CHARSET=ascii" }) %> do |t|
create_table "employees", primary_key: "emp_no", force: :cascade, charset: "ascii" do |t|
t.date "birth_date", null: false
t.string "first_name", limit: 14, null: false, collation: "utf8_general_ci"
t.string "last_name", limit: 16, null: false, collation: "utf8_general_ci"
Expand Down
14 changes: 7 additions & 7 deletions spec/mysql/collation/collation_spec.rb
Expand Up @@ -4,7 +4,7 @@
context 'when change column (add collation)' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "ascii_bin"
Expand All @@ -15,7 +15,7 @@

let(:expected_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "ascii_bin"
Expand All @@ -39,7 +39,7 @@
context 'when change column (delete collation)' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "ascii_bin"
Expand All @@ -50,7 +50,7 @@

let(:expected_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "ascii_bin"
Expand All @@ -74,7 +74,7 @@
context 'when change column (change collation)' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "ascii_bin"
Expand All @@ -85,7 +85,7 @@

let(:expected_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "utf8mb4_bin"
Expand All @@ -109,7 +109,7 @@
context 'when change column (no change collation)' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :bigint, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "club_id", null: false, unsigned: true
t.string "string", null: false, collation: "ascii_bin"
Expand Down
6 changes: 3 additions & 3 deletions spec/mysql/dump/dump_class_method_spec.rb
Expand Up @@ -7,12 +7,12 @@

it {
expect(subject.dump(conn_spec, dump_without_table_options: true)).to match_fuzzy erbh(<<-ERB)
create_table "clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
create_table "clubs", id: { type: :integer, unsigned: true }, force: :cascade do |t|
t.string "name", default: "", null: false
t.index ["name"], name: "idx_name", unique: true
end
create_table "departments", primary_key: "dept_no", <%= i cond(">= 6.1", { id: { type: :string, limit: 4 } }, { id: :string, limit: 4 }) %>, force: :cascade do |t|
create_table "departments", primary_key: "dept_no", id: { type: :string, limit: 4 }, force: :cascade do |t|
t.string "dept_name", limit: 40, null: false
t.index ["dept_name"], name: "dept_name", unique: true
end
Expand All @@ -35,7 +35,7 @@
t.index ["emp_no"], name: "emp_no"
end
create_table "employee_clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true }}) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :integer, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false, unsigned: true
t.integer "club_id", null: false, unsigned: true
t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
Expand Down
6 changes: 3 additions & 3 deletions spec/mysql/dump/dump_spec.rb
Expand Up @@ -7,12 +7,12 @@

it {
expect(subject.dump).to match_fuzzy erbh(<<-ERB)
create_table "clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
create_table "clubs", id: { type: :integer, unsigned: true }, force: :cascade do |t|
t.string "name", default: "", null: false
t.index ["name"], name: "idx_name", unique: true
end
create_table "departments", primary_key: "dept_no", <%= i cond(">= 6.1", { id: { type: :string, limit: 4 } }, { id: :string, limit: 4 }) %>, force: :cascade do |t|
create_table "departments", primary_key: "dept_no", id: { type: :string, limit: 4 }, force: :cascade do |t|
t.string "dept_name", limit: 40, null: false
t.index ["dept_name"], name: "dept_name", unique: true
end
Expand All @@ -35,7 +35,7 @@
t.index ["emp_no"], name: "emp_no"
end
create_table "employee_clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
create_table "employee_clubs", id: { type: :integer, unsigned: true }, force: :cascade do |t|
t.integer "emp_no", null: false, unsigned: true
t.integer "club_id", null: false, unsigned: true
t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
Expand Down
2 changes: 1 addition & 1 deletion spec/mysql/dump/dump_unknown_column_type_spec.rb
Expand Up @@ -7,7 +7,7 @@

it {
expect(subject.dump).to match_fuzzy erbh(<<-ERB)
create_table "clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
create_table "clubs", id: { type: :integer, unsigned: true }, force: :cascade do |t|
t.string "name", default: "", null: false
t.index ["name"], name: "idx_name", unique: true
end
Expand Down
2 changes: 1 addition & 1 deletion spec/mysql/dump/dump_without_table_options_spec.rb
Expand Up @@ -15,7 +15,7 @@
context 'when without table options' do
let(:expected_dsl) do
erbh(<<-ERB)
create_table "books", <%= i cond('>= 6.1', { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
create_table "books", id: { type: :bigint, unsigned: true }, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
t.string "title", null: false
t.integer "author_id", null: false
t.datetime "created_at"
Expand Down
14 changes: 7 additions & 7 deletions spec/mysql/fk/migrate_create_fk_spec.rb
Expand Up @@ -254,10 +254,10 @@
context 'when create fk with first key of multiple column indexes for its column' do
let(:dsl) do
erbh(<<-ERB, utf8: condition(:mysql80) ? 'utf8mb3' : 'utf8')
create_table "parent", id: :integer, force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "parent", id: :integer, force: :cascade, charset: "<%= @utf8 %>" do |t|
end
create_table "child", force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "child", force: :cascade, charset: "<%= @utf8 %>" do |t|
t.integer "parent_id"
t.string "name"
t.index ["parent_id", "name"], name: "par_id"
Expand All @@ -279,10 +279,10 @@
context 'when create fk on the primary key' do
let(:dsl) do
erbh(<<-ERB, utf8: condition(:mysql80) ? 'utf8mb3' : 'utf8')
create_table "users", force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "users", force: :cascade, charset: "<%= @utf8 %>" do |t|
end
create_table "icons", primary_key: "user_id", force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "icons", primary_key: "user_id", force: :cascade, charset: "<%= @utf8 %>" do |t|
end
add_foreign_key "icons", "users", name: "fk_icons_users"
ERB
Expand All @@ -302,13 +302,13 @@
context 'when create fk on the first primary key' do
let(:dsl) do
erbh(<<-ERB, utf8: condition(:mysql80) ? 'utf8mb3' : 'utf8')
create_table "users", id: :integer, force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "users", id: :integer, force: :cascade, charset: "<%= @utf8 %>" do |t|
end
create_table "employee", id: :integer, force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "employee", id: :integer, force: :cascade, charset: "<%= @utf8 %>" do |t|
end
create_table "icons", primary_key: ["user_id", "employee_id"], force: :cascade, <%= i cond('>= 6.1', { charset: @utf8 }, { options: "ENGINE=InnoDB DEFAULT CHARSET=\#{@utf8}" }) %> do |t|
create_table "icons", primary_key: ["user_id", "employee_id"], force: :cascade, charset: "<%= @utf8 %>" do |t|
t.integer "user_id", null: false
t.integer "employee_id", null: false
end
Expand Down
2 changes: 1 addition & 1 deletion spec/mysql/migrate/migrate_add_check_constraint_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Ridgepole::Client#diff -> migrate', condition: [['>= 6.1', :mysql80]] do
describe 'Ridgepole::Client#diff -> migrate', condition: [[:mysql80]] do
context 'when add check constraint' do
let(:actual_dsl) do
erbh(<<-ERB)
Expand Down
2 changes: 1 addition & 1 deletion spec/mysql/migrate/migrate_change_check_constraint_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Ridgepole::Client#diff -> migrate', condition: [['>= 6.1', :mysql80]] do
describe 'Ridgepole::Client#diff -> migrate', condition: [[:mysql80]] do
context 'when change check constraint' do
let(:actual_dsl) do
erbh(<<-ERB)
Expand Down
39 changes: 4 additions & 35 deletions spec/mysql/migrate/migrate_change_column8_spec.rb
Expand Up @@ -15,7 +15,7 @@

let(:actual_dsl) do
erbh(<<-ERB)
create_table "employees", primary_key: "emp_no", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' }) %> do |t|
create_table "employees", primary_key: "emp_no", force: :cascade, charset: 'utf8' do |t|
end
ERB
end
Expand All @@ -27,38 +27,7 @@
ERB
end

context 'when change options (no change)', condition: '< 6.1' do
let(:table_options) { "ENGINE=InnoDB DEFAULT CHARSET=#{condition(:mysql80) ? 'utf8mb3' : 'utf8'}" }

it {
expect(Ridgepole::Logger.instance).to_not receive(:verbose_info).with(warning_regexp)
delta = subject.diff(expected_dsl)
expect(delta.differ?).to be_falsey
}
end

context 'when change options (change)', condition: '< 6.1' do
let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4' }

it {
expect(Ridgepole::Logger.instance).to receive(:verbose_info).with(warning_regexp)
delta = subject.diff(expected_dsl)
expect(delta.differ?).to be_falsey
}
end

context 'when dump_without_table_options => true', condition: '< 6.1' do
let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4' }
let(:dump_without_table_options) { true }

it {
expect(Ridgepole::Logger.instance).to_not receive(:verbose_info).with(warning_regexp)
delta = subject.diff(expected_dsl)
expect(delta.differ?).to be_falsey
}
end

context 'when change options (no change)', condition: '>= 6.1' do
context 'when change options (no change)' do
let(:table_hash_options) { { charset: condition(:mysql80) ? 'utf8mb3' : 'utf8' } }

it {
Expand All @@ -68,7 +37,7 @@
}
end

context 'when change options (change)', condition: '>= 6.1' do
context 'when change options (change)' do
let(:table_hash_options) { { charset: 'utf8mb4' } }

it {
Expand All @@ -78,7 +47,7 @@
}
end

context 'when dump_without_table_options => true', condition: '>= 6.1' do
context 'when dump_without_table_options => true' do
let(:table_hash_options) { { charset: 'utf8mb4' } }
let(:dump_without_table_options) { true }

Expand Down
11 changes: 0 additions & 11 deletions spec/mysql/migrate/migrate_change_index_spec.rb
Expand Up @@ -220,16 +220,5 @@
end
RUBY
}

# duplicated index checker is deleted in 6.1
# https://github.com/rails/rails/commit/edb23791d2ee9df89c5a4f24d72940ff8eaec8fc#diff-5a1c923abf3a794dbc133959167f794b2479ea8bcd0b1deda7766c22f05e8dfeL1198
it 'detects duplicated index', condition: '< 6.1' do
delta = client(bulk_change: true).diff(expected_dsl)

# XXX: Can not add an index of the same name
expect do
delta.migrate
end.to raise_error(/Index name 'emp_no' on table 'dept_emp' already exists/)
end
end
end

0 comments on commit 2509abc

Please sign in to comment.