-
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… (
#38) add billing functionality to subscription service BREAKING CHANGE: yes gh-34 ## Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Intermediate change (work in progress) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Test A - [ ] Test B ## Checklist: - [ ] Performed a self-review of my own code - [ ] npm test passes on your machine - [ ] New tests added or existing tests modified to cover all changes - [ ] Code conforms with the style guide - [ ] API Documentation in code was updated - [ ] Any dependent changes have been merged and published in downstream modules
- Loading branch information
1 parent
944a5c3
commit a1ea1e3
Showing
43 changed files
with
3,150 additions
and
1,223 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 VARCHAR(255), | ||
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.