I need to calculate MRR as describe in https://www.chargebee.com/blog/mrr-subscription-businesses-saas-metrics-101/ between selected two dates
using postgresql json, also my subscription are having intervals like "1 DAY", "15 DAY", "2 WEEK", "X WEEK", "X MONTH", "x YEAR" where x can be any number
I have following subscription schema and values:
CREATE TABLE subscriptions
(
id bigserial NOT NULL,
data json,
created_date date,
updated_date date,
user_id bigserial NOT NULL,
CONSTRAINT subscription_id_pk PRIMARY KEY (id)
)
And data are inside column "data" in json format like:
{
"id": "1",
"amount": 3900,
"interval": "1 WEEK",
"created": 1424011935
}
And transactions, is created when each recurring subscription is succeeded. I think transaction is not required, but if u can develop with this then good too.
CREATE TABLE transactions
(
id bigserial NOT NULL,
data json,
created_date date,
updated_date date,
user_id bigserial NOT NULL,
CONSTRAINT transactions_id_pk PRIMARY KEY (id)
)
And data are inside column "data" in json format like:
{
"id": "1",
"amount": 3900,
"subscription_id": "1"
"created": 1424011935
}
you can use created unix timestamp from data json or created_date from table whichever is better for you
here subscription created date is subscription created first time and not each recurring.
I am having version 9.3