-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(inmail-service): added-in-mail-service-migration-update-for-soft-…
…delete-req-fields-and-thread-view (#209)
- Loading branch information
1 parent
8497f0f
commit 948cef3
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
services/in-mail-service/migrations/20210512100952-add-soft-delete-req-fields.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,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, | ||
}; |
61 changes: 61 additions & 0 deletions
61
services/in-mail-service/migrations/20210514143737-update-thread-view.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,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, | ||
}; |
10 changes: 10 additions & 0 deletions
10
services/in-mail-service/migrations/sqls/20210512100952-add-soft-delete-req-fields-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,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; |
10 changes: 10 additions & 0 deletions
10
services/in-mail-service/migrations/sqls/20210512100952-add-soft-delete-req-fields-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,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; |
37 changes: 37 additions & 0 deletions
37
services/in-mail-service/migrations/sqls/20210514143737-update-thread-view-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,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; |
39 changes: 39 additions & 0 deletions
39
services/in-mail-service/migrations/sqls/20210514143737-update-thread-view-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,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; |