Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

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.

Copy link
Contributor

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 sure price is right?

Copy link
Contributor Author

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

tier_name tier_enum NOT NULL,
version subscription_version_enum NOT NULL,
PRIMARY KEY (price_id)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Loading