-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrations: remove plan items table and flush plans in subscription s…
…ervice migrations
- Loading branch information
1 parent
73a9a45
commit cd15972
Showing
9 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...igrations/subscription-service/migrations/20240826054503-seed-size-config-and-features.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,63 @@ | ||
"use strict"; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var 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) { | ||
var filePath = path.join( | ||
__dirname, | ||
"sqls", | ||
"20240826054503-seed-size-config-and-features-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) { | ||
data = data.replaceAll( | ||
"{{ADMIN_USER_TENANT_ID}}", | ||
process.env.ADMIN_USER_TENANT_ID | ||
); | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports.down = function (db) { | ||
var filePath = path.join( | ||
__dirname, | ||
"sqls", | ||
"20240826054503-seed-size-config-and-features-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, | ||
}; |
53 changes: 53 additions & 0 deletions
53
packages/migrations/subscription-service/migrations/20240826065341-remove-plan-items.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,53 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var 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) { | ||
var filePath = path.join(__dirname, 'sqls', '20240826065341-remove-plan-items-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) { | ||
var filePath = path.join(__dirname, 'sqls', '20240826065341-remove-plan-items-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 | ||
}; |
53 changes: 53 additions & 0 deletions
53
packages/migrations/subscription-service/migrations/20240826065659-flush-plans.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,53 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var 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) { | ||
var filePath = path.join(__dirname, 'sqls', '20240826065659-flush-plans-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) { | ||
var filePath = path.join(__dirname, 'sqls', '20240826065659-flush-plans-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 | ||
}; |
4 changes: 4 additions & 0 deletions
4
...ubscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-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,4 @@ | ||
DELETE FROM main.plan_sizes | ||
WHERE size IN ('SMALL', 'LARGE', 'MEDIUM'); | ||
|
||
DELETE FROM main.features WHERE key IN ('COMMISSION', 'MONTHLY_CONSULTATION', 'VIDEO_CALL', 'MEDICINE_STORE'); |
12 changes: 12 additions & 0 deletions
12
.../subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-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,12 @@ | ||
INSERT INTO main.plan_sizes (id, size, config, created_by) | ||
VALUES | ||
(DEFAULT, 'SMALL', '{"POSTGRES_SIZE": "10", "INSTANCE_CATEGORY": "t"}', '{{ADMIN_USER_TENANT_ID}}'), | ||
(DEFAULT, 'LARGE', '{"POSTGRES_SIZE": "50", "INSTANCE_CATEGORY": "c"}', '{{ADMIN_USER_TENANT_ID}}'), | ||
(DEFAULT, 'MEDIUM', '{"POSTGRES_SIZE": "25", "INSTANCE_CATEGORY": "m"}', '{{ADMIN_USER_TENANT_ID}}'); | ||
|
||
INSERT INTO main.features (id, name, key, description, default_value, type, metadata, created_by) | ||
VALUES | ||
(DEFAULT, 'Commission Rate', 'COMMISSION', '% Commission that goes to the SaaS Provider, for each call paid call that gets scheduled via the tenant''s application.', '0.5', 'number', '{}', '{{ADMIN_USER_TENANT_ID}}'), | ||
(DEFAULT, 'Monthly Consultation Limit', 'MONTHLY_CONSULTATION', 'Number of consultation that can be scheduled in a month across customers.', NULL, 'number', '{}', '{{ADMIN_USER_TENANT_ID}}'), | ||
(DEFAULT, 'Video Call', 'VIDEO_CALL', 'Whether to allow video call facility in the application.', 'false', 'boolean', '{}', '{{ADMIN_USER_TENANT_ID}}'), | ||
(DEFAULT, 'Online Medicine Store', 'MEDICINE_STORE', 'Feature to publish a medicine store page in the app.', 'false', 'boolean', '{}', '{{ADMIN_USER_TENANT_ID}}'); |
24 changes: 24 additions & 0 deletions
24
...migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-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,24 @@ | ||
CREATE TABLE IF NOT EXISTS main.plan_items | ||
( | ||
id uuid NOT NULL DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid, | ||
created_on timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
modified_on timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
deleted boolean NOT NULL DEFAULT false, | ||
deleted_on timestamp with time zone, | ||
deleted_by uuid, | ||
created_by uuid NOT NULL, | ||
modified_by uuid, | ||
name character varying(100) COLLATE pg_catalog."default" NOT NULL, | ||
plan_item_type character varying(30) COLLATE pg_catalog."default" NOT NULL, | ||
plan_id uuid NOT NULL, | ||
value jsonb NOT NULL, | ||
CONSTRAINT pk_plan_items_id PRIMARY KEY (id), | ||
CONSTRAINT fk_plan_items_plan_id FOREIGN KEY (plan_id) | ||
REFERENCES main.plans (id) MATCH SIMPLE | ||
ON UPDATE NO ACTION | ||
ON DELETE NO ACTION, | ||
CONSTRAINT fk_plan_items_plans FOREIGN KEY (plan_id) | ||
REFERENCES main.plans (id) MATCH SIMPLE | ||
ON UPDATE NO ACTION | ||
ON DELETE NO ACTION | ||
) |
1 change: 1 addition & 0 deletions
1
...s/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-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 @@ | ||
DROP TABLE IF EXISTS main.plan_items; |
Empty file.
1 change: 1 addition & 0 deletions
1
packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-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 @@ | ||
DELETE from main.plans; |