Skip to content

Commit

Permalink
fix(inmail-service): added-in-mail-service-migration-update-for-soft-…
Browse files Browse the repository at this point in the history
…delete-req-fields-and-thread-view (#209)
  • Loading branch information
sumit-tuteja authored May 18, 2021
1 parent 8497f0f commit 948cef3
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

let dbm;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let type;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let seed;
const fs = require('fs');
const 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) {
const filePath = path.join(
__dirname,
'sqls',
'20210512100952-add-soft-delete-req-fields-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) {
const filePath = path.join(
__dirname,
'sqls',
'20210512100952-add-soft-delete-req-fields-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,61 @@
'use strict';

let dbm;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let type;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let seed;
const fs = require('fs');
const 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) {
const filePath = path.join(
__dirname,
'sqls',
'20210514143737-update-thread-view-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) {
const filePath = path.join(
__dirname,
'sqls',
'20210514143737-update-thread-view-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,10 @@
ALTER TABLE IF EXISTS main.thread DROP COLUMN IF EXISTS deleted_on;
ALTER TABLE IF EXISTS main.thread DROP COLUMN IF EXISTS deleted_by;
ALTER TABLE IF EXISTS main.message DROP COLUMN IF EXISTS deleted_on;
ALTER TABLE IF EXISTS main.message DROP COLUMN IF EXISTS deleted_by;
ALTER TABLE IF EXISTS main.attachment DROP COLUMN IF EXISTS deleted_on;
ALTER TABLE IF EXISTS main.attachment DROP COLUMN IF EXISTS deleted_by;
ALTER TABLE IF EXISTS main.group DROP COLUMN IF EXISTS deleted_on;
ALTER TABLE IF EXISTS main.group DROP COLUMN IF EXISTS deleted_by;
ALTER TABLE IF EXISTS main.meta DROP COLUMN IF EXISTS deleted_on;
ALTER TABLE IF EXISTS main.meta DROP COLUMN IF EXISTS deleted_by;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER TABLE IF EXISTS main.thread ADD COLUMN IF NOT EXISTS deleted_on timestamptz;
ALTER TABLE IF EXISTS main.thread ADD COLUMN IF NOT EXISTS deleted_by uuid;
ALTER TABLE IF EXISTS main.message ADD COLUMN IF NOT EXISTS deleted_on timestamptz;
ALTER TABLE IF EXISTS main.message ADD COLUMN IF NOT EXISTS deleted_by uuid;
ALTER TABLE IF EXISTS main.attachment ADD COLUMN IF NOT EXISTS deleted_on timestamptz;
ALTER TABLE IF EXISTS main.attachment ADD COLUMN IF NOT EXISTS deleted_by uuid;
ALTER TABLE IF EXISTS main.group ADD COLUMN IF NOT EXISTS deleted_on timestamptz;
ALTER TABLE IF EXISTS main.group ADD COLUMN IF NOT EXISTS deleted_by uuid;
ALTER TABLE IF EXISTS main.meta ADD COLUMN IF NOT EXISTS deleted_on timestamptz;
ALTER TABLE IF EXISTS main.meta ADD COLUMN IF NOT EXISTS deleted_by uuid;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
DROP VIEW IF EXISTS main.v_thread
CASCADE;
CREATE OR REPLACE VIEW main.v_thread
AS
SELECT t.id,
t.subject,
t.created_on,
t.modified_on,
t.created_by,
t.ext_id,
t.deleted,
t.ext_metadata as thread_ext_metadata,
t.modified_by,
m.id as message_id,
m.sender,
m.body,
m.ext_metadata as message_ext_metadata,
( SELECT array_to_json(array_agg(row_to_json(d.*))) AS attachment
FROM ( SELECT a.id,
a.path,
a.thumbnail,
a.mime,
a.ext_metadata as "extMetadata",
a.name
FROM main.attachment a
WHERE a.message_id = m.id) d) AS attachment,
( SELECT array_to_json(array_agg(row_to_json(d.*))) AS group
FROM ( SELECT g.id,
g.party,
g.type,
g.is_important as "isImportant",
g.ext_metadata as "extMetadata"
FROM main.group g
WHERE g.message_id = m.id) d) AS group
from
main.thread t
JOIN main.message m on m.thread_id = t.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
DROP VIEW IF EXISTS main.v_thread
CASCADE;
CREATE OR REPLACE VIEW main.v_thread
AS
SELECT t.id,
t.subject,
t.created_on,
t.modified_on,
t.created_by,
t.ext_id,
t.deleted,
t.deleted_on,
t.deleted_by,
t.ext_metadata as thread_ext_metadata,
t.modified_by,
m.id as message_id,
m.sender,
m.body,
m.ext_metadata as message_ext_metadata,
( SELECT array_to_json(array_agg(row_to_json(d.*))) AS attachment
FROM ( SELECT a.id,
a.path,
a.thumbnail,
a.mime,
a.ext_metadata as "extMetadata",
a.name
FROM main.attachment a
WHERE a.message_id = m.id) d) AS attachment,
( SELECT array_to_json(array_agg(row_to_json(d.*))) AS group
FROM ( SELECT g.id,
g.party,
g.type,
g.is_important as "isImportant",
g.ext_metadata as "extMetadata"
FROM main.group g
WHERE g.message_id = m.id) d) AS group
from
main.thread t
JOIN main.message m on m.thread_id = t.id;

0 comments on commit 948cef3

Please sign in to comment.