Skip to content

Commit

Permalink
Fixed issue with alphabetize_schema and virtual columns - fixes #276
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 9, 2024
1 parent 516be69 commit 9605653
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1 (unreleased)

- Fixed issue with `alphabetize_schema` and virtual columns

## 2.0.0 (2024-06-28)

- Improved install generator for Trilogy
Expand Down
11 changes: 11 additions & 0 deletions lib/strong_migrations/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ def initialize(connection)
def columns(*args, **options)
@connection.columns(*args, **options).sort_by(&:name)
end

# forward private methods with send
# method_missing cannot tell how method was called
# this is not ideal, but other solutions have drawbacks
def send(name, ...)
if respond_to?(name, true)
super
else
@connection.send(name, ...)
end
end
end
end
12 changes: 12 additions & 0 deletions test/alphabetize_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def test_enabled
assert_match expected_columns, schema
end

def test_virtual_column
skip unless mysql? || mariadb?

migrate AddColumnGeneratedVirtual
schema =
StrongMigrations.stub(:alphabetize_schema, true) do
dump_schema
end
migrate AddColumnGeneratedVirtual, direction: :down
assert_match "t.virtual", schema
end

private

def dump_schema
Expand Down

0 comments on commit 9605653

Please sign in to comment.