-
Notifications
You must be signed in to change notification settings - Fork 91
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
Multiple Unique Constraints with auto migrations #582
base: master
Are you sure you want to change the base?
Multiple Unique Constraints with auto migrations #582
Conversation
@northpowered Thanks for this, it looks promising! I think the linters are currently failing because of isort. |
Mb because we are using different linters |
piccolo/columns/constraints.py
Outdated
ALTER TABLE foo_table ADD CONSTRAINT my_constraint_1 UNIQUE (foo_field, bar_field); | ||
ALTER TABLE foo_table DROP IF EXIST CONSTRAINT my_constraint_1; | ||
""" | ||
def __init__(self, unique_columns: list[str]) -> None: |
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 think this is why the tests are failing.
We can't use this newer syntax yet, because we're keeping backwards compatibility with Python 3.7.
So it'll have to be typing.List[str]
instead.
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.
Sorry, I used to Python3.10, so I forgot about older versions
piccolo/query/methods/alter.py
Outdated
__slots__ = ("constraint_name","columns") | ||
|
||
constraint_name: str | ||
columns: list[str] |
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.
Same as above -> List[str]
piccolo/query/methods/alter.py
Outdated
@@ -433,6 +446,12 @@ def _get_constraint_name(self, column: t.Union[str, ForeignKey]) -> str: | |||
tablename = self.table._meta.tablename | |||
return f"{tablename}_{column_name}_fk" | |||
|
|||
def add_unique_constraint(self, constraint_name: str, columns: list[str]): |
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.
See above.
@northpowered Sorry it has taken me so long - let's try and get these tests passing. |
@dantownsend |
Full description is in pinned issue
ADDED:
IMPORTANT!
There`re no ALTER CONSTRAINT option, but will be added soon, I hope.
For changing constraint I recommend do it with 2 migrations: DROP->CREATE