-
-
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/product: upgrade Stripe's products metadata
- Loading branch information
1 parent
bd5132c
commit 8c4d5ee
Showing
3 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
server/migrations/versions/2024-05-15-1206_update_stripe_s_product_metadata.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,61 @@ | ||
"""Update Stripe's product metadata | ||
Revision ID: 40f397ad512a | ||
Revises: 8ca7adb6786e | ||
Create Date: 2024-05-15 12:06:39.431048 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from polar.integrations.stripe.service import stripe as stripe_service | ||
|
||
# Polar Custom Imports | ||
from polar.kit.extensions.sqlalchemy import PostgresUUID | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "40f397ad512a" | ||
down_revision = "8ca7adb6786e" | ||
branch_labels: tuple[str] | None = None | ||
depends_on: tuple[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
connection = op.get_bind() | ||
result = connection.execute( | ||
sa.text( | ||
""" | ||
SELECT products.id, products.stripe_product_id | ||
FROM products | ||
WHERE stripe_product_id IS NOT NULL; | ||
""" | ||
) | ||
) | ||
|
||
for product_id, stripe_product_id in result: | ||
metadata = { | ||
"product_id": str(product_id), | ||
"subscription_tier_id": "", | ||
} | ||
stripe_service.update_product(stripe_product_id, metadata=metadata) | ||
|
||
|
||
def downgrade() -> None: | ||
connection = op.get_bind() | ||
result = connection.execute( | ||
sa.text( | ||
""" | ||
SELECT products.id, products.stripe_product_id | ||
FROM products | ||
WHERE stripe_product_id IS NOT NULL; | ||
""" | ||
) | ||
) | ||
|
||
for product_id, stripe_product_id in result: | ||
metadata = { | ||
"subscription_tier_id": str(product_id), | ||
"product_id": "", | ||
} | ||
stripe_service.update_product(stripe_product_id, metadata=metadata) |
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