-
Notifications
You must be signed in to change notification settings - Fork 11
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
[feature] Added constraint support in migrations #108
[feature] Added constraint support in migrations #108
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! I left some comments inline.
:create_if_not_exists -> " ADD CONSTRAINT IF NOT EXISTS " | ||
end | ||
|
||
constraint_expr = constraint |> constraint_expr() |> Enum.join("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need to Enum.join
since we are returning an iolist anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed Enum.join as removed constraint_expr/1
|
||
defp constraint_expr(%Constraint{check: check, validate: true, comment: comment}) | ||
when is_binary(check) and is_binary(comment) do | ||
raise "Clickhouse adapter does not support comments on check constraints" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably put all these checks into a single function clause like this
defp constraint_expr(%Constraint{} = constraint) do
if constraint.comment do
raise "Clickhouse adapter does not support comments on check constraints"
end
unless constraint.validate do
raise ...
end
# etc. checks for other unsupported fields / options
[@conn.quote_name(constraint.name), " CHECK (", constraint.check, ?)]
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case maybe it's more appropriate to move them inside execute_ddl/1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️❤️❤️
@senconscious thank you! I released these changes as |
end | ||
|
||
unless constraint.validate do | ||
raise "Clickhouse adapter does not support check constraints without validation on creation" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been refactoring migrations and noticed
Constraint check will not be executed on existing data if it was added.
on https://clickhouse.com/docs/en/sql-reference/statements/alter/constraint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it mean that we should have the opposite check?
if constraint.validate do
raise "ClickHouse does not support check constraints with validation on creation"
end
Hello, there was no support for constraint in create, create_if_not_exists, drop, drop_if_exists. Need to run those through execute. So I decided to contribute and add this small feature.