Multiple Unique Constraints with auto migrations#582
Multiple Unique Constraints with auto migrations#582northpowered wants to merge 6 commits intopiccolo-orm:masterfrom
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.
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.
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] |
piccolo/query/methods/alter.py
Outdated
| tablename = self.table._meta.tablename | ||
| return f"{tablename}_{column_name}_fk" | ||
|
|
||
| def add_unique_constraint(self, constraint_name: str, columns: list[str]): |
|
@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