Skip to content

Commit

Permalink
migrations: remove plan items table and flush plans in subscription s…
Browse files Browse the repository at this point in the history
…ervice migrations
  • Loading branch information
shubhamp-sf committed Aug 28, 2024
1 parent 73a9a45 commit cd15972
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 0 deletions.
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,
};
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
};
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
};
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');
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}}');
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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS main.plan_items;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE from main.plans;

0 comments on commit cd15972

Please sign in to comment.