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

Improve formatting of dumped schema #436

Open
wants to merge 1 commit into
base: main
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/scenic/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ def views(stream)

dumpable_views_in_database.each do |view|
stream.puts(view.to_schema)
indexes(view.name, stream)

index_stream = StringIO.new
indexes(view.name, index_stream)

if index_stream.string.present?
stream.puts
stream.puts(index_stream.string)
end
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/scenic/view.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "niceql"

module Scenic
# The in-memory representation of a view definition.
#
Expand Down Expand Up @@ -46,11 +48,19 @@ def to_schema

<<-DEFINITION
create_view #{UnaffixedName.for(name).inspect}, #{materialized_option}sql_definition: <<-\SQL
#{escaped_definition.indent(2)}
#{formatted_definition.indent(2)}
SQL
DEFINITION
end

def formatted_definition
colorize = false

Niceql::Prettifier
.prettify_sql(escaped_definition, colorize)
.chomp(";")
end

def escaped_definition
definition.gsub("\\", "\\\\\\")
end
Expand Down
1 change: 1 addition & 0 deletions scenic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "activerecord", ">= 4.0.0"
spec.add_dependency "railties", ">= 4.0.0"
spec.add_dependency "niceql", ">= 0.6.1"

spec.required_ruby_version = ">= 2.3.0"
end
Loading