@colveor/core 1.2.1 → 1.3.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 +0 -7
- package/package.json +1 -1
- package/dist/database/migrations/1784284557960-audit-partitioning.d.ts +0 -17
- package/dist/database/migrations/1784284557960-audit-partitioning.d.ts.map +0 -1
- package/dist/database/migrations/1784284557960-audit-partitioning.js +0 -384
- package/dist/database/migrations/1784284557960-audit-partitioning.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
## [1.2.1](https://github.com/colveor/core/compare/v1.2.0...v1.2.1) (2026-07-30)
|
|
2
|
-
|
|
3
|
-
### Bug Fixes
|
|
4
|
-
|
|
5
|
-
* correct formatting in audit partitioning migration and test ([5cafb19](https://github.com/colveor/core/commit/5cafb19b790868a412a7d19bc637fcf0c4497532))
|
|
6
|
-
* restore audit_events partitioning after full-schema ([57fd535](https://github.com/colveor/core/commit/57fd5354e26f0137d1ebe1b543e29c34e280ac45))
|
|
7
|
-
|
|
8
1
|
## [1.2.0](https://github.com/colveor/core/compare/v1.1.0...v1.2.0) (2026-07-30)
|
|
9
2
|
|
|
10
3
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colveor/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "The core package of the Colveor ecosystem, providing reusable modules for authentication, user profiles, notifications, and shared application services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"colveor",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type MigrationInterface, type QueryRunner } from 'typeorm';
|
|
2
|
-
/**
|
|
3
|
-
* Post–full-schema audit hardening (TypeORM generate cannot emit this):
|
|
4
|
-
* - range-partition `audit_events` by `created_at`
|
|
5
|
-
* - SECURITY DEFINER legal_hold / purge / seal / partition helpers
|
|
6
|
-
* - ownership split + REVOKE UPDATE/DELETE when privileges allow
|
|
7
|
-
* - immutability trigger + `colveor_audit_owner` schema CREATE for monthly partitions
|
|
8
|
-
*
|
|
9
|
-
* Idempotent: if `audit_events` is already partitioned, conversion is skipped and
|
|
10
|
-
* helpers/grants are still (re)applied.
|
|
11
|
-
*/
|
|
12
|
-
export declare class AuditPartitioning1784284557960 implements MigrationInterface {
|
|
13
|
-
name: string;
|
|
14
|
-
up(queryRunner: QueryRunner): Promise<void>;
|
|
15
|
-
down(queryRunner: QueryRunner): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=1784284557960-audit-partitioning.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1784284557960-audit-partitioning.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/1784284557960-audit-partitioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpE;;;;;;;;;GASG;AACH,qBAAa,8BAA+B,YAAW,kBAAkB;IACxE,IAAI,SAAoC;IAE3B,EAAE,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAyX3C,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAgD1D"}
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuditPartitioning1784284557960 = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Post–full-schema audit hardening (TypeORM generate cannot emit this):
|
|
6
|
-
* - range-partition `audit_events` by `created_at`
|
|
7
|
-
* - SECURITY DEFINER legal_hold / purge / seal / partition helpers
|
|
8
|
-
* - ownership split + REVOKE UPDATE/DELETE when privileges allow
|
|
9
|
-
* - immutability trigger + `colveor_audit_owner` schema CREATE for monthly partitions
|
|
10
|
-
*
|
|
11
|
-
* Idempotent: if `audit_events` is already partitioned, conversion is skipped and
|
|
12
|
-
* helpers/grants are still (re)applied.
|
|
13
|
-
*/
|
|
14
|
-
class AuditPartitioning1784284557960 {
|
|
15
|
-
name = 'AuditPartitioning1784284557960';
|
|
16
|
-
async up(queryRunner) {
|
|
17
|
-
await queryRunner.query(`
|
|
18
|
-
CREATE OR REPLACE FUNCTION audit_events_immutable_guard()
|
|
19
|
-
RETURNS trigger
|
|
20
|
-
LANGUAGE plpgsql
|
|
21
|
-
AS $$
|
|
22
|
-
DECLARE
|
|
23
|
-
mode text := current_setting('app.audit_mutation', true);
|
|
24
|
-
BEGIN
|
|
25
|
-
IF TG_OP = 'DELETE' THEN
|
|
26
|
-
IF mode = 'purge' THEN
|
|
27
|
-
RETURN OLD;
|
|
28
|
-
END IF;
|
|
29
|
-
RAISE EXCEPTION 'audit_events is append-only (DELETE denied)';
|
|
30
|
-
END IF;
|
|
31
|
-
|
|
32
|
-
IF TG_OP = 'UPDATE' THEN
|
|
33
|
-
IF mode = 'legal_hold' THEN
|
|
34
|
-
IF NEW.id IS DISTINCT FROM OLD.id
|
|
35
|
-
OR NEW.created_at IS DISTINCT FROM OLD.created_at
|
|
36
|
-
OR NEW.actor_type IS DISTINCT FROM OLD.actor_type
|
|
37
|
-
OR NEW.actor_id IS DISTINCT FROM OLD.actor_id
|
|
38
|
-
OR NEW.action IS DISTINCT FROM OLD.action
|
|
39
|
-
OR NEW.resource_type IS DISTINCT FROM OLD.resource_type
|
|
40
|
-
OR NEW.resource_id IS DISTINCT FROM OLD.resource_id
|
|
41
|
-
OR NEW.status IS DISTINCT FROM OLD.status
|
|
42
|
-
OR NEW.metadata IS DISTINCT FROM OLD.metadata
|
|
43
|
-
OR NEW.ip_address IS DISTINCT FROM OLD.ip_address
|
|
44
|
-
OR NEW.device_info IS DISTINCT FROM OLD.device_info
|
|
45
|
-
OR NEW.request_id IS DISTINCT FROM OLD.request_id
|
|
46
|
-
OR NEW.correlation_id IS DISTINCT FROM OLD.correlation_id
|
|
47
|
-
OR NEW.trace_id IS DISTINCT FROM OLD.trace_id
|
|
48
|
-
OR NEW.chain_seq IS DISTINCT FROM OLD.chain_seq
|
|
49
|
-
OR NEW.event_hash IS DISTINCT FROM OLD.event_hash
|
|
50
|
-
OR NEW.prev_hash IS DISTINCT FROM OLD.prev_hash
|
|
51
|
-
THEN
|
|
52
|
-
RAISE EXCEPTION 'audit_events legal_hold mode may only toggle legal_hold';
|
|
53
|
-
END IF;
|
|
54
|
-
RETURN NEW;
|
|
55
|
-
END IF;
|
|
56
|
-
|
|
57
|
-
IF mode = 'seal' THEN
|
|
58
|
-
IF OLD.event_hash IS NOT NULL THEN
|
|
59
|
-
RAISE EXCEPTION 'audit_events seal mode only allowed when event_hash is null';
|
|
60
|
-
END IF;
|
|
61
|
-
IF NEW.id IS DISTINCT FROM OLD.id
|
|
62
|
-
OR NEW.created_at IS DISTINCT FROM OLD.created_at
|
|
63
|
-
OR NEW.actor_type IS DISTINCT FROM OLD.actor_type
|
|
64
|
-
OR NEW.actor_id IS DISTINCT FROM OLD.actor_id
|
|
65
|
-
OR NEW.action IS DISTINCT FROM OLD.action
|
|
66
|
-
OR NEW.resource_type IS DISTINCT FROM OLD.resource_type
|
|
67
|
-
OR NEW.resource_id IS DISTINCT FROM OLD.resource_id
|
|
68
|
-
OR NEW.status IS DISTINCT FROM OLD.status
|
|
69
|
-
OR NEW.metadata IS DISTINCT FROM OLD.metadata
|
|
70
|
-
OR NEW.ip_address IS DISTINCT FROM OLD.ip_address
|
|
71
|
-
OR NEW.device_info IS DISTINCT FROM OLD.device_info
|
|
72
|
-
OR NEW.request_id IS DISTINCT FROM OLD.request_id
|
|
73
|
-
OR NEW.correlation_id IS DISTINCT FROM OLD.correlation_id
|
|
74
|
-
OR NEW.trace_id IS DISTINCT FROM OLD.trace_id
|
|
75
|
-
OR NEW.chain_seq IS DISTINCT FROM OLD.chain_seq
|
|
76
|
-
OR NEW.legal_hold IS DISTINCT FROM OLD.legal_hold
|
|
77
|
-
THEN
|
|
78
|
-
RAISE EXCEPTION 'audit_events seal mode may only set event_hash/prev_hash';
|
|
79
|
-
END IF;
|
|
80
|
-
RETURN NEW;
|
|
81
|
-
END IF;
|
|
82
|
-
|
|
83
|
-
RAISE EXCEPTION 'audit_events is append-only (UPDATE denied)';
|
|
84
|
-
END IF;
|
|
85
|
-
|
|
86
|
-
RETURN NEW;
|
|
87
|
-
END;
|
|
88
|
-
$$
|
|
89
|
-
`);
|
|
90
|
-
// Drop helpers before rename so RETURN SETOF does not pin the old type.
|
|
91
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_set_legal_hold(uuid, boolean)`);
|
|
92
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_purge_ids(uuid[])`);
|
|
93
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_seal_hashes(uuid, varchar, varchar)`);
|
|
94
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_ensure_month_partition(date)`);
|
|
95
|
-
await queryRunner.query(`
|
|
96
|
-
DO $convert$
|
|
97
|
-
DECLARE
|
|
98
|
-
relkind "char";
|
|
99
|
-
start_month date;
|
|
100
|
-
end_month date;
|
|
101
|
-
cursor_month date;
|
|
102
|
-
part_name text;
|
|
103
|
-
from_ts timestamptz;
|
|
104
|
-
to_ts timestamptz;
|
|
105
|
-
BEGIN
|
|
106
|
-
SELECT c.relkind INTO relkind
|
|
107
|
-
FROM pg_class c
|
|
108
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
109
|
-
WHERE c.relname = 'audit_events' AND n.nspname = 'public';
|
|
110
|
-
|
|
111
|
-
IF relkind IS NULL THEN
|
|
112
|
-
RAISE EXCEPTION 'audit_events table does not exist; run full-schema first';
|
|
113
|
-
END IF;
|
|
114
|
-
|
|
115
|
-
-- Already partitioned — leave data/layout alone.
|
|
116
|
-
IF relkind = 'p' THEN
|
|
117
|
-
RETURN;
|
|
118
|
-
END IF;
|
|
119
|
-
|
|
120
|
-
ALTER TABLE audit_events RENAME TO audit_events_plain;
|
|
121
|
-
DROP TRIGGER IF EXISTS trg_audit_events_immutable ON audit_events_plain;
|
|
122
|
-
|
|
123
|
-
CREATE TABLE audit_events (
|
|
124
|
-
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
|
|
125
|
-
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
126
|
-
"actor_type" character varying(32) NOT NULL DEFAULT 'USER',
|
|
127
|
-
"actor_id" uuid,
|
|
128
|
-
"action" character varying(128) NOT NULL,
|
|
129
|
-
"resource_type" character varying(64),
|
|
130
|
-
"resource_id" character varying(128),
|
|
131
|
-
"status" character varying(16) NOT NULL DEFAULT 'SUCCESS',
|
|
132
|
-
"metadata" jsonb,
|
|
133
|
-
"ip_address" character varying(64),
|
|
134
|
-
"device_info" character varying(512),
|
|
135
|
-
"request_id" character varying(64),
|
|
136
|
-
"correlation_id" character varying(64),
|
|
137
|
-
"trace_id" character varying(64),
|
|
138
|
-
"chain_seq" bigint NOT NULL,
|
|
139
|
-
"event_hash" character varying(64),
|
|
140
|
-
"prev_hash" character varying(64),
|
|
141
|
-
"legal_hold" boolean NOT NULL DEFAULT false,
|
|
142
|
-
CONSTRAINT "PK_audit_events_id_created_at" PRIMARY KEY ("id", "created_at")
|
|
143
|
-
) PARTITION BY RANGE ("created_at");
|
|
144
|
-
|
|
145
|
-
SELECT date_trunc('month', COALESCE(MIN(created_at), now()))::date
|
|
146
|
-
INTO start_month
|
|
147
|
-
FROM audit_events_plain;
|
|
148
|
-
|
|
149
|
-
end_month := (date_trunc('month', now()) + interval '12 months')::date;
|
|
150
|
-
cursor_month := start_month;
|
|
151
|
-
|
|
152
|
-
WHILE cursor_month <= end_month LOOP
|
|
153
|
-
part_name := 'audit_events_' || to_char(cursor_month, 'YYYY_MM');
|
|
154
|
-
from_ts := cursor_month::timestamptz;
|
|
155
|
-
to_ts := (cursor_month + interval '1 month')::timestamptz;
|
|
156
|
-
EXECUTE format(
|
|
157
|
-
'CREATE TABLE IF NOT EXISTS %I PARTITION OF audit_events FOR VALUES FROM (%L) TO (%L)',
|
|
158
|
-
part_name,
|
|
159
|
-
from_ts,
|
|
160
|
-
to_ts
|
|
161
|
-
);
|
|
162
|
-
cursor_month := (cursor_month + interval '1 month')::date;
|
|
163
|
-
END LOOP;
|
|
164
|
-
|
|
165
|
-
CREATE TABLE IF NOT EXISTS audit_events_default PARTITION OF audit_events DEFAULT;
|
|
166
|
-
|
|
167
|
-
INSERT INTO audit_events (
|
|
168
|
-
id, created_at, actor_type, actor_id, action, resource_type, resource_id,
|
|
169
|
-
status, metadata, ip_address, device_info, request_id, correlation_id, trace_id,
|
|
170
|
-
chain_seq, event_hash, prev_hash, legal_hold
|
|
171
|
-
)
|
|
172
|
-
SELECT
|
|
173
|
-
id, created_at, actor_type, actor_id, action, resource_type, resource_id,
|
|
174
|
-
status, metadata, ip_address, device_info, request_id, correlation_id, trace_id,
|
|
175
|
-
chain_seq, event_hash, prev_hash, legal_hold
|
|
176
|
-
FROM audit_events_plain;
|
|
177
|
-
|
|
178
|
-
-- Detach sequence before DROP so OWNED BY does not cascade-drop it.
|
|
179
|
-
IF EXISTS (SELECT 1 FROM pg_class WHERE relname = 'audit_events_chain_seq_seq') THEN
|
|
180
|
-
ALTER SEQUENCE audit_events_chain_seq_seq OWNED BY NONE;
|
|
181
|
-
END IF;
|
|
182
|
-
|
|
183
|
-
DROP TABLE audit_events_plain;
|
|
184
|
-
END
|
|
185
|
-
$convert$
|
|
186
|
-
`);
|
|
187
|
-
await queryRunner.query(`
|
|
188
|
-
CREATE SEQUENCE IF NOT EXISTS audit_events_chain_seq_seq
|
|
189
|
-
`);
|
|
190
|
-
await queryRunner.query(`
|
|
191
|
-
SELECT setval(
|
|
192
|
-
'audit_events_chain_seq_seq',
|
|
193
|
-
GREATEST(COALESCE((SELECT MAX(chain_seq) FROM audit_events), 0), 1)
|
|
194
|
-
)
|
|
195
|
-
`);
|
|
196
|
-
await queryRunner.query(`
|
|
197
|
-
ALTER TABLE audit_events
|
|
198
|
-
ALTER COLUMN chain_seq SET DEFAULT nextval('audit_events_chain_seq_seq')
|
|
199
|
-
`);
|
|
200
|
-
await queryRunner.query(`ALTER SEQUENCE audit_events_chain_seq_seq OWNED BY audit_events.chain_seq`);
|
|
201
|
-
await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "UQ_audit_events_chain_seq_created"
|
|
202
|
-
ON audit_events ("chain_seq", "created_at")`);
|
|
203
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_actor_type" ON audit_events ("actor_type")`);
|
|
204
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_actor_id" ON audit_events ("actor_id")`);
|
|
205
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_action" ON audit_events ("action")`);
|
|
206
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_resource_id" ON audit_events ("resource_id")`);
|
|
207
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_created_at" ON audit_events ("created_at")`);
|
|
208
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_correlation_id" ON audit_events ("correlation_id")`);
|
|
209
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_legal_hold" ON audit_events ("legal_hold") WHERE legal_hold = true`);
|
|
210
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_created_at_brin" ON audit_events USING BRIN ("created_at")`);
|
|
211
|
-
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_chain_seq" ON audit_events ("chain_seq")`);
|
|
212
|
-
await queryRunner.query(`DROP TRIGGER IF EXISTS trg_audit_events_immutable ON audit_events`);
|
|
213
|
-
await queryRunner.query(`
|
|
214
|
-
CREATE TRIGGER trg_audit_events_immutable
|
|
215
|
-
BEFORE UPDATE OR DELETE ON audit_events
|
|
216
|
-
FOR EACH ROW
|
|
217
|
-
EXECUTE PROCEDURE audit_events_immutable_guard()
|
|
218
|
-
`);
|
|
219
|
-
await queryRunner.query(`
|
|
220
|
-
CREATE OR REPLACE FUNCTION audit_set_legal_hold(p_id uuid, p_hold boolean)
|
|
221
|
-
RETURNS SETOF audit_events
|
|
222
|
-
LANGUAGE plpgsql
|
|
223
|
-
SECURITY DEFINER
|
|
224
|
-
SET search_path = public
|
|
225
|
-
AS $$
|
|
226
|
-
BEGIN
|
|
227
|
-
PERFORM set_config('app.audit_mutation', 'legal_hold', true);
|
|
228
|
-
RETURN QUERY
|
|
229
|
-
UPDATE audit_events
|
|
230
|
-
SET legal_hold = p_hold
|
|
231
|
-
WHERE id = p_id
|
|
232
|
-
RETURNING *;
|
|
233
|
-
END;
|
|
234
|
-
$$
|
|
235
|
-
`);
|
|
236
|
-
await queryRunner.query(`
|
|
237
|
-
CREATE OR REPLACE FUNCTION audit_purge_ids(p_ids uuid[])
|
|
238
|
-
RETURNS integer
|
|
239
|
-
LANGUAGE plpgsql
|
|
240
|
-
SECURITY DEFINER
|
|
241
|
-
SET search_path = public
|
|
242
|
-
AS $$
|
|
243
|
-
DECLARE
|
|
244
|
-
deleted integer;
|
|
245
|
-
BEGIN
|
|
246
|
-
PERFORM set_config('app.audit_mutation', 'purge', true);
|
|
247
|
-
DELETE FROM audit_events
|
|
248
|
-
WHERE id = ANY(p_ids)
|
|
249
|
-
AND legal_hold = false;
|
|
250
|
-
GET DIAGNOSTICS deleted = ROW_COUNT;
|
|
251
|
-
RETURN deleted;
|
|
252
|
-
END;
|
|
253
|
-
$$
|
|
254
|
-
`);
|
|
255
|
-
await queryRunner.query(`
|
|
256
|
-
CREATE OR REPLACE FUNCTION audit_seal_hashes(
|
|
257
|
-
p_id uuid,
|
|
258
|
-
p_event_hash varchar,
|
|
259
|
-
p_prev_hash varchar
|
|
260
|
-
)
|
|
261
|
-
RETURNS void
|
|
262
|
-
LANGUAGE plpgsql
|
|
263
|
-
SECURITY DEFINER
|
|
264
|
-
SET search_path = public
|
|
265
|
-
AS $$
|
|
266
|
-
BEGIN
|
|
267
|
-
PERFORM set_config('app.audit_mutation', 'seal', true);
|
|
268
|
-
UPDATE audit_events
|
|
269
|
-
SET event_hash = p_event_hash,
|
|
270
|
-
prev_hash = p_prev_hash
|
|
271
|
-
WHERE id = p_id
|
|
272
|
-
AND event_hash IS NULL;
|
|
273
|
-
END;
|
|
274
|
-
$$
|
|
275
|
-
`);
|
|
276
|
-
await queryRunner.query(`
|
|
277
|
-
CREATE OR REPLACE FUNCTION audit_ensure_month_partition(p_month date)
|
|
278
|
-
RETURNS void
|
|
279
|
-
LANGUAGE plpgsql
|
|
280
|
-
SECURITY DEFINER
|
|
281
|
-
SET search_path = public
|
|
282
|
-
AS $$
|
|
283
|
-
DECLARE
|
|
284
|
-
part_name text;
|
|
285
|
-
from_ts timestamptz;
|
|
286
|
-
to_ts timestamptz;
|
|
287
|
-
month_start date := date_trunc('month', p_month)::date;
|
|
288
|
-
BEGIN
|
|
289
|
-
part_name := 'audit_events_' || to_char(month_start, 'YYYY_MM');
|
|
290
|
-
from_ts := month_start::timestamptz;
|
|
291
|
-
to_ts := (month_start + interval '1 month')::timestamptz;
|
|
292
|
-
EXECUTE format(
|
|
293
|
-
'CREATE TABLE IF NOT EXISTS %I PARTITION OF audit_events FOR VALUES FROM (%L) TO (%L)',
|
|
294
|
-
part_name,
|
|
295
|
-
from_ts,
|
|
296
|
-
to_ts
|
|
297
|
-
);
|
|
298
|
-
END;
|
|
299
|
-
$$
|
|
300
|
-
`);
|
|
301
|
-
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_set_legal_hold(uuid, boolean) FROM PUBLIC`);
|
|
302
|
-
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_purge_ids(uuid[]) FROM PUBLIC`);
|
|
303
|
-
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_seal_hashes(uuid, varchar, varchar) FROM PUBLIC`);
|
|
304
|
-
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_ensure_month_partition(date) FROM PUBLIC`);
|
|
305
|
-
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_set_legal_hold(uuid, boolean) TO CURRENT_USER`);
|
|
306
|
-
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_purge_ids(uuid[]) TO CURRENT_USER`);
|
|
307
|
-
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_seal_hashes(uuid, varchar, varchar) TO CURRENT_USER`);
|
|
308
|
-
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_ensure_month_partition(date) TO CURRENT_USER`);
|
|
309
|
-
await queryRunner.query(`
|
|
310
|
-
DO $body$
|
|
311
|
-
BEGIN
|
|
312
|
-
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'colveor_audit_owner') THEN
|
|
313
|
-
CREATE ROLE colveor_audit_owner NOLOGIN;
|
|
314
|
-
END IF;
|
|
315
|
-
|
|
316
|
-
ALTER TABLE audit_events OWNER TO colveor_audit_owner;
|
|
317
|
-
ALTER TABLE audit_outbox OWNER TO colveor_audit_owner;
|
|
318
|
-
ALTER FUNCTION audit_events_immutable_guard() OWNER TO colveor_audit_owner;
|
|
319
|
-
ALTER FUNCTION audit_set_legal_hold(uuid, boolean) OWNER TO colveor_audit_owner;
|
|
320
|
-
ALTER FUNCTION audit_purge_ids(uuid[]) OWNER TO colveor_audit_owner;
|
|
321
|
-
ALTER FUNCTION audit_seal_hashes(uuid, varchar, varchar) OWNER TO colveor_audit_owner;
|
|
322
|
-
ALTER FUNCTION audit_ensure_month_partition(date) OWNER TO colveor_audit_owner;
|
|
323
|
-
IF EXISTS (SELECT 1 FROM pg_class WHERE relname = 'audit_events_chain_seq_seq') THEN
|
|
324
|
-
ALTER SEQUENCE audit_events_chain_seq_seq OWNER TO colveor_audit_owner;
|
|
325
|
-
END IF;
|
|
326
|
-
|
|
327
|
-
REVOKE ALL ON TABLE audit_events FROM PUBLIC;
|
|
328
|
-
REVOKE UPDATE, DELETE ON TABLE audit_events FROM CURRENT_USER;
|
|
329
|
-
GRANT SELECT, INSERT ON TABLE audit_events TO CURRENT_USER;
|
|
330
|
-
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE audit_outbox TO CURRENT_USER;
|
|
331
|
-
GRANT USAGE, SELECT ON SEQUENCE audit_events_chain_seq_seq TO CURRENT_USER;
|
|
332
|
-
|
|
333
|
-
GRANT USAGE, CREATE ON SCHEMA public TO colveor_audit_owner;
|
|
334
|
-
EXCEPTION
|
|
335
|
-
WHEN insufficient_privilege OR invalid_grantor OR undefined_object THEN
|
|
336
|
-
RAISE NOTICE 'audit ownership/REVOKE skipped: %', SQLERRM;
|
|
337
|
-
END
|
|
338
|
-
$body$
|
|
339
|
-
`);
|
|
340
|
-
}
|
|
341
|
-
async down(queryRunner) {
|
|
342
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_ensure_month_partition(date)`);
|
|
343
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_seal_hashes(uuid, varchar, varchar)`);
|
|
344
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_purge_ids(uuid[])`);
|
|
345
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_set_legal_hold(uuid, boolean)`);
|
|
346
|
-
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_events_immutable_guard() CASCADE`);
|
|
347
|
-
await queryRunner.query(`CREATE TABLE audit_events_merged (LIKE audit_events INCLUDING DEFAULTS INCLUDING CONSTRAINTS)`);
|
|
348
|
-
await queryRunner.query(`INSERT INTO audit_events_merged SELECT * FROM audit_events`);
|
|
349
|
-
await queryRunner.query(`DROP TABLE audit_events`);
|
|
350
|
-
await queryRunner.query(`ALTER TABLE audit_events_merged RENAME TO audit_events`);
|
|
351
|
-
// Restore composite PK shape expected by full-schema / entities.
|
|
352
|
-
await queryRunner.query(`
|
|
353
|
-
ALTER TABLE audit_events
|
|
354
|
-
DROP CONSTRAINT IF EXISTS "PK_audit_events_id_created_at"
|
|
355
|
-
`);
|
|
356
|
-
await queryRunner.query(`
|
|
357
|
-
DO $pk$
|
|
358
|
-
BEGIN
|
|
359
|
-
IF NOT EXISTS (
|
|
360
|
-
SELECT 1 FROM pg_constraint
|
|
361
|
-
WHERE conrelid = 'audit_events'::regclass AND contype = 'p'
|
|
362
|
-
) THEN
|
|
363
|
-
ALTER TABLE audit_events
|
|
364
|
-
ADD CONSTRAINT "PK_7a893600893f8f5086bffa23f2b" PRIMARY KEY ("id", "created_at");
|
|
365
|
-
END IF;
|
|
366
|
-
END
|
|
367
|
-
$pk$
|
|
368
|
-
`);
|
|
369
|
-
await queryRunner.query(`
|
|
370
|
-
DO $body$
|
|
371
|
-
BEGIN
|
|
372
|
-
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'colveor_audit_owner') THEN
|
|
373
|
-
REVOKE CREATE ON SCHEMA public FROM colveor_audit_owner;
|
|
374
|
-
END IF;
|
|
375
|
-
EXCEPTION
|
|
376
|
-
WHEN insufficient_privilege OR undefined_object THEN
|
|
377
|
-
RAISE NOTICE 'audit owner schema revoke skipped: %', SQLERRM;
|
|
378
|
-
END
|
|
379
|
-
$body$
|
|
380
|
-
`);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
exports.AuditPartitioning1784284557960 = AuditPartitioning1784284557960;
|
|
384
|
-
//# sourceMappingURL=1784284557960-audit-partitioning.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1784284557960-audit-partitioning.js","sourceRoot":"","sources":["../../../src/database/migrations/1784284557960-audit-partitioning.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;GASG;AACH,MAAa,8BAA8B;IAC1C,IAAI,GAAG,gCAAgC,CAAC;IAEjC,KAAK,CAAC,EAAE,CAAC,WAAwB;QACvC,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;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