2017-08-13 13:02:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-28 17:12:48 +00:00
|
|
|
require "bundler/inline"
|
2016-09-15 11:28:12 +00:00
|
|
|
|
|
|
|
gemfile(true) do
|
|
|
|
source "https://rubygems.org"
|
2017-09-27 08:55:43 +00:00
|
|
|
|
2017-09-26 21:02:11 +00:00
|
|
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
2017-09-27 08:55:43 +00:00
|
|
|
|
2016-09-15 11:28:12 +00:00
|
|
|
# Activate the gem you are reporting the issue against.
|
2020-12-11 07:45:53 +00:00
|
|
|
gem "activerecord", "6.1.0"
|
2019-04-25 10:07:09 +00:00
|
|
|
gem "sqlite3"
|
2016-09-15 11:28:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
require "active_record"
|
|
|
|
require "minitest/autorun"
|
|
|
|
require "logger"
|
|
|
|
|
|
|
|
# This connection will do for database-independent bug reports.
|
|
|
|
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
|
|
|
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
|
|
|
|
|
|
ActiveRecord::Schema.define do
|
|
|
|
create_table :payments, force: true do |t|
|
|
|
|
t.decimal :amount, precision: 10, scale: 0, default: 0, null: false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Payment < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
|
2021-05-02 12:17:04 +00:00
|
|
|
class ChangeAmountToAddScale < ActiveRecord::Migration[6.1]
|
2016-09-15 11:28:12 +00:00
|
|
|
def change
|
|
|
|
reversible do |dir|
|
|
|
|
dir.up do
|
|
|
|
change_column :payments, :amount, :decimal, precision: 10, scale: 2, default: 0, null: false
|
|
|
|
end
|
|
|
|
|
|
|
|
dir.down do
|
|
|
|
change_column :payments, :amount, :decimal, precision: 10, scale: 0, default: 0, null: false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BugTest < Minitest::Test
|
|
|
|
def test_migration_up
|
2017-06-21 23:08:45 +00:00
|
|
|
ChangeAmountToAddScale.migrate(:up)
|
2016-09-15 11:28:12 +00:00
|
|
|
Payment.reset_column_information
|
|
|
|
|
|
|
|
assert_equal "decimal(10,2)", Payment.columns.last.sql_type
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_migration_down
|
2017-06-21 23:08:45 +00:00
|
|
|
ChangeAmountToAddScale.migrate(:down)
|
2016-09-15 11:28:12 +00:00
|
|
|
Payment.reset_column_information
|
|
|
|
|
|
|
|
assert_equal "decimal(10,0)", Payment.columns.last.sql_type
|
|
|
|
end
|
2016-10-29 03:05:58 +00:00
|
|
|
end
|