-
Notifications
You must be signed in to change notification settings - Fork 312
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
add check constraints for MySQL #621
add check constraints for MySQL #621
Conversation
Doing an If it needs to be compliant w/ >= 8.0.16 I can change it to be a |
If wanted I can take a crack at adding the check constraint migrator implementation for MySQL as well, or put it in another PR, now that 8.0.19 supports check constraints outside table definitions |
@petermueller I think it is fine to do it all as part of this PR. |
@josevalim updated,
Questions:
There's support for enabling/disabling Postgres supports the equivalent
I don't know what people's appetite is for having ecto manage stored procedures :-/ |
|
I should clarify, I don't see anywhere that the PG adapter connection does I see in the reference I'm not sure this is really worth it right now. I can add to the docs for the
😅 I kind of wanted to see if I could do it with a procedure. The tests I added seem to work just though. Probably could use a test with multiple migrations to know the delimiter doesn't mess things up. def execute_ddl({:drop_if_exists, %Constraint{} = constraint, :restrict}) do
table_name = [?', to_string(constraint.table), ?']
constraint_name = [?', to_string(constraint.name), ?']
table_schema =
if constraint.prefix do
[?', to_string(constraint.prefix), ?']
else
"DATABASE()"
end
[
["DROP PROCEDURE IF EXISTS PROC_ECTO_DROP_CONSTRAINT"],
[
"CREATE PROCEDURE PROC_ECTO_DROP_CONSTRAINT ( ",
"IN tableName VARCHAR(200), ",
"IN constraintName VARCHAR(200), ",
"IN tableSchema VARCHAR(200) ",
") ",
"BEGIN ",
"IF EXISTS ( ",
"SELECT * FROM `information_schema`.`table_constraints` ",
"WHERE table_schema = tableSchema ",
"AND table_name = tableName ",
"AND constraint_name = constraintName ",
"AND constraint_type in ('UNIQUE', 'FOREIGN KEY', 'CHECK')) ",
"THEN ",
"SET @query = CONCAT('ALTER TABLE ', tableName, ' DROP CONSTRAINT ', constraintName, ';'); ",
"PREPARE stmt FROM @query; ",
"EXECUTE stmt; ",
"DEALLOCATE PREPARE stmt; ",
"END IF; ",
"END"
],
[
"CALL PROC_ECTO_DROP_CONSTRAINT(",
table_name,
", ",
constraint_name,
", ",
table_schema,
")"
],
["DROP PROCEDURE PROC_ECTO_DROP_CONSTRAINT"]
]
end Ok, Let me stop increasing scope and get to just finishing the docs changes 😅 |
Agreed the changes are out of scope. Let's change the docs and I will do another review soon! |
Updated 🙂 Let me know if you prefer a different format or different information |
Thanks 😊 Once the myxql changes are released, should I update this PR to point to them? |
I released v0.7.1, so we can depend on it! |
Cool. I will update push in a few hours. Just 0.7, or just unlock so only the lockfile changes? |
Update mix.exs please! |
Should be good to go. I also added a tag so 5.7 shouldn't try to run them |
thanks very much |
constraint/2
andconstraint/3
support for adding and dropping check constraints in MySQL migrationsER_CHECK_CONSTRAINT_VIOLATED
MySQL server error number, introduced in 8.0.16https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_check_constraint_violated
relies on elixir-ecto/myxql#187