@axinom/mosaic-db-common 0.14.0-rc.9 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/common/types.d.ts +15 -0
- package/dist/common/types.d.ts.map +1 -1
- package/dist/messaging/messaging-counter.d.ts +3 -3
- package/dist/messaging/messaging-counter.d.ts.map +1 -1
- package/dist/messaging/messaging-counter.js.map +1 -1
- package/dist/middleware/pg-pool.middleware.d.ts +11 -12
- package/dist/middleware/pg-pool.middleware.d.ts.map +1 -1
- package/dist/middleware/pg-pool.middleware.js +1 -0
- package/dist/middleware/pg-pool.middleware.js.map +1 -1
- package/migrations/before-migration/{005-created-updated-triggers.sql → 005-created-updated-deleted-triggers.sql} +47 -6
- package/migrations/define/define-functions.sql +3 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.14.0](https://dev.azure.com/axinom/CMS/_git/Navy/branchCompare?baseVersion=GT@axinom/mosaic-db-common@0.13.0&targetVersion=GT@axinom/mosaic-db-common@0.14.0) (2022-03-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* generate-define-func-migration command added to mosaic-db cli ([2ac186a](https://dev.azure.com/axinom/CMS/_git/Navy/commit/2ac186a441f03c8c3995150fda62874027b46f98)), closes [#34023](https://dev.azure.com/axinom/CMS/_workitems/edit/34023)
|
|
12
|
+
* modular @axinom/mosaic-cli ([3cefbdb](https://dev.azure.com/axinom/CMS/_git/Navy/commit/3cefbdb5ff38fa99ee5e1f89b8ee44ac35ad92f9)), closes [#34705](https://dev.azure.com/axinom/CMS/_workitems/edit/34705) [#34288](https://dev.azure.com/axinom/CMS/_workitems/edit/34288)
|
|
13
|
+
* mosaic-db CLI dropped in favor of modular mosaic CLI ([6bdbea0](https://dev.azure.com/axinom/CMS/_git/Navy/commit/6bdbea06f2cae3dfaf766444b6c49d3775b686bd))
|
|
14
|
+
* multitenancy delete safety net ([f09f6d3](https://dev.azure.com/axinom/CMS/_git/Navy/commit/f09f6d3f0fd07dc2227095f583625d8708b97ee2)), closes [#34820](https://dev.azure.com/axinom/CMS/_workitems/edit/34820)
|
|
15
|
+
* renamed consumer to end-user where possible ([c24f49b](https://dev.azure.com/axinom/CMS/_git/Navy/commit/c24f49b4e471e4de83836f587dc10c8efdb0f751))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
## [0.13.0](https://dev.azure.com/axinom/CMS/_git/Navy/branchCompare?baseVersion=GT@axinom/mosaic-db-common@0.12.0&targetVersion=GT@axinom/mosaic-db-common@0.13.0) (2022-03-01)
|
|
7
20
|
|
|
8
21
|
|
package/dist/common/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
1
2
|
/**
|
|
2
3
|
* A dictionary of string keys and generic values. Consider using it instead of `any`.
|
|
3
4
|
*/
|
|
@@ -33,4 +34,18 @@ export interface DbLogger {
|
|
|
33
34
|
export interface DbShutdownActions {
|
|
34
35
|
push(action: () => void | Promise<void>): void;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* An abstract type extending PostgreSQL Pool. All labelled pool types extend
|
|
39
|
+
* pg.Pool but labelled pool types are not interchangeable so typescript can be
|
|
40
|
+
* leveraged to ensure the correct pool type is being used in a given context.
|
|
41
|
+
*/
|
|
42
|
+
export declare type LabelledPgPool<T extends string> = Pool & {
|
|
43
|
+
label: T;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Default labelled pool types
|
|
47
|
+
*/
|
|
48
|
+
export declare type OwnerPgPool = LabelledPgPool<'Owner'>;
|
|
49
|
+
export declare type EnvOwnerPgPool = LabelledPgPool<'EnvOwner'>;
|
|
50
|
+
export declare type LoginPgPool = LabelledPgPool<'Login'>;
|
|
36
51
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAChD"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAChD;AAED;;;;GAIG;AACH,oBAAY,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,IAAI,GAAG;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEnE;;GAEG;AACH,oBAAY,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AAClD,oBAAY,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AACxD,oBAAY,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OwnerPgPool } from '../common/types';
|
|
2
2
|
export interface NextRedeliveriesFunction {
|
|
3
3
|
(error: Error | undefined | null, redeliveries?: number): void;
|
|
4
4
|
}
|
|
@@ -6,7 +6,7 @@ export interface NextRedeliveriesFunction {
|
|
|
6
6
|
* This method can be called from a CRON job/task scheduler to regularly cleanup expired messages.
|
|
7
7
|
* @param ownerPool database pool with select and delete permissions to `app_private.messaging_counter`
|
|
8
8
|
*/
|
|
9
|
-
export declare const cleanupExpiredMessagingCounters: (ownerPool:
|
|
9
|
+
export declare const cleanupExpiredMessagingCounters: (ownerPool: OwnerPgPool) => Promise<void>;
|
|
10
10
|
/**
|
|
11
11
|
* ## PostgreSQL messaging counter for Rascal redeliveries
|
|
12
12
|
*
|
|
@@ -84,7 +84,7 @@ export declare const cleanupExpiredMessagingCounters: (ownerPool: Pool) => Promi
|
|
|
84
84
|
* ```
|
|
85
85
|
* @param ownerPool database pool with full read/modify permissions to `app_private.messaging_counter`
|
|
86
86
|
*/
|
|
87
|
-
export declare const initMessagingCounter: (ownerPool:
|
|
87
|
+
export declare const initMessagingCounter: (ownerPool: OwnerPgPool) => () => {
|
|
88
88
|
incrementAndGet: (key: string, next: NextRedeliveriesFunction) => void;
|
|
89
89
|
};
|
|
90
90
|
//# sourceMappingURL=messaging-counter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-counter.d.ts","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messaging-counter.d.ts","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAyC9C,MAAM,WAAW,wBAAwB;IACvC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChE;AAED;;;GAGG;AACH,eAAO,MAAM,+BAA+B,cAC/B,WAAW,KACrB,QAAQ,IAAI,CAQd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,eAAO,MAAM,oBAAoB,cAAe,WAAW;2BAEhC,MAAM,QAAQ,wBAAwB,KAAK,IAAI;CAiBzE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-counter.js","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"messaging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sB,EAAE,EAAE;IAC7D,OAAO,SAAS,IAAI;QAGlB,OAAO;YACL,eAAe,EAAE,UAAU,GAAW,EAAE,IAA8B;gBACpE,sBAAsB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,IAAI,CACzC,CAAC,OAAe,EAAE,EAAE;oBAClB,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACtB,CAAC,EACD,CAAC,GAAU,EAAE,EAAE;oBACb,IAAI,GAAG,EAAE;wBACP,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;qBAClB;gBACH,CAAC,CACF,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,oBAAoB,wBAmB/B"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Application, Express } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
import { DbLogger, DbShutdownActions } from '../common';
|
|
2
|
+
import { DbLogger, DbShutdownActions, EnvOwnerPgPool, LabelledPgPool, LoginPgPool, OwnerPgPool } from '../common';
|
|
4
3
|
/**
|
|
5
4
|
* Creates a PostgreSQL Pool for a given connection string, and returns it.
|
|
6
5
|
*
|
|
@@ -10,40 +9,40 @@ import { DbLogger, DbShutdownActions } from '../common';
|
|
|
10
9
|
* @param shutdownActions
|
|
11
10
|
* @returns
|
|
12
11
|
*/
|
|
13
|
-
export declare const createPgPool: (connectionString: string, poolLabel:
|
|
12
|
+
export declare const createPgPool: <T extends string>(connectionString: string, poolLabel: T, logger: DbLogger, shutdownActions: DbShutdownActions) => LabelledPgPool<T>;
|
|
14
13
|
/**
|
|
15
14
|
* Returns the previously set up PostgreSQL pool for the database owner. The owner pool has full access to the database.
|
|
16
15
|
* @param app express app
|
|
17
16
|
*/
|
|
18
|
-
export declare const getOwnerPgPool: (app: Express | Application) =>
|
|
17
|
+
export declare const getOwnerPgPool: (app: Express | Application) => OwnerPgPool;
|
|
19
18
|
/**
|
|
20
19
|
* Sets a given pool as the Owner Pool for an Express Application
|
|
21
20
|
* @param app
|
|
22
21
|
* @param ownerPool
|
|
23
22
|
*/
|
|
24
|
-
export declare const setOwnerPgPool: (app: Application, ownerPool:
|
|
23
|
+
export declare const setOwnerPgPool: (app: Application, ownerPool: OwnerPgPool) => void;
|
|
25
24
|
/**
|
|
26
25
|
* Returns the previously set up PostgreSQL pool for the environment owner. The environment owner cannot bypass Row Level Security and database requests will only operate on specific tenant and environment rows.
|
|
27
26
|
* @param app express app
|
|
28
27
|
*/
|
|
29
|
-
export declare const getEnvOwnerPgPool: (app: Express | Application) =>
|
|
28
|
+
export declare const getEnvOwnerPgPool: (app: Express | Application) => EnvOwnerPgPool;
|
|
30
29
|
/**
|
|
31
30
|
* Sets a given pool as the Environment Owner Pool for an Express Application
|
|
32
31
|
* @param app
|
|
33
32
|
* @param envOwnerPool
|
|
34
33
|
*/
|
|
35
|
-
export declare const setEnvOwnerPgPool: (app: Application, envOwnerPool:
|
|
34
|
+
export declare const setEnvOwnerPgPool: (app: Application, envOwnerPool: EnvOwnerPgPool) => void;
|
|
36
35
|
/**
|
|
37
36
|
* Returns the previously set up PostgreSQL pool for the login user. The login pool is internally used by postgraphile to access the database via GraphQL API endpoints.
|
|
38
37
|
* @param app express app
|
|
39
38
|
*/
|
|
40
|
-
export declare const getLoginPgPool: (app: Express | Application) =>
|
|
39
|
+
export declare const getLoginPgPool: (app: Express | Application) => LoginPgPool;
|
|
41
40
|
/**
|
|
42
41
|
* Sets a given pool as the Login Pool for an Express Application
|
|
43
42
|
* @param app
|
|
44
43
|
* @param loginPool
|
|
45
44
|
*/
|
|
46
|
-
export declare const setLoginPgPool: (app: Application, loginPool:
|
|
45
|
+
export declare const setLoginPgPool: (app: Application, loginPool: LoginPgPool) => void;
|
|
47
46
|
/**
|
|
48
47
|
* Sets up a PostgreSQL pool for the owner to be reused by other app components. The owner pool has full access to the database.
|
|
49
48
|
* @param app express app
|
|
@@ -74,19 +73,19 @@ export declare const setupLoginPgPool: (app: Express | Application, connectionSt
|
|
|
74
73
|
* @param logger logger to log errors and shutdown action messages
|
|
75
74
|
* @param shutdownActions shutdown actions middleware
|
|
76
75
|
*/
|
|
77
|
-
export declare const createOwnerPgPool: (connectionString: string, logger: DbLogger, shutdownActions: DbShutdownActions) =>
|
|
76
|
+
export declare const createOwnerPgPool: (connectionString: string, logger: DbLogger, shutdownActions: DbShutdownActions) => OwnerPgPool;
|
|
78
77
|
/**
|
|
79
78
|
* Sets up a PostgreSQL pool for the environment owner. The environment owner cannot bypass Row Level Security and database requests will only operate on specific tenant and environment rows.
|
|
80
79
|
* @param connectionString full database connection string
|
|
81
80
|
* @param logger logger to log errors and shutdown action messages
|
|
82
81
|
* @param shutdownActions shutdown actions middleware
|
|
83
82
|
*/
|
|
84
|
-
export declare const createEnvOwnerPgPool: (connectionString: string, logger: DbLogger, shutdownActions: DbShutdownActions) =>
|
|
83
|
+
export declare const createEnvOwnerPgPool: (connectionString: string, logger: DbLogger, shutdownActions: DbShutdownActions) => EnvOwnerPgPool;
|
|
85
84
|
/**
|
|
86
85
|
* Sets up a PostgreSQL pool for the login user. The login pool is internally used by postgraphile to access the database via GraphQL API endpoints.
|
|
87
86
|
* @param connectionString full database connection string
|
|
88
87
|
* @param logger logger to log errors and shutdown action messages
|
|
89
88
|
* @param shutdownActions shutdown actions middleware
|
|
90
89
|
*/
|
|
91
|
-
export declare const createLoginPgPool: (connectionString: string, logger: DbLogger, shutdownActions: DbShutdownActions) =>
|
|
90
|
+
export declare const createLoginPgPool: (connectionString: string, logger: DbLogger, shutdownActions: DbShutdownActions) => LoginPgPool;
|
|
92
91
|
//# sourceMappingURL=pg-pool.middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-pool.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/pg-pool.middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"pg-pool.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/pg-pool.middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,WAAW,EACX,WAAW,EACZ,MAAM,WAAW,CAAC;AAEnB;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,uCACL,MAAM,wBAEhB,QAAQ,mBACC,iBAAiB,sBA2BnC,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAS,OAAO,GAAG,WAAW,KAAG,WAE3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,QACpB,WAAW,aACL,WAAW,KACrB,IAEF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QACvB,OAAO,GAAG,WAAW,KACzB,cAEF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QACvB,WAAW,gBACF,cAAc,KAC3B,IAEF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAS,OAAO,GAAG,WAAW,KAAG,WAE3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,QACpB,WAAW,aACL,WAAW,KACrB,IAEF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QACtB,OAAO,GAAG,WAAW,oBACR,MAAM,UAChB,QAAQ,mBACC,iBAAiB,KACjC,IAKF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,QACzB,OAAO,GAAG,WAAW,oBACR,MAAM,UAChB,QAAQ,mBACC,iBAAiB,KACjC,IAKF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QACtB,OAAO,GAAG,WAAW,oBACR,MAAM,UAChB,QAAQ,mBACC,iBAAiB,KACjC,IAKF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,qBACV,MAAM,UAChB,QAAQ,mBACC,iBAAiB,KACjC,WAEF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,qBACb,MAAM,UAChB,QAAQ,mBACC,iBAAiB,KACjC,cAEF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,qBACV,MAAM,UAChB,QAAQ,mBACC,iBAAiB,KACjC,WAEF,CAAC"}
|
|
@@ -13,6 +13,7 @@ const pg_1 = require("pg");
|
|
|
13
13
|
*/
|
|
14
14
|
const createPgPool = (connectionString, poolLabel, logger, shutdownActions) => {
|
|
15
15
|
const pgPool = new pg_1.Pool({ connectionString });
|
|
16
|
+
pgPool.label = poolLabel;
|
|
16
17
|
// If a pg pool error happens and triggers the exit of node process (e.g postgres server stopped while postgraphile service is running) -
|
|
17
18
|
// it is possible for it to not be caught using this handler, because node process will close faster.
|
|
18
19
|
// But such errors can always be caught using 'uncaughtException' process event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-pool.middleware.js","sourceRoot":"","sources":["../../src/middleware/pg-pool.middleware.ts"],"names":[],"mappings":";;;AAEA,2BAA0B;
|
|
1
|
+
{"version":3,"file":"pg-pool.middleware.js","sourceRoot":"","sources":["../../src/middleware/pg-pool.middleware.ts"],"names":[],"mappings":";;;AAEA,2BAA0B;AAU1B;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAC1B,gBAAwB,EACxB,SAAY,EACZ,MAAgB,EAChB,eAAkC,EACf,EAAE;IACrB,MAAM,MAAM,GAAG,IAAI,SAAI,CAAC,EAAE,gBAAgB,EAAE,CAAsB,CAAC;IACnE,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC;IAEzB,yIAAyI;IACzI,qGAAqG;IACrG,gFAAgF;IAChF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,uEAAuE;QACvE,MAAM,WAAW,GAAG,GAA2B,C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,OAAO,IAAA,oBAAY,EAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC1E,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B;AAEF;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,CAClC,gBAAwB,EACxB,MAAgB,EAChB,eAAkC,EAClB,EAAE;IAClB,OAAO,IAAA,oBAAY,EAAC,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC7E,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B;AAEF;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAC/B,gBAAwB,EACxB,MAAgB,EAChB,eAAkC,EACrB,EAAE;IACf,OAAO,IAAA,oBAAY,EAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC1E,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B"}
|
|
@@ -26,12 +26,17 @@ BEGIN
|
|
|
26
26
|
END;
|
|
27
27
|
$$ LANGUAGE plpgsql volatile SET search_path TO pg_catalog, public, pg_temp;
|
|
28
28
|
|
|
29
|
-
--
|
|
30
|
-
-- mosaic.tenant_id and
|
|
31
|
-
--
|
|
32
|
-
--
|
|
33
|
-
--
|
|
34
|
-
--
|
|
29
|
+
-- Trigger function to set tenant_id and environment_id from settings and to
|
|
30
|
+
-- prevent accidental cross-tenant/environment updates. mosaic.tenant_id and
|
|
31
|
+
-- mosaic.environment_id are added by PostGraphile to the pool context. If a
|
|
32
|
+
-- pool is manually created the settings must be supplied as well. The only
|
|
33
|
+
-- exception are superusers who can manually set them for e.g. local
|
|
34
|
+
-- development.
|
|
35
|
+
-- IMPORTANT: UPDATE operations made by db owner must explicitly specify
|
|
36
|
+
-- tenant_id / environment_id in a WHERE condition. If UPDATE or INSERT
|
|
37
|
+
-- would affect/create rows for a tenant / environment that does not match
|
|
38
|
+
-- settings then an exception will occur.
|
|
39
|
+
-- Usage:
|
|
35
40
|
-- SELECT set_config('mosaic.tenant_id', '00000000-0000-0000-0000-000000000000', TRUE);
|
|
36
41
|
-- SELECT set_config('mosaic.environment_id', '00000000-0000-0000-0000-000000000000', TRUE);
|
|
37
42
|
-- or
|
|
@@ -66,6 +71,42 @@ $$ LANGUAGE plpgsql VOLATILE;
|
|
|
66
71
|
COMMENT ON FUNCTION ax_utils.tg__tenant_environment() IS
|
|
67
72
|
E'This trigger should be called on tables needing automatic tenant_id, environment_id - to support multi-tenancy';
|
|
68
73
|
|
|
74
|
+
-- Trigger function to prevent accidental cross-tenant/environment deletion.
|
|
75
|
+
-- This trigger should be applied alongside 'ax_utils.tg__tenant_environment'
|
|
76
|
+
-- Settings & usage are the same as for 'ax_utils.tg__tenant_environment'.
|
|
77
|
+
-- IMPORTANT: DELETE operations made by db owner must explicitly specify
|
|
78
|
+
-- tenant_id / environment_id in a WHERE condition. If DELETE would affect
|
|
79
|
+
-- rows from a tenant / environment that does not match settings then an
|
|
80
|
+
-- exception will occur.
|
|
81
|
+
CREATE OR REPLACE FUNCTION ax_utils.tg__tenant_environment_on_delete() RETURNS TRIGGER AS $$
|
|
82
|
+
DECLARE
|
|
83
|
+
tenant_id text = current_setting('mosaic.tenant_id', TRUE);
|
|
84
|
+
environment_id text = current_setting('mosaic.environment_id', TRUE);
|
|
85
|
+
is_superuser text = current_setting('is_superuser', TRUE);
|
|
86
|
+
ignore_multitenancy text = current_setting('mosaic.ignore_multitenancy', TRUE);
|
|
87
|
+
BEGIN
|
|
88
|
+
IF tenant_id <> '' THEN -- Not null and not empty
|
|
89
|
+
IF OLD.tenant_id::TEXT <> tenant_id THEN
|
|
90
|
+
perform ax_utils.raise_error('The "mosaic.tenant_id" set via set_config must match the deleted row.', 'TENAN');
|
|
91
|
+
END IF;
|
|
92
|
+
ELSIF is_superuser <> 'on' AND ignore_multitenancy <> 'on' THEN
|
|
93
|
+
perform ax_utils.raise_error('The "mosaic.tenant_id" must be set via set_config value.', 'TENAN');
|
|
94
|
+
END IF;
|
|
95
|
+
IF environment_id <> '' THEN -- Not null and not empty
|
|
96
|
+
IF OLD.environment_id::TEXT <> environment_id THEN
|
|
97
|
+
perform ax_utils.raise_error('The "mosaic.environment_id" set via set_config must match the deleted row.', 'ENVVV');
|
|
98
|
+
END IF;
|
|
99
|
+
ELSIF is_superuser <> 'on' AND ignore_multitenancy <> 'on' THEN
|
|
100
|
+
perform ax_utils.raise_error('The "mosaic.environment_id" must be set via set_config value.', 'ENVVV');
|
|
101
|
+
END IF;
|
|
102
|
+
RETURN OLD;
|
|
103
|
+
END;
|
|
104
|
+
$$ LANGUAGE plpgsql VOLATILE;
|
|
105
|
+
|
|
106
|
+
COMMENT ON FUNCTION ax_utils.tg__tenant_environment_on_delete() IS
|
|
107
|
+
E'This trigger should be called on tables needing automatic tenant_id, environment_id - to support multi-tenancy';
|
|
108
|
+
|
|
109
|
+
|
|
69
110
|
-- Trigger function to set user_id from settings mosaic.auth.user_id.
|
|
70
111
|
-- The setting is added by Postgraphile to the pool context referring
|
|
71
112
|
-- to the 'sub' property of the AuthenticatedSubject when the type is of EndUserAccount.
|
|
@@ -142,6 +142,7 @@ CREATE OR REPLACE FUNCTION ax_define.drop_tenant_environment_trigger(tableName t
|
|
|
142
142
|
AS $$
|
|
143
143
|
BEGIN
|
|
144
144
|
EXECUTE 'DROP trigger IF EXISTS _200_tenant_environment on ' || schemaName || '.' || tableName || ';';
|
|
145
|
+
EXECUTE 'DROP trigger IF EXISTS _200_tenant_environment_on_delete on ' || schemaName || '.' || tableName || ';';
|
|
145
146
|
END;
|
|
146
147
|
$$;
|
|
147
148
|
|
|
@@ -162,6 +163,8 @@ BEGIN
|
|
|
162
163
|
PERFORM ax_define.drop_tenant_environment_trigger(tableName, schemaName);
|
|
163
164
|
EXECUTE 'CREATE trigger _200_tenant_environment BEFORE INSERT OR UPDATE ON ' || schemaName || '.' || tableName ||
|
|
164
165
|
' for each ROW EXECUTE PROCEDURE ax_utils.tg__tenant_environment();';
|
|
166
|
+
EXECUTE 'CREATE trigger _200_tenant_environment_on_delete BEFORE DELETE ON ' || schemaName || '.' || tableName ||
|
|
167
|
+
' for each ROW EXECUTE PROCEDURE ax_utils.tg__tenant_environment_on_delete();';
|
|
165
168
|
END;
|
|
166
169
|
$$;
|
|
167
170
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-db-common",
|
|
3
|
-
"version": "0.14.0
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "This library encapsulates database-related functionality to develop Mosaic based services.",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "0f2b502b5ab032e6430cf4dac79a54e346447a2f"
|
|
52
52
|
}
|