Skip to content

Commit e564ccd

Browse files
committed
Add spaces between functions and triggers in schema.rb
I've been dealing with the changes to schema_dumper in Rails 8.1 and Senic 1.9 and found that it's most common for their methods not to emit a newline after their last operation. Hence I think it's safe to assume that functions() and triggers() should emit a newline before their loops and within their loops, up to the last iteration. And, not having these functions emit a final newline holds with the pattern used by the Rails and Scenic schema_dumpers. I've tested this in my own apps with a patch on this gem and the spacing is correct with the new Rails 8.1 schema changes (and with Scenic emitting `create_view` statements before the `create_function` and `create_trigger` statements).
1 parent a58067d commit e564ccd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/fx/schema_dumper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ def tables(stream)
2020
def functions(stream)
2121
dumpable_functions_in_database = Fx.database.functions
2222

23-
dumpable_functions_in_database.each do |function|
23+
stream.puts
24+
25+
dumpable_functions_in_database.each_with_index do |function, index|
2426
stream.puts(function.to_schema)
27+
stream.puts unless index == dumpable_functions_in_database.size - 1
2528
end
26-
27-
stream.puts if dumpable_functions_in_database.any?
2829
end
2930

3031
def triggers(stream)
3132
dumpable_triggers_in_database = Fx.database.triggers
3233

33-
if dumpable_triggers_in_database.any?
34-
stream.puts
35-
end
34+
stream.puts
3635

37-
dumpable_triggers_in_database.each do |trigger|
36+
dumpable_triggers_in_database.each_with_index do |trigger, index|
3837
stream.puts(trigger.to_schema)
38+
stream.puts unless index == dumpable_triggers_in_database.size - 1
3939
end
4040
end
4141
end

0 commit comments

Comments
 (0)