From 510a0871760d2629a5008b3f2e06705f4fd2c874 Mon Sep 17 00:00:00 2001 From: Chilliwiddit Date: Thu, 12 Dec 2024 13:38:03 +0530 Subject: [PATCH] Fix postgres database script --- .../api-monetization/monetizing-an-api.md | 103 ++++++++---------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/en/docs/design/api-monetization/monetizing-an-api.md b/en/docs/design/api-monetization/monetizing-an-api.md index 93acafe4bf..c0b59970fc 100644 --- a/en/docs/design/api-monetization/monetizing-an-api.md +++ b/en/docs/design/api-monetization/monetizing-an-api.md @@ -439,64 +439,51 @@ Let's use the [wso2-am-stripe-plugin](https://github.com/wso2-extensions/wso2-am === "Postgre" ``` java - CREATE SEQUENCE AM_MONETIZATION START WITH 1 INCREMENT BY 1; - CREATE TABLE IF NOT EXISTS AM_POLICY_SUBSCRIPTION ( - API_ID INTEGER NOT NULL, - TIER_NAME VARCHAR(512), - STRIPE_PRODUCT_ID VARCHAR(512), - STRIPE_PLAN_ID VARCHAR(512), - FOREIGN KEY (API_ID) REFERENCES AM_API (API_ID) ON DELETE CASCADE - ); - - CREATE SEQUENCE AM_POLICY_PLAN_MAPPING START WITH 1 INCREMENT BY 1; - CREATE TABLE IF NOT EXISTS AM_POLICY_SUBSCRIPTION ( - POLICY_ID INTEGER DEFAULT NEXTVAL('AM_POLICY_PLAN_MAPPING'), - POLICY_UUID VARCHAR(256), - PRODUCT_ID VARCHAR(512), - PLAN_ID VARCHAR(512), - FOREIGN KEY (POLICY_UUID) REFERENCES AM_POLICY_SUBSCRIPTION(UUID) - - ); - - CREATE SEQUENCE AM_MONETIZATION_PLATFORM_CUSTOMERS START WITH 1 INCREMENT BY 1; - CREATE TABLE IF NOT EXISTS AM_POLICY_SUBSCRIPTION ( - POLICY_ID INTEGER DEFAULT NEXTVAL('AM_MONETIZATION_PLATFORM_CUSTOMERS'), - ID INTEGER NOT NULL AUTO_INCREMENT, - SUBSCRIBER_ID INTEGER NOT NULL, - TENANT_ID INTEGER NOT NULL, - CUSTOMER_ID VARCHAR(256) NOT NULL, - PRIMARY KEY (ID), - FOREIGN KEY (SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON DELETE CASCADE - ); - - CREATE SEQUENCE AM_MONETIZATION_SHARED_CUSTOMERS START WITH 1 INCREMENT BY 1; - CREATE TABLE IF NOT EXISTS AM_POLICY_SUBSCRIPTION ( - POLICY_ID INTEGER DEFAULT NEXTVAL('AM_MONETIZATION_SHARED_CUSTOMERS'), - ID INTEGER NOT NULL AUTO_INCREMENT, - APPLICATION_ID INTEGER NOT NULL, - API_PROVIDER VARCHAR(256) NOT NULL, - TENANT_ID INTEGER NOT NULL, - SHARED_CUSTOMER_ID VARCHAR(256) NOT NULL, - PARENT_CUSTOMER_ID INTEGER NOT NULL, - PRIMARY KEY (ID), - FOREIGN KEY (APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) ON DELETE CASCADE, - FOREIGN KEY (PARENT_CUSTOMER_ID) REFERENCES AM_MONETIZATION_PLATFORM_CUSTOMERS(ID) ON DELETE CASCADE - ); - - CREATE SEQUENCE AM_MONETIZATION_SUBSCRIPTIONS START WITH 1 INCREMENT BY 1; - CREATE TABLE IF NOT EXISTS AM_POLICY_SUBSCRIPTION ( - POLICY_ID INTEGER DEFAULT NEXTVAL('AM_MONETIZATION_SUBSCRIPTIONS'), - ID INTEGER NOT NULL AUTO_INCREMENT, - SUBSCRIBED_APPLICATION_ID INTEGER NOT NULL, - SUBSCRIBED_API_ID INTEGER NOT NULL, - TENANT_ID INTEGER NOT NULL, - SUBSCRIPTION_ID VARCHAR(256) NOT NULL, - SHARED_CUSTOMER_ID INTEGER NOT NULL, - PRIMARY KEY (ID), - FOREIGN KEY (SUBSCRIBED_APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) ON DELETE CASCADE, - FOREIGN KEY (SUBSCRIBED_API_ID) REFERENCES AM_API(API_ID) ON DELETE CASCADE, - FOREIGN KEY (SHARED_CUSTOMER_ID) REFERENCES AM_MONETIZATION_SHARED_CUSTOMERS(ID) ON DELETE CASCADE - ); + CREATE TABLE IF NOT EXISTS AM_MONETIZATION ( + API_ID INTEGER NOT NULL, + TIER_NAME VARCHAR(512), + STRIPE_PRODUCT_ID VARCHAR(512), + STRIPE_PLAN_ID VARCHAR(512), + CONSTRAINT fk_api FOREIGN KEY (API_ID) REFERENCES AM_API (API_ID) ON DELETE CASCADE + ); + + CREATE TABLE IF NOT EXISTS AM_POLICY_PLAN_MAPPING ( + POLICY_UUID VARCHAR(256), + PRODUCT_ID VARCHAR(512), + PLAN_ID VARCHAR(512), + CONSTRAINT fk_policy FOREIGN KEY (POLICY_UUID) REFERENCES AM_POLICY_SUBSCRIPTION(UUID) + ); + + CREATE TABLE IF NOT EXISTS AM_MONETIZATION_PLATFORM_CUSTOMERS ( + ID SERIAL PRIMARY KEY, + SUBSCRIBER_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, + CUSTOMER_ID VARCHAR(256) NOT NULL, + CONSTRAINT fk_subscriber FOREIGN KEY (SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON DELETE CASCADE + ); + + CREATE TABLE IF NOT EXISTS AM_MONETIZATION_SHARED_CUSTOMERS ( + ID SERIAL PRIMARY KEY, + APPLICATION_ID INTEGER NOT NULL, + API_PROVIDER VARCHAR(256) NOT NULL, + TENANT_ID INTEGER NOT NULL, + SHARED_CUSTOMER_ID VARCHAR(256) NOT NULL, + PARENT_CUSTOMER_ID INTEGER NOT NULL, + CONSTRAINT fk_application FOREIGN KEY (APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) ON DELETE CASCADE, + CONSTRAINT fk_parent_customer FOREIGN KEY (PARENT_CUSTOMER_ID) REFERENCES AM_MONETIZATION_PLATFORM_CUSTOMERS(ID) ON DELETE CASCADE + ); + + CREATE TABLE IF NOT EXISTS AM_MONETIZATION_SUBSCRIPTIONS ( + ID SERIAL PRIMARY KEY, + SUBSCRIBED_APPLICATION_ID INTEGER NOT NULL, + SUBSCRIBED_API_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, + SUBSCRIPTION_ID VARCHAR(256) NOT NULL, + SHARED_CUSTOMER_ID INTEGER NOT NULL, + CONSTRAINT fk_subscribed_application FOREIGN KEY (SUBSCRIBED_APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) ON DELETE CASCADE, + CONSTRAINT fk_subscribed_api FOREIGN KEY (SUBSCRIBED_API_ID) REFERENCES AM_API(API_ID) ON DELETE CASCADE, + CONSTRAINT fk_shared_customer FOREIGN KEY (SHARED_CUSTOMER_ID) REFERENCES AM_MONETIZATION_SHARED_CUSTOMERS(ID) ON DELETE CASCADE + ); ``` 3. Configure the additional monetization properties that are specific to the billing engine in WSO2 API Manager.