-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server/customer: harden the rules for linking customers with users
- Loading branch information
1 parent
886e814
commit 2700bf3
Showing
8 changed files
with
104 additions
and
24 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
server/migrations/versions/2025-01-02-1656_make_usercustomer_customer_id_unique.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Make UserCustomer.customer_id unique | ||
Revision ID: 58d5e316549f | ||
Revises: 6a6e872cbea5 | ||
Create Date: 2025-01-02 16:56:16.433658 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# Polar Custom Imports | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "58d5e316549f" | ||
down_revision = "6a6e872cbea5" | ||
branch_labels: tuple[str] | None = None | ||
depends_on: tuple[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint( | ||
"user_customers_user_id_customer_id_key", "user_customers", type_="unique" | ||
) | ||
op.create_unique_constraint( | ||
op.f("user_customers_customer_id_key"), "user_customers", ["customer_id"] | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint( | ||
op.f("user_customers_customer_id_key"), "user_customers", type_="unique" | ||
) | ||
op.create_unique_constraint( | ||
"user_customers_user_id_customer_id_key", | ||
"user_customers", | ||
["user_id", "customer_id"], | ||
) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters