Skip to content
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

Fix postgres database script #8973

Open
wants to merge 1 commit into
base: 4.4.0
Choose a base branch
from
Open
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
103 changes: 45 additions & 58 deletions en/docs/design/api-monetization/monetizing-an-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down