-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add premium tiers table #1684
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
backend/pkg/commons/db/migrations/postgres/20250819120437_premium_tiers.sql
This file contains hidden or 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,53 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| -- create enum type for tier_name | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'tier_enum') THEN | ||
| CREATE TYPE tier_enum AS ENUM ('FREE', 'HOBBYIST', 'BUSINESS', 'SCALE'); | ||
| END IF; | ||
| END$$; | ||
|
|
||
| -- create enum type for version | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'subscription_version_enum') THEN | ||
| CREATE TYPE subscription_version_enum AS ENUM ('stripe_v3', 'stripe_legacy'); | ||
| END IF; | ||
| END$$; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS subscription_tiers ( | ||
| price_id VARCHAR(255) NOT NULL, | ||
| tier_name tier_enum NOT NULL, | ||
| version subscription_version_enum NOT NULL, | ||
| PRIMARY KEY (price_id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The primary key should be tier_name, not price_id, right? Otherwise it could be possible to accidentally add in multiple tiers with the same name but different price_ids, and the code will break. |
||
| ); | ||
|
|
||
| COMMENT ON COLUMN subscription_tiers.price_id IS 'Unique subscription price identifier (e.g. Stripe price ID)'; | ||
| COMMENT ON COLUMN subscription_tiers.tier_name IS 'Our subscription tier this price belongs to. Valid values: FREE, HOBBYIST, BUSINESS, SCALE'; | ||
| COMMENT ON COLUMN subscription_tiers.version IS 'Integration version. Valid values: stripe_v3 (current) or stripe_legacy (v1).'; | ||
|
|
||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
|
|
||
| DROP TABLE IF EXISTS subscription_tiers; | ||
|
|
||
| -- drop enums if no longer used | ||
| DO $$ | ||
| BEGIN | ||
| IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'tier_enum') THEN | ||
| DROP TYPE tier_enum; | ||
| END IF; | ||
| END$$; | ||
|
|
||
| DO $$ | ||
| BEGIN | ||
| IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'subscription_version_enum') THEN | ||
| DROP TYPE subscription_version_enum; | ||
| END IF; | ||
| END$$; | ||
|
|
||
| -- +goose StatementEnd | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Call this explicitly
stripe_*, because then whoever sees this variable is going to know exactly where it comes from. Otherwise, they have to guess.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.
Also, I thought we were going to rename this to
stripe_subscription_id. Are we surepriceis right?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.
Yeah it was my bad, I confused subscription id and price id in the call but checked after to make sure I get this right. Price ID is the correct one (identifying what the user purchased, subscription is is just the id of that specific user subscription).
As for the stripe prefix. In theory we could use this table for a generic implementation. It's just a mapping between any third party identifier of a thing a user can by to our local reference for it. That's why I'd argue against tying it to strongly to stripe