-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4202 from beyondessential/release-2022-40
Release 2022-40
- Loading branch information
Showing
41 changed files
with
962 additions
and
476 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
120 changes: 120 additions & 0 deletions
120
...i/scripts/patches/1_0_0/20220921024633-FixRenameMaterializedViewToUpdateOuterJoinTable.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,120 @@ | ||
let dbm; | ||
let type; | ||
let seed; | ||
|
||
/** | ||
* 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; | ||
}; | ||
|
||
exports.up = async function (db) { | ||
// Remove orphaned outer join details from previous use of broken renameMaterializedView function | ||
await db.runSql(` | ||
DELETE FROM pg$mviews_oj_details | ||
WHERE view_name = 'analytics_tmp' | ||
`); | ||
|
||
await db.runSql(` | ||
CREATE OR REPLACE | ||
FUNCTION mv$renameMaterializedView | ||
( | ||
pOldViewName IN TEXT, | ||
pNewViewName IN TEXT, | ||
pOwner IN TEXT DEFAULT USER | ||
) | ||
RETURNS VOID | ||
AS | ||
$BODY$ | ||
/* --------------------------------------------------------------------------------------------------------------------------------- | ||
Routine Name: mv$renameMaterializedView | ||
Author: Rohan Port | ||
Date: 17/08/2021 | ||
------------------------------------------------------------------------------------------------------------------------------------ | ||
Revision History Push Down List | ||
------------------------------------------------------------------------------------------------------------------------------------ | ||
Date | Name | Description | ||
------------+---------------+------------------------------------------------------------------------------------------------------- | ||
21/09/2022 | Rohan Port | Fix to rename references in outerjoin details table as well | ||
------------+---------------+------------------------------------------------------------------------------------------------------- | ||
Description: Renames a materialized view, edits the view_name in the pg$mviews table | ||
This function performs the following steps | ||
1) Edits the view_name in the pg$mviews table to be the new name | ||
2) Alters the materialized view table name to be the new name | ||
Arguments: IN pOldViewName The existing name of the materialized view | ||
IN pNewViewName The new name of the materialized view | ||
IN pOwner Optional, the owner of the materialized view, defaults to user | ||
Returns: VOID | ||
************************************************************************************************************************************ | ||
Copyright 2021 Beyond Essential Systems Pty Ltd | ||
***********************************************************************************************************************************/ | ||
DECLARE | ||
aPgMview pg$mviews; | ||
rConst mv$allConstants; | ||
tUpdatePgMviewsSqlStatement TEXT := ''; | ||
tUpdatePgMviewOjDetailsSqlStatement TEXT := ''; | ||
tRenameTableSqlStatement TEXT := ''; | ||
tRenameIndexSqlStatement TEXT := ''; | ||
rIndex RECORD; | ||
tOldIndexName TEXT; | ||
tNewIndexName TEXT; | ||
begin | ||
rConst := mv$buildAllConstants(); | ||
tUpdatePgMviewsSqlStatement := rConst.UPDATE_COMMAND || 'pg$mviews' || rConst.SET_COMMAND || 'view_name = ' | ||
|| rConst.SINGLE_QUOTE_CHARACTER || pNewViewName || rConst.SINGLE_QUOTE_CHARACTER | ||
|| rConst.WHERE_COMMAND || 'view_name = ' || rConst.SINGLE_QUOTE_CHARACTER || pOldViewName || rConst.SINGLE_QUOTE_CHARACTER; | ||
tUpdatePgMviewOjDetailsSqlStatement := rConst.UPDATE_COMMAND || 'pg$mviews_oj_details' || rConst.SET_COMMAND || 'view_name = ' | ||
|| rConst.SINGLE_QUOTE_CHARACTER || pNewViewName || rConst.SINGLE_QUOTE_CHARACTER | ||
|| rConst.WHERE_COMMAND || 'view_name = ' || rConst.SINGLE_QUOTE_CHARACTER || pOldViewName || rConst.SINGLE_QUOTE_CHARACTER; | ||
tRenameTableSqlStatement := rConst.ALTER_TABLE || pOldViewName || rConst.RENAME_TO_COMMAND || pNewViewName; | ||
EXECUTE tUpdatePgMviewsSqlStatement; | ||
EXECUTE tUpdatePgMviewOjDetailsSqlStatement; | ||
EXECUTE tRenameTableSqlStatement; | ||
FOR rIndex IN | ||
SELECT indexname FROM pg_indexes WHERE schemaname = pOwner AND tablename = pNewViewName AND indexname like '%' || rConst.MV_M_ROW$_COLUMN || '%' | ||
LOOP | ||
tOldIndexName := rIndex.indexname; | ||
tNewIndexName := REPLACE(tOldIndexName, pOldViewName, pNewViewName); | ||
tRenameIndexSqlStatement := rConst.ALTER_INDEX || tOldIndexName || rConst.RENAME_TO_COMMAND || tNewIndexName; | ||
execute tRenameIndexSqlStatement; | ||
END LOOP; | ||
RETURN; | ||
EXCEPTION | ||
WHEN OTHERS | ||
THEN | ||
RAISE INFO 'Exception in function mv$renameMaterializedView'; | ||
RAISE INFO 'Error %:- %:', SQLSTATE, SQLERRM; | ||
RAISE INFO E'Error Context:% % \n % \n %',CHR(10), tUpdatePgMviewsSqlStatement, tRenameTableSqlStatement, tRenameIndexSqlStatement; | ||
RAISE EXCEPTION '%', SQLSTATE; | ||
END; | ||
$BODY$ | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER; | ||
`); | ||
}; | ||
|
||
exports.down = function (db) { | ||
return null; | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
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
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,7 @@ | ||
const baseConfig = require('../../jest.config-js.json'); | ||
|
||
module.exports = async () => ({ | ||
...baseConfig, | ||
rootDir: '.', | ||
setupFilesAfterEnv: ['../../jest.setup.js', './jest.setup.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,12 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { clearTestData, getTestDatabase } from './src/testUtilities'; | ||
|
||
afterAll(async () => { | ||
const database = getTestDatabase(); | ||
await clearTestData(database); | ||
await database.closeConnections(); | ||
}); |
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
Oops, something went wrong.