-
Notifications
You must be signed in to change notification settings - Fork 60
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 Support for Check Constraint - Backend code changes #945
base: master
Are you sure you want to change the base?
Add Support for Check Constraint - Backend code changes #945
Conversation
Backend Support for Check Constraint
oldName := conv.SrcSchema[tableId].ColDefs[colId].Name | ||
|
||
for i := range conv.SpSchema[tableId].CheckConstraints { | ||
originalString := conv.SpSchema[tableId].CheckConstraints[i].Expr |
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.
What if there were two columns id_name and id. id gets updated to id2, this code will cause errors
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.
added regular expression to match the exact column name.
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.
please add test cases for this flow.
There are two things missing in this PR:
|
// getQuery returns the appropriate SQL query based on the existence of CHECK_CONSTRAINTS. | ||
func (isi InfoSchemaImpl) getQuery(tableExists bool) string { | ||
if tableExists { | ||
return `SELECT k.COLUMN_NAME, t.CONSTRAINT_TYPE, COALESCE(c.CHECK_CLAUSE, '') AS CHECK_CLAUSE |
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.
do we need this fork in the logic here ? The query would return empty in case the table does not exist.
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 tried multiple iterations of the query, it was failing on the older versions
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.
Can you add a comment - which versions of MySQL go in which flow ? This is not clear from the code.
…nstraint name is empty
Can you please update the PR description with what is being done, and make it it a regular PR from draft ? |
switch constraintType { | ||
case "PRIMARY KEY": | ||
*primaryKeys = append(*primaryKeys, col) | ||
case "CHECK": |
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.
can you please use the full name here ? "CHECK" is not very clear.
@@ -103,14 +103,16 @@ var PGSQL_TO_STANDARD_TYPE_TYPEMAP = map[string]string{ | |||
|
|||
// PGDialect keyword list | |||
// Assumption is that this list PGSQL dialect uses the same keywords | |||
var PGSQL_RESERVED_KEYWORD_LIST = []string{"ALL", "ANALYSE", "ANALYZE", "AND", "ANY", "ARRAY", "AS", "ASC", "ASYMMETRIC", "AUTHORIZATION", "BETWEEN", "BIGINT", "BINARY", "BIT", "BOOLEAN", "BOTH", "CASE", "CAST", | |||
var PGSQL_RESERVED_KEYWORD_LIST = []string{ |
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.
seems like some whitespaces are added here, can you revert this ?
|
||
func isCheckConstraintsNameExist(spcks []ddl.CheckConstraint, targetName string) bool { |
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.
nit: doesCheckConstraintNameExist
oldName := conv.SrcSchema[tableId].ColDefs[colId].Name | ||
|
||
for i := range conv.SpSchema[tableId].CheckConstraints { | ||
originalString := conv.SpSchema[tableId].CheckConstraints[i].Expr |
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.
please add test cases for this flow.
Backend Support for Check Constraint
Fixes #<issue_number_goes_here>
Backend code changes to support CHECK CONSTRAINTS