-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: migrate direct subscription management to Sale, esp. in Trans…
…action
- Loading branch information
1 parent
2ab059e
commit 33a2767
Showing
27 changed files
with
680 additions
and
489 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
server/migrations/versions/2024-05-16-1358_migrate_heldbalance.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,117 @@ | ||
"""Migrate HeldBalance | ||
Revision ID: f850759b02d5 | ||
Revises: e553ec9cf929 | ||
Create Date: 2024-05-16 13:58:23.584174 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# Polar Custom Imports | ||
from polar.kit.extensions.sqlalchemy import PostgresUUID | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "f850759b02d5" | ||
down_revision = "e553ec9cf929" | ||
branch_labels: tuple[str] | None = None | ||
depends_on: tuple[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("held_balances", sa.Column("sale_id", sa.UUID(), nullable=True)) | ||
op.create_foreign_key( | ||
op.f("held_balances_sale_id_fkey"), | ||
"held_balances", | ||
"sales", | ||
["sale_id"], | ||
["id"], | ||
ondelete="set null", | ||
) | ||
|
||
op.execute( | ||
""" | ||
UPDATE held_balances | ||
SET sale_id = sales.id | ||
FROM sales | ||
JOIN subscriptions ON sales.subscription_id = subscriptions.id | ||
WHERE held_balances.subscription_id = subscriptions.id | ||
""" | ||
) | ||
|
||
op.drop_index("ix_held_balances_product_price_id", table_name="held_balances") | ||
op.drop_index("ix_held_balances_subscription_id", table_name="held_balances") | ||
op.create_index( | ||
op.f("ix_held_balances_sale_id"), "held_balances", ["sale_id"], unique=False | ||
) | ||
op.drop_constraint( | ||
"held_balances_subscription_id_fkey", "held_balances", type_="foreignkey" | ||
) | ||
op.drop_constraint( | ||
"held_balances_subscription_tier_price_id_fkey", | ||
"held_balances", | ||
type_="foreignkey", | ||
) | ||
|
||
op.drop_column("held_balances", "product_price_id") | ||
op.drop_column("held_balances", "subscription_id") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"held_balances", | ||
sa.Column("subscription_id", sa.UUID(), autoincrement=False, nullable=True), | ||
) | ||
op.add_column( | ||
"held_balances", | ||
sa.Column("product_price_id", sa.UUID(), autoincrement=False, nullable=True), | ||
) | ||
op.create_foreign_key( | ||
"held_balances_subscription_tier_price_id_fkey", | ||
"held_balances", | ||
"product_prices", | ||
["product_price_id"], | ||
["id"], | ||
ondelete="SET NULL", | ||
) | ||
op.create_foreign_key( | ||
"held_balances_subscription_id_fkey", | ||
"held_balances", | ||
"subscriptions", | ||
["subscription_id"], | ||
["id"], | ||
ondelete="SET NULL", | ||
) | ||
|
||
op.execute( | ||
""" | ||
UPDATE held_balances | ||
SET subscription_id = sales.subscription_id, | ||
product_price_id = sales.product_price_id | ||
FROM sales | ||
WHERE sales.id = held_balances.sale_id | ||
""" | ||
) | ||
|
||
op.drop_constraint( | ||
op.f("held_balances_sale_id_fkey"), "held_balances", type_="foreignkey" | ||
) | ||
op.drop_index(op.f("ix_held_balances_sale_id"), table_name="held_balances") | ||
op.create_index( | ||
"ix_held_balances_subscription_id", | ||
"held_balances", | ||
["subscription_id"], | ||
unique=False, | ||
) | ||
op.create_index( | ||
"ix_held_balances_product_price_id", | ||
"held_balances", | ||
["product_price_id"], | ||
unique=False, | ||
) | ||
op.drop_column("held_balances", "sale_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
Empty file.
Oops, something went wrong.