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

SchemaDumper adds materialized view destination #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 5 additions & 4 deletions lib/clickhouse-activerecord/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def table(table, stream)
# super(table.gsub(/^\.inner\./, ''), stream)

# detect view table
match = sql.match(/^CREATE\s+(MATERIALIZED\s+)?VIEW/)
view_match = sql.match(/^CREATE\s+(MATERIALIZED\s+)?VIEW\s+\S+\s+(TO (\S+))?/)
end

# Copy from original dumper
Expand All @@ -50,8 +50,9 @@ def table(table, stream)

unless simple
# Add materialize flag
tbl.print ', view: true' if match
tbl.print ', materialized: true' if match && match[1].presence
tbl.print ', view: true' if view_match
tbl.print ', materialized: true' if view_match && view_match[1].presence
tbl.print ", to: \"#{view_match[3]}\"" if view_match && view_match[3].presence
end

if (id = columns.detect { |c| c.name == 'id' })
Expand All @@ -75,7 +76,7 @@ def table(table, stream)
tbl.puts ", force: :cascade do |t|"

# then dump all non-primary key columns
if simple || !match
if simple || !view_match
columns.each do |column|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
next if column.name == pk
Expand Down
Loading