From cd15972014faf3879365e8666124f8b1af1cc55b Mon Sep 17 00:00:00 2001 From: Shubham P Date: Wed, 28 Aug 2024 12:01:27 +0530 Subject: [PATCH] migrations: remove plan items table and flush plans in subscription service migrations --- ...826054503-seed-size-config-and-features.js | 63 +++++++++++++++++++ .../20240826065341-remove-plan-items.js | 53 ++++++++++++++++ .../migrations/20240826065659-flush-plans.js | 53 ++++++++++++++++ ...503-seed-size-config-and-features-down.sql | 4 ++ ...54503-seed-size-config-and-features-up.sql | 12 ++++ .../20240826065341-remove-plan-items-down.sql | 24 +++++++ .../20240826065341-remove-plan-items-up.sql | 1 + .../sqls/20240826065659-flush-plans-down.sql | 0 .../sqls/20240826065659-flush-plans-up.sql | 1 + 9 files changed, 211 insertions(+) create mode 100644 packages/migrations/subscription-service/migrations/20240826054503-seed-size-config-and-features.js create mode 100644 packages/migrations/subscription-service/migrations/20240826065341-remove-plan-items.js create mode 100644 packages/migrations/subscription-service/migrations/20240826065659-flush-plans.js create mode 100644 packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-down.sql create mode 100644 packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-up.sql create mode 100644 packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-down.sql create mode 100644 packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-up.sql create mode 100644 packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-down.sql create mode 100644 packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-up.sql diff --git a/packages/migrations/subscription-service/migrations/20240826054503-seed-size-config-and-features.js b/packages/migrations/subscription-service/migrations/20240826054503-seed-size-config-and-features.js new file mode 100644 index 0000000..e00c60e --- /dev/null +++ b/packages/migrations/subscription-service/migrations/20240826054503-seed-size-config-and-features.js @@ -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, +}; diff --git a/packages/migrations/subscription-service/migrations/20240826065341-remove-plan-items.js b/packages/migrations/subscription-service/migrations/20240826065341-remove-plan-items.js new file mode 100644 index 0000000..2db3ce1 --- /dev/null +++ b/packages/migrations/subscription-service/migrations/20240826065341-remove-plan-items.js @@ -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 +}; diff --git a/packages/migrations/subscription-service/migrations/20240826065659-flush-plans.js b/packages/migrations/subscription-service/migrations/20240826065659-flush-plans.js new file mode 100644 index 0000000..7f923f9 --- /dev/null +++ b/packages/migrations/subscription-service/migrations/20240826065659-flush-plans.js @@ -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 +}; diff --git a/packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-down.sql b/packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-down.sql new file mode 100644 index 0000000..1949395 --- /dev/null +++ b/packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-down.sql @@ -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'); \ No newline at end of file diff --git a/packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-up.sql b/packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-up.sql new file mode 100644 index 0000000..28db0b5 --- /dev/null +++ b/packages/migrations/subscription-service/migrations/sqls/20240826054503-seed-size-config-and-features-up.sql @@ -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}}'); diff --git a/packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-down.sql b/packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-down.sql new file mode 100644 index 0000000..147de33 --- /dev/null +++ b/packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-down.sql @@ -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 +) \ No newline at end of file diff --git a/packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-up.sql b/packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-up.sql new file mode 100644 index 0000000..de563c3 --- /dev/null +++ b/packages/migrations/subscription-service/migrations/sqls/20240826065341-remove-plan-items-up.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS main.plan_items; \ No newline at end of file diff --git a/packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-down.sql b/packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-down.sql new file mode 100644 index 0000000..e69de29 diff --git a/packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-up.sql b/packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-up.sql new file mode 100644 index 0000000..8265bbc --- /dev/null +++ b/packages/migrations/subscription-service/migrations/sqls/20240826065659-flush-plans-up.sql @@ -0,0 +1 @@ +DELETE from main.plans;