-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subscription-service): add billing functionality to subscription…
… service add billing functionality to subscription service BREAKING CHANGE: yes gh-34
- Loading branch information
1 parent
3a7aa05
commit 9bd232b
Showing
36 changed files
with
1,661 additions
and
302 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
services/subscription-service/migrations/pg/migrations/20240209122448-add-customer-table.js
This file contains 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,59 @@ | ||
'use strict'; | ||
|
||
let dbm; | ||
let type; | ||
let seed; | ||
let fs = require('fs'); | ||
let path = require('path'); | ||
let Promise; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function (options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
Promise = options.Promise; | ||
}; | ||
|
||
exports.up = function (db) { | ||
let filePath = path.join( | ||
__dirname, | ||
'sqls', | ||
'20240209122448-add-customer-table-up.sql', | ||
); | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { | ||
if (err) return reject(err); | ||
console.log('received data: ' + data); | ||
|
||
resolve(data); | ||
}); | ||
}).then(function (data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports.down = function (db) { | ||
let filePath = path.join( | ||
__dirname, | ||
'sqls', | ||
'20240209122448-add-customer-table-down.sql', | ||
); | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { | ||
if (err) return reject(err); | ||
console.log('received data: ' + data); | ||
|
||
resolve(data); | ||
}); | ||
}).then(function (data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
This file contains 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
2 changes: 2 additions & 0 deletions
2
...cription-service/migrations/pg/migrations/sqls/20240209122448-add-customer-table-down.sql
This file contains 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,2 @@ | ||
drop table main.billing_customer; | ||
drop table main.invoice; |
41 changes: 41 additions & 0 deletions
41
...bscription-service/migrations/pg/migrations/sqls/20240209122448-add-customer-table-up.sql
This file contains 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,41 @@ | ||
|
||
CREATE TABLE main.billing_customer ( | ||
id uuid DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL, | ||
tenant_id varchar(255) NOT NULL, | ||
customer_id varchar(255) NOT NULL, | ||
payment_source_id varchar(255), | ||
created_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
modified_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
deleted boolean DEFAULT false NOT NULL, | ||
deleted_on timestamptz, | ||
deleted_by uuid, | ||
created_by uuid NOT NULL, | ||
modified_by uuid, | ||
CONSTRAINT pk_billing_customer_id PRIMARY KEY (id), | ||
CONSTRAINT uq_billing_customer_customer_id UNIQUE (customer_id) | ||
); | ||
|
||
|
||
|
||
CREATE TABLE main.invoice ( | ||
id UUID DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL, | ||
invoice_id VARCHAR(255) NOT NULL, | ||
invoice_status BOOLEAN, | ||
billing_customer_id uuid NOT NULL, | ||
-- subscription_id uuid, | ||
created_on TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
modified_on TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
deleted BOOLEAN DEFAULT false NOT NULL, | ||
deleted_on TIMESTAMPTZ, | ||
deleted_by UUID, | ||
created_by UUID NOT NULL, | ||
modified_by UUID, | ||
CONSTRAINT pk_invoice_id PRIMARY KEY (id), | ||
CONSTRAINT fk_invoice_customer FOREIGN KEY (billing_customer_id) REFERENCES main.billing_customer(id) | ||
|
||
-- CONSTRAINT fk_invoice_subscription FOREIGN KEY (subscription_id) REFERENCES main.subscriptions(id) -- Add this constraint | ||
); | ||
|
||
ALTER TABLE main.subscriptions | ||
ADD COLUMN invoice_id uuid NOT NULL, | ||
ADD CONSTRAINT fk_subscriptions_invoice FOREIGN KEY (invoice_id) REFERENCES main.invoice(id); |
This file contains 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
This file contains 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
Oops, something went wrong.