Skip to content

Commit

Permalink
Merge 984e2d6 into f6680a7
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Dec 18, 2021
2 parents f6680a7 + 984e2d6 commit adb0f0b
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 85 deletions.
4 changes: 4 additions & 0 deletions Appraisals
Expand Up @@ -16,3 +16,7 @@ end
appraise 'activerecord-6.1' do
gem 'activerecord', '~> 6.1.0'
end

appraise 'activerecord-7.0' do
gem 'activerecord', '~> 7.0.0'
end
7 changes: 7 additions & 0 deletions gemfiles/activerecord_7.0.gemfile
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 7.0.0"

gemspec path: "../"
3 changes: 3 additions & 0 deletions lib/ridgepole/diff.rb
Expand Up @@ -419,6 +419,9 @@ def normalize_column_options!(attrs, primary_key = false)
opts[:limit] = 4_294_967_295
end
end

# Workaround for Active Record 7.0
opts.delete(:precision) if attrs[:type] == :datetime && opts[:precision].nil?
end
end

Expand Down
5 changes: 4 additions & 1 deletion lib/ridgepole/execute_expander.rb
Expand Up @@ -13,7 +13,10 @@ def respond_to_missing?(_symbol, _include_private)
end

module ConnectionAdapterExt
def execute(sql, name = nil)
def execute(*args)
sql = args.fetch(0)
name = args[1]

if Ridgepole::ExecuteExpander.noop
if (callback = Ridgepole::ExecuteExpander.callback)
sql = append_alter_extra(sql)
Expand Down
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.2.7') # rubocop:disable Gemspec/RequiredRubyVersion

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

spec.add_development_dependency 'appraisal', '>= 2.2.0'
Expand Down
16 changes: 8 additions & 8 deletions spec/mysql/bigint_pk/int_pk_spec.rb
Expand Up @@ -3,14 +3,14 @@
describe 'Ridgepole::Client (with integer pk)' do
context 'when with id:integer' do
let(:dsl) do
<<-RUBY
erbh(<<-ERB)
create_table "books", id: :integer, force: :cascade do |t|
t.string "title", null: false
t.integer "author_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>
end
RUBY
ERB
end

subject { client }
Expand All @@ -25,14 +25,14 @@

context 'when without id:integer' do
let(:dsl) do
<<-RUBY
erbh(<<-ERB)
create_table "books", force: :cascade do |t|
t.string "title", null: false
t.integer "author_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>
end
RUBY
ERB
end

subject { client }
Expand Down
30 changes: 15 additions & 15 deletions spec/mysql/default_lambda/default_lambda_spec.rb
Expand Up @@ -5,11 +5,11 @@
subject { client }

it do
delta = subject.diff(<<-RUBY)
delta = subject.diff(erbh(<<-ERB))
create_table "foos", force: :cascade do |t|
t.datetime "bar", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "bar", <%= i cond(">= 7.0", { precision: nil }) %>, default: -> { "CURRENT_TIMESTAMP" }, null: false
end
RUBY
ERB

expect(delta.differ?).to be_truthy
delta.migrate
Expand All @@ -24,11 +24,11 @@

context 'when there is no difference' do
let(:dsl) do
<<-RUBY
erbh(<<-ERB)
create_table "foos", force: :cascade do |t|
t.datetime "bar", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "bar", <%= i cond(">= 7.0", { precision: nil }) %>, default: -> { "CURRENT_TIMESTAMP" }, null: false
end
RUBY
ERB
end

subject { client }
Expand All @@ -47,11 +47,11 @@
subject { client }

before do
subject.diff(<<-RUBY).migrate
subject.diff(erbh(<<-ERB)).migrate
create_table "foos", force: :cascade do |t|
t.datetime "bar", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "bar", <%= i cond(">= 7.0", { precision: nil }) %>, default: -> { "CURRENT_TIMESTAMP" }, null: false
end
RUBY
ERB
end

it do
Expand Down Expand Up @@ -113,12 +113,12 @@
end

it do
delta = subject.diff(<<-RUBY)
delta = subject.diff(erbh(<<-ERB))
create_table "foos", force: :cascade do |t|
t.datetime "bar", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "bar", <%= i cond(">= 7.0", { precision: nil }) %>, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.integer "zoo"
end
RUBY
ERB

expect(delta.differ?).to be_truthy
delta.migrate
Expand All @@ -136,12 +136,12 @@
subject { client }

before do
subject.diff(<<-RUBY).migrate
subject.diff(erbh(<<-ERB)).migrate
create_table "foos", force: :cascade do |t|
t.datetime "bar", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "bar", <%= i cond(">= 7.0", { precision: nil }) %>, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.integer "zoo"
end
RUBY
ERB
end

it do
Expand Down
4 changes: 2 additions & 2 deletions spec/mysql/dump/dump_without_table_options_spec.rb
Expand Up @@ -18,8 +18,8 @@
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|
t.string "title", null: false
t.integer "author_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>
end
ERB
end
Expand Down
32 changes: 16 additions & 16 deletions spec/mysql/fk/migrate_fk_with_column_spec.rb
Expand Up @@ -7,16 +7,16 @@
create_table "direct_messages", id: :integer, force: :cascade do |t|
t.integer "sender_id"
t.integer "reciever_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.index ["reciever_id"], name: "index_direct_messages_on_reciever_id"
t.index ["sender_id"], name: "index_direct_messages_on_sender_id"
end
create_table "users", id: :integer, force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
end
ERB
end
Expand Down Expand Up @@ -65,16 +65,16 @@
create_table "direct_messages", id: :integer, force: :cascade do |t|
t.integer "sender_id"
t.integer "reciever_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.index ["reciever_id"], name: "index_direct_messages_on_reciever_id"
t.index ["sender_id"], name: "index_direct_messages_on_sender_id"
end
create_table "users", id: :integer, force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
end
ERB
end
Expand Down Expand Up @@ -109,16 +109,16 @@
create_table "direct_messages", id: :integer, force: :cascade do |t|
t.integer "sender_id"
t.integer "reciever_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.index ["reciever_id"], name: "index_direct_messages_on_reciever_id"
t.index ["sender_id"], name: "index_direct_messages_on_sender_id"
end
create_table "users", id: :integer, force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
end
add_foreign_key "direct_messages", "users", column: "reciever_id", on_delete: :cascade
Expand All @@ -131,16 +131,16 @@
create_table "direct_messages", id: :integer, force: :cascade do |t|
t.integer "sender_id"
t.integer "reciever_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.index ["reciever_id"], name: "index_direct_messages_on_reciever_id"
t.index ["sender_id"], name: "index_direct_messages_on_sender_id"
end
create_table "users", id: :integer, force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
end
add_foreign_key "direct_messages", "users", column: "reciever_id"
Expand Down
12 changes: 6 additions & 6 deletions spec/mysql/migrate/migrate_change_column3_spec.rb
Expand Up @@ -3,17 +3,17 @@
describe 'Ridgepole::Client#diff -> migrate' do
context 'when use timestamps (no change)' do
let(:actual_dsl) do
<<-RUBY
erbh(<<-ERB)
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
t.date "birth_date", null: false
t.string "first_name", limit: 14, null: false
t.string "last_name", limit: 16, null: false
t.string "gender", limit: 1, null: false
t.date "hire_date", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: nil }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: nil }) %>, null: false
end
RUBY
ERB
end

let(:expected_dsl) do
Expand Down Expand Up @@ -72,8 +72,8 @@
t.string "last_name", limit: 16, null: false
t.string "gender", limit: 1, null: false
t.date "hire_date", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
end
ERB
end
Expand Down
16 changes: 8 additions & 8 deletions spec/mysql/migrate/migrate_change_column4_spec.rb
Expand Up @@ -18,18 +18,18 @@
end

let(:expected_dsl) do
<<-RUBY
erbh(<<-ERB)
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
t.date "birth_date", null: false
t.string "first_name", limit: 14, null: false
t.string "last_name", limit: 16, null: false
t.string "gender", limit: 1, null: false
t.date "hire_date", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.boolean "registered"
end
RUBY
ERB
end

before { subject.diff(actual_dsl).migrate }
Expand Down Expand Up @@ -58,18 +58,18 @@
end

let(:expected_dsl) do
<<-RUBY
erbh(<<-ERB)
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
t.date "birth_date", null: false
t.string "first_name", limit: 14, null: false
t.string "last_name", limit: 16, null: false
t.string "gender", limit: 1, null: false
t.date "hire_date", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.datetime "updated_at", <%= i cond(">= 7.0", { precision: 6 }) %>, null: false
t.boolean "registered", limit: 1
end
RUBY
ERB
end

before { subject.diff(actual_dsl).migrate }
Expand Down

0 comments on commit adb0f0b

Please sign in to comment.