Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format the version schema like rails does since 5.2 #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/merge_db_schema/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ def main(argv)

def update_version(path, version)
text = path.read
text[RE_DEFINE, 1] = version.to_s
text[RE_DEFINE, 1] = formatted_version(version)
path.write(text)
end

def formatted_version(version)
stringified = version.to_s
return stringified unless stringified.length == 14
stringified.insert(4, "_").insert(7, "_").insert(10, "_")
end

end
end
end
2 changes: 1 addition & 1 deletion test/data/simple/expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170628094212) do
ActiveRecord::Schema.define(version: 2017_06_28_094212) do

create_table "articles", force: :cascade do |t|
t.string "title"
Expand Down
4 changes: 2 additions & 2 deletions test/test_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def test_integration_conflict
sh! 'git', 'branch', 'change2-original'
ex = assert_raises{sh! 'git', 'merge', '--no-edit', 'change1'}
assert ex.is_a?(CommandExecutionError)
assert_match(/version: 20170701093311/, db_schema.read)
assert_match(/version: 2017_07_01_093311/, db_schema.read)
sh! 'git', 'merge', '--abort'

sh! 'git', 'checkout', 'change1'
ex = assert_raises{sh! 'git', 'merge', '--no-edit', 'change2-original'}
assert ex.is_a?(CommandExecutionError)
assert_match(/version: 20170701093311/, db_schema.read)
assert_match(/version: 2017_07_01_093311/, db_schema.read)
end
ensure
ENV['PATH'] = original_path
Expand Down
4 changes: 2 additions & 2 deletions test/test_main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def assert_merged(current, current_original, expected)
assert current.read != current_original.read
assert_equal current.read, expected.read

assert_match(/version: 20170628094212/, current.read)
assert_match(/version: 2017_06_28_094212/, current.read)
refute current.read.match(/\={7,}/)
refute current.read.match(/\<{7,}/)
refute current.read.match(/\>{7,}/)
Expand All @@ -87,7 +87,7 @@ def assert_merged(current, current_original, expected)
def assert_conflict(current, current_original, expected)
assert current.read != current_original.read

assert_match(/version: 20170701093311/, current.read)
assert_match(/version: 2017_07_01_093311/, current.read)
assert current.read.match(/\={7,}/)
assert current.read.match(/\<{7,}/)
assert current.read.match(/\>{7,}/)
Expand Down