@openpeepshq/core 0.28.0 → 0.29.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.
@@ -0,0 +1,27 @@
1
+ import type { AuditLogRow } from '../db/pg/schema';
2
+ export interface ListAuditEntriesOptions {
3
+ /**
4
+ * Cursor: only entries strictly older than `(before, beforeId)`.
5
+ * `before` is the `created_at` (ISO string) and `beforeId` is the `id` of
6
+ * the last row of the previous page; both are used together so that rows
7
+ * tying on `created_at` with the boundary row are not skipped. `before`
8
+ * alone (no `beforeId`) degrades to "older than this timestamp".
9
+ */
10
+ before?: string;
11
+ beforeId?: string;
12
+ limit?: number;
13
+ actorProfileId?: string;
14
+ targetType?: string;
15
+ targetId?: string;
16
+ }
17
+ /**
18
+ * Newest-first, cursor-paginated listing. `before` is the `created_at` of the
19
+ * last row of the previous page ("older page"); rows are immutable, and tied
20
+ * timestamps are ordered by `id desc` for deterministic pages.
21
+ *
22
+ * `limit` is clamped defensively with an explicit `Number()` so the bound
23
+ * holds whether the value arrived as a number or a numeric string (the direct
24
+ * `.handle()` call path bypasses Riddl's query coercion, which a real request
25
+ * would have already applied).
26
+ */
27
+ export declare const listAuditEntries: (options?: ListAuditEntriesOptions) => Promise<AuditLogRow[]>;
@@ -0,0 +1,40 @@
1
+ import { and, desc, eq, lt, or } from 'drizzle-orm';
2
+ import { auditLogs } from '../db/pg/schema/index.js';
3
+ import { allpeepDb } from '../db/index.js';
4
+ const DEFAULT_LIMIT = 100;
5
+ const MAX_LIMIT = 1000;
6
+ /**
7
+ * Newest-first, cursor-paginated listing. `before` is the `created_at` of the
8
+ * last row of the previous page ("older page"); rows are immutable, and tied
9
+ * timestamps are ordered by `id desc` for deterministic pages.
10
+ *
11
+ * `limit` is clamped defensively with an explicit `Number()` so the bound
12
+ * holds whether the value arrived as a number or a numeric string (the direct
13
+ * `.handle()` call path bypasses Riddl's query coercion, which a real request
14
+ * would have already applied).
15
+ */
16
+ export const listAuditEntries = async (options = {}) => {
17
+ const limit = Math.min(Math.max(Number(options.limit ?? DEFAULT_LIMIT), 1), MAX_LIMIT);
18
+ const cursor = options.before && options.beforeId
19
+ ? or(lt(auditLogs.createdAt, options.before), and(eq(auditLogs.createdAt, options.before), lt(auditLogs.id, options.beforeId)))
20
+ : options.before
21
+ ? lt(auditLogs.createdAt, options.before)
22
+ : undefined;
23
+ const conditions = [
24
+ cursor,
25
+ options.actorProfileId
26
+ ? eq(auditLogs.actorProfileId, options.actorProfileId)
27
+ : undefined,
28
+ options.targetType
29
+ ? eq(auditLogs.targetType, options.targetType)
30
+ : undefined,
31
+ options.targetId ? eq(auditLogs.targetId, options.targetId) : undefined,
32
+ ].filter(Boolean);
33
+ const { db } = await allpeepDb();
34
+ return db
35
+ .select()
36
+ .from(auditLogs)
37
+ .where(conditions.length ? and(...conditions) : undefined)
38
+ .orderBy(desc(auditLogs.createdAt), desc(auditLogs.id))
39
+ .limit(limit);
40
+ };
@@ -0,0 +1,3 @@
1
+ export * from './mapping';
2
+ export * from './mutations';
3
+ export * from './finders';
@@ -0,0 +1,3 @@
1
+ export * from './mapping.js';
2
+ export * from './mutations.js';
3
+ export * from './finders.js';
@@ -0,0 +1,4 @@
1
+ import type { AuditLogEntry } from '@openpeepshq/common/types';
2
+ import type { AuditLogRow } from '../db/pg/schema';
3
+ export declare const mapAuditLogRow: (row: AuditLogRow) => AuditLogEntry;
4
+ export declare const mapAuditLogRows: (rows: AuditLogRow[]) => AuditLogEntry[];
@@ -0,0 +1,18 @@
1
+ import { normalizeIsoDatetime } from '../db/pg/mappers.js';
2
+ export const mapAuditLogRow = (row) => ({
3
+ id: row.id,
4
+ actorProfileId: row.actorProfileId,
5
+ actorAccountId: row.actorAccountId,
6
+ actorIp: row.actorIp,
7
+ action: row.action,
8
+ targetType: row.targetType,
9
+ targetId: row.targetId,
10
+ targetLabel: row.targetLabel,
11
+ // `jsonb` columns have no type mode, so drizzle infers `unknown` on read.
12
+ metadata: row.metadata,
13
+ // The pg driver returns timestamptz as an offset string
14
+ // (`"2026-11-26 12:00:00.123+00"`); normalize to ISO UTC so the
15
+ // `z.string().datetime()` output schemas accept it.
16
+ createdAt: normalizeIsoDatetime(row.createdAt),
17
+ });
18
+ export const mapAuditLogRows = (rows) => rows.map(mapAuditLogRow);
@@ -0,0 +1,42 @@
1
+ import type { ProfileWithMeta } from '@openpeepshq/common/types';
2
+ export interface AuditEntryData {
3
+ /** Id of the profile performing the action. */
4
+ actorProfileId: string;
5
+ actorAccountId?: string | null;
6
+ actorIp?: string | null;
7
+ /** e.g. `profile.delete`, `report.resolve`, `role.update`. */
8
+ action: string;
9
+ /** e.g. `profile`, `account`, `report`, `role`, `group`. */
10
+ targetType: string;
11
+ targetId?: string | null;
12
+ /** Human-readable target detail (handle, email, role key…). */
13
+ targetLabel?: string | null;
14
+ /** Action-specific detail; never credentials or full request bodies. */
15
+ metadata?: Record<string, unknown> | null;
16
+ }
17
+ /** Plain insert — throws on failure. */
18
+ export declare const createAuditEntry: (data: AuditEntryData) => Promise<{
19
+ id: string;
20
+ metadata: unknown;
21
+ createdAt: string;
22
+ actorProfileId: string;
23
+ actorAccountId: string | null;
24
+ actorIp: string | null;
25
+ action: string;
26
+ targetType: string;
27
+ targetId: string | null;
28
+ targetLabel: string | null;
29
+ }>;
30
+ export interface AuditContext {
31
+ /** The actor (already loaded by the auth middleware). */
32
+ profile?: ProfileWithMeta | null;
33
+ /** Client IP at request time (behind the TLS proxy: first XFF hop). */
34
+ ip?: string | null;
35
+ }
36
+ /**
37
+ * Fire-and-forget audit write: resolves the actor (profile + owning
38
+ * account), inserts one row and swallows its own errors. A failed audit
39
+ * write must never fail the admin action that triggered it — it is logged
40
+ * as a server error.
41
+ */
42
+ export declare const recordAuditEntry: (data: Omit<AuditEntryData, "actorAccountId" | "actorProfileId" | "actorIp"> & Partial<Pick<AuditEntryData, "actorProfileId">>, ctx: AuditContext) => Promise<void>;
@@ -0,0 +1,43 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { auditLogs } from '../db/pg/schema/index.js';
3
+ import { allpeepDb } from '../db/index.js';
4
+ import { logger } from '../log/index.js';
5
+ const log = logger('auditLog');
6
+ /** Plain insert — throws on failure. */
7
+ export const createAuditEntry = async (data) => {
8
+ const { db } = await allpeepDb();
9
+ const [row] = await db
10
+ .insert(auditLogs)
11
+ .values({
12
+ id: randomUUID(),
13
+ actorProfileId: data.actorProfileId,
14
+ actorAccountId: data.actorAccountId ?? null,
15
+ actorIp: data.actorIp ?? null,
16
+ action: data.action,
17
+ targetType: data.targetType,
18
+ targetId: data.targetId ?? null,
19
+ targetLabel: data.targetLabel ?? null,
20
+ metadata: data.metadata ?? null,
21
+ })
22
+ .returning();
23
+ return row;
24
+ };
25
+ /**
26
+ * Fire-and-forget audit write: resolves the actor (profile + owning
27
+ * account), inserts one row and swallows its own errors. A failed audit
28
+ * write must never fail the admin action that triggered it — it is logged
29
+ * as a server error.
30
+ */
31
+ export const recordAuditEntry = async (data, ctx) => {
32
+ try {
33
+ await createAuditEntry({
34
+ actorProfileId: data.actorProfileId ?? ctx.profile?.id ?? '',
35
+ actorAccountId: ctx.profile?.controllers?.[0]?.id ?? null,
36
+ actorIp: ctx.ip ?? null,
37
+ ...data,
38
+ });
39
+ }
40
+ catch (error) {
41
+ log.error('audit entry write failed:', error);
42
+ }
43
+ };
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Immutable audit trail of admin actions (user-data and moderation).
3
+ * Rows are append-only: no `updated_at`/`deleted_at`, and there is no
4
+ * retention job — the log is kept indefinitely.
5
+ */
6
+ export declare const auditLogs: import("drizzle-orm/pg-core").PgTableWithColumns<{
7
+ name: "audit_logs";
8
+ schema: undefined;
9
+ columns: {
10
+ id: import("drizzle-orm/pg-core").PgColumn<{
11
+ name: "id";
12
+ tableName: "audit_logs";
13
+ dataType: "string";
14
+ columnType: "PgUUID";
15
+ data: string;
16
+ driverParam: string;
17
+ notNull: true;
18
+ hasDefault: false;
19
+ isPrimaryKey: true;
20
+ isAutoincrement: false;
21
+ hasRuntimeDefault: false;
22
+ enumValues: undefined;
23
+ baseColumn: never;
24
+ identity: undefined;
25
+ generated: undefined;
26
+ }, {}, {}>;
27
+ actorProfileId: import("drizzle-orm/pg-core").PgColumn<{
28
+ name: "actor_profile_id";
29
+ tableName: "audit_logs";
30
+ dataType: "string";
31
+ columnType: "PgText";
32
+ data: string;
33
+ driverParam: string;
34
+ notNull: true;
35
+ hasDefault: false;
36
+ isPrimaryKey: false;
37
+ isAutoincrement: false;
38
+ hasRuntimeDefault: false;
39
+ enumValues: [string, ...string[]];
40
+ baseColumn: never;
41
+ identity: undefined;
42
+ generated: undefined;
43
+ }, {}, {}>;
44
+ actorAccountId: import("drizzle-orm/pg-core").PgColumn<{
45
+ name: "actor_account_id";
46
+ tableName: "audit_logs";
47
+ dataType: "string";
48
+ columnType: "PgText";
49
+ data: string;
50
+ driverParam: string;
51
+ notNull: false;
52
+ hasDefault: false;
53
+ isPrimaryKey: false;
54
+ isAutoincrement: false;
55
+ hasRuntimeDefault: false;
56
+ enumValues: [string, ...string[]];
57
+ baseColumn: never;
58
+ identity: undefined;
59
+ generated: undefined;
60
+ }, {}, {}>;
61
+ actorIp: import("drizzle-orm/pg-core").PgColumn<{
62
+ name: "actor_ip";
63
+ tableName: "audit_logs";
64
+ dataType: "string";
65
+ columnType: "PgText";
66
+ data: string;
67
+ driverParam: string;
68
+ notNull: false;
69
+ hasDefault: false;
70
+ isPrimaryKey: false;
71
+ isAutoincrement: false;
72
+ hasRuntimeDefault: false;
73
+ enumValues: [string, ...string[]];
74
+ baseColumn: never;
75
+ identity: undefined;
76
+ generated: undefined;
77
+ }, {}, {}>;
78
+ action: import("drizzle-orm/pg-core").PgColumn<{
79
+ name: "action";
80
+ tableName: "audit_logs";
81
+ dataType: "string";
82
+ columnType: "PgText";
83
+ data: string;
84
+ driverParam: string;
85
+ notNull: true;
86
+ hasDefault: false;
87
+ isPrimaryKey: false;
88
+ isAutoincrement: false;
89
+ hasRuntimeDefault: false;
90
+ enumValues: [string, ...string[]];
91
+ baseColumn: never;
92
+ identity: undefined;
93
+ generated: undefined;
94
+ }, {}, {}>;
95
+ targetType: import("drizzle-orm/pg-core").PgColumn<{
96
+ name: "target_type";
97
+ tableName: "audit_logs";
98
+ dataType: "string";
99
+ columnType: "PgText";
100
+ data: string;
101
+ driverParam: string;
102
+ notNull: true;
103
+ hasDefault: false;
104
+ isPrimaryKey: false;
105
+ isAutoincrement: false;
106
+ hasRuntimeDefault: false;
107
+ enumValues: [string, ...string[]];
108
+ baseColumn: never;
109
+ identity: undefined;
110
+ generated: undefined;
111
+ }, {}, {}>;
112
+ targetId: import("drizzle-orm/pg-core").PgColumn<{
113
+ name: "target_id";
114
+ tableName: "audit_logs";
115
+ dataType: "string";
116
+ columnType: "PgText";
117
+ data: string;
118
+ driverParam: string;
119
+ notNull: false;
120
+ hasDefault: false;
121
+ isPrimaryKey: false;
122
+ isAutoincrement: false;
123
+ hasRuntimeDefault: false;
124
+ enumValues: [string, ...string[]];
125
+ baseColumn: never;
126
+ identity: undefined;
127
+ generated: undefined;
128
+ }, {}, {}>;
129
+ targetLabel: import("drizzle-orm/pg-core").PgColumn<{
130
+ name: "target_label";
131
+ tableName: "audit_logs";
132
+ dataType: "string";
133
+ columnType: "PgText";
134
+ data: string;
135
+ driverParam: string;
136
+ notNull: false;
137
+ hasDefault: false;
138
+ isPrimaryKey: false;
139
+ isAutoincrement: false;
140
+ hasRuntimeDefault: false;
141
+ enumValues: [string, ...string[]];
142
+ baseColumn: never;
143
+ identity: undefined;
144
+ generated: undefined;
145
+ }, {}, {}>;
146
+ metadata: import("drizzle-orm/pg-core").PgColumn<{
147
+ name: "metadata";
148
+ tableName: "audit_logs";
149
+ dataType: "json";
150
+ columnType: "PgJsonb";
151
+ data: unknown;
152
+ driverParam: unknown;
153
+ notNull: false;
154
+ hasDefault: false;
155
+ isPrimaryKey: false;
156
+ isAutoincrement: false;
157
+ hasRuntimeDefault: false;
158
+ enumValues: undefined;
159
+ baseColumn: never;
160
+ identity: undefined;
161
+ generated: undefined;
162
+ }, {}, {}>;
163
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
164
+ name: "created_at";
165
+ tableName: "audit_logs";
166
+ dataType: "string";
167
+ columnType: "PgTimestampString";
168
+ data: string;
169
+ driverParam: string;
170
+ notNull: true;
171
+ hasDefault: true;
172
+ isPrimaryKey: false;
173
+ isAutoincrement: false;
174
+ hasRuntimeDefault: false;
175
+ enumValues: undefined;
176
+ baseColumn: never;
177
+ identity: undefined;
178
+ generated: undefined;
179
+ }, {}, {}>;
180
+ };
181
+ dialect: "pg";
182
+ }>;
183
+ export type AuditLogRow = typeof auditLogs.$inferSelect;
@@ -0,0 +1,30 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { index, jsonb, pgTable, text, timestamp } from 'drizzle-orm/pg-core';
3
+ import { idColumn } from './base.js';
4
+ /**
5
+ * Immutable audit trail of admin actions (user-data and moderation).
6
+ * Rows are append-only: no `updated_at`/`deleted_at`, and there is no
7
+ * retention job — the log is kept indefinitely.
8
+ */
9
+ export const auditLogs = pgTable('audit_logs', {
10
+ id: idColumn(),
11
+ actorProfileId: text('actor_profile_id').notNull(),
12
+ actorAccountId: text('actor_account_id'),
13
+ // Stores the client-supplied `X-Forwarded-For` value at write time (see
14
+ // `clientIp`). It is not verified against the proxy and rows are
15
+ // immutable, so treat `actor_ip` as untrusted provenance — a client can
16
+ // set it arbitrarily before the TLS proxy.
17
+ actorIp: text('actor_ip'),
18
+ action: text('action').notNull(),
19
+ targetType: text('target_type').notNull(),
20
+ targetId: text('target_id'),
21
+ targetLabel: text('target_label'),
22
+ metadata: jsonb('metadata'),
23
+ createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' })
24
+ .notNull()
25
+ .default(sql `now()`),
26
+ }, (table) => [
27
+ index('audit_logs_created_at_idx').on(table.createdAt.desc()),
28
+ index('audit_logs_actor_profile_idx').on(table.actorProfileId),
29
+ index('audit_logs_target_idx').on(table.targetType, table.targetId),
30
+ ]);
@@ -2,7 +2,185 @@ export * from './documents';
2
2
  export * from './edges';
3
3
  export * from './analytics';
4
4
  export * from './calendarFeedTokens';
5
+ export * from './auditLogs';
5
6
  export declare const schema: {
7
+ auditLogs: import("drizzle-orm/pg-core").PgTableWithColumns<{
8
+ name: "audit_logs";
9
+ schema: undefined;
10
+ columns: {
11
+ id: import("drizzle-orm/pg-core").PgColumn<{
12
+ name: "id";
13
+ tableName: "audit_logs";
14
+ dataType: "string";
15
+ columnType: "PgUUID";
16
+ data: string;
17
+ driverParam: string;
18
+ notNull: true;
19
+ hasDefault: false;
20
+ isPrimaryKey: true;
21
+ isAutoincrement: false;
22
+ hasRuntimeDefault: false;
23
+ enumValues: undefined;
24
+ baseColumn: never;
25
+ identity: undefined;
26
+ generated: undefined;
27
+ }, {}, {}>;
28
+ actorProfileId: import("drizzle-orm/pg-core").PgColumn<{
29
+ name: "actor_profile_id";
30
+ tableName: "audit_logs";
31
+ dataType: "string";
32
+ columnType: "PgText";
33
+ data: string;
34
+ driverParam: string;
35
+ notNull: true;
36
+ hasDefault: false;
37
+ isPrimaryKey: false;
38
+ isAutoincrement: false;
39
+ hasRuntimeDefault: false;
40
+ enumValues: [string, ...string[]];
41
+ baseColumn: never;
42
+ identity: undefined;
43
+ generated: undefined;
44
+ }, {}, {}>;
45
+ actorAccountId: import("drizzle-orm/pg-core").PgColumn<{
46
+ name: "actor_account_id";
47
+ tableName: "audit_logs";
48
+ dataType: "string";
49
+ columnType: "PgText";
50
+ data: string;
51
+ driverParam: string;
52
+ notNull: false;
53
+ hasDefault: false;
54
+ isPrimaryKey: false;
55
+ isAutoincrement: false;
56
+ hasRuntimeDefault: false;
57
+ enumValues: [string, ...string[]];
58
+ baseColumn: never;
59
+ identity: undefined;
60
+ generated: undefined;
61
+ }, {}, {}>;
62
+ actorIp: import("drizzle-orm/pg-core").PgColumn<{
63
+ name: "actor_ip";
64
+ tableName: "audit_logs";
65
+ dataType: "string";
66
+ columnType: "PgText";
67
+ data: string;
68
+ driverParam: string;
69
+ notNull: false;
70
+ hasDefault: false;
71
+ isPrimaryKey: false;
72
+ isAutoincrement: false;
73
+ hasRuntimeDefault: false;
74
+ enumValues: [string, ...string[]];
75
+ baseColumn: never;
76
+ identity: undefined;
77
+ generated: undefined;
78
+ }, {}, {}>;
79
+ action: import("drizzle-orm/pg-core").PgColumn<{
80
+ name: "action";
81
+ tableName: "audit_logs";
82
+ dataType: "string";
83
+ columnType: "PgText";
84
+ data: string;
85
+ driverParam: string;
86
+ notNull: true;
87
+ hasDefault: false;
88
+ isPrimaryKey: false;
89
+ isAutoincrement: false;
90
+ hasRuntimeDefault: false;
91
+ enumValues: [string, ...string[]];
92
+ baseColumn: never;
93
+ identity: undefined;
94
+ generated: undefined;
95
+ }, {}, {}>;
96
+ targetType: import("drizzle-orm/pg-core").PgColumn<{
97
+ name: "target_type";
98
+ tableName: "audit_logs";
99
+ dataType: "string";
100
+ columnType: "PgText";
101
+ data: string;
102
+ driverParam: string;
103
+ notNull: true;
104
+ hasDefault: false;
105
+ isPrimaryKey: false;
106
+ isAutoincrement: false;
107
+ hasRuntimeDefault: false;
108
+ enumValues: [string, ...string[]];
109
+ baseColumn: never;
110
+ identity: undefined;
111
+ generated: undefined;
112
+ }, {}, {}>;
113
+ targetId: import("drizzle-orm/pg-core").PgColumn<{
114
+ name: "target_id";
115
+ tableName: "audit_logs";
116
+ dataType: "string";
117
+ columnType: "PgText";
118
+ data: string;
119
+ driverParam: string;
120
+ notNull: false;
121
+ hasDefault: false;
122
+ isPrimaryKey: false;
123
+ isAutoincrement: false;
124
+ hasRuntimeDefault: false;
125
+ enumValues: [string, ...string[]];
126
+ baseColumn: never;
127
+ identity: undefined;
128
+ generated: undefined;
129
+ }, {}, {}>;
130
+ targetLabel: import("drizzle-orm/pg-core").PgColumn<{
131
+ name: "target_label";
132
+ tableName: "audit_logs";
133
+ dataType: "string";
134
+ columnType: "PgText";
135
+ data: string;
136
+ driverParam: string;
137
+ notNull: false;
138
+ hasDefault: false;
139
+ isPrimaryKey: false;
140
+ isAutoincrement: false;
141
+ hasRuntimeDefault: false;
142
+ enumValues: [string, ...string[]];
143
+ baseColumn: never;
144
+ identity: undefined;
145
+ generated: undefined;
146
+ }, {}, {}>;
147
+ metadata: import("drizzle-orm/pg-core").PgColumn<{
148
+ name: "metadata";
149
+ tableName: "audit_logs";
150
+ dataType: "json";
151
+ columnType: "PgJsonb";
152
+ data: unknown;
153
+ driverParam: unknown;
154
+ notNull: false;
155
+ hasDefault: false;
156
+ isPrimaryKey: false;
157
+ isAutoincrement: false;
158
+ hasRuntimeDefault: false;
159
+ enumValues: undefined;
160
+ baseColumn: never;
161
+ identity: undefined;
162
+ generated: undefined;
163
+ }, {}, {}>;
164
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
165
+ name: "created_at";
166
+ tableName: "audit_logs";
167
+ dataType: "string";
168
+ columnType: "PgTimestampString";
169
+ data: string;
170
+ driverParam: string;
171
+ notNull: true;
172
+ hasDefault: true;
173
+ isPrimaryKey: false;
174
+ isAutoincrement: false;
175
+ hasRuntimeDefault: false;
176
+ enumValues: undefined;
177
+ baseColumn: never;
178
+ identity: undefined;
179
+ generated: undefined;
180
+ }, {}, {}>;
181
+ };
182
+ dialect: "pg";
183
+ }>;
6
184
  calendarFeedTokens: import("drizzle-orm/pg-core").PgTableWithColumns<{
7
185
  name: "calendar_feed_tokens";
8
186
  schema: undefined;
@@ -2,13 +2,16 @@ export * from './documents.js';
2
2
  export * from './edges.js';
3
3
  export * from './analytics.js';
4
4
  export * from './calendarFeedTokens.js';
5
+ export * from './auditLogs.js';
5
6
  import * as documents from './documents.js';
6
7
  import * as edges from './edges.js';
7
8
  import * as analytics from './analytics.js';
8
9
  import * as calendarFeedTokens from './calendarFeedTokens.js';
10
+ import * as auditLogs from './auditLogs.js';
9
11
  export const schema = {
10
12
  ...documents,
11
13
  ...edges,
12
14
  ...analytics,
13
15
  ...calendarFeedTokens,
16
+ ...auditLogs,
14
17
  };
@@ -0,0 +1,16 @@
1
+ CREATE TABLE "audit_logs" (
2
+ "id" uuid PRIMARY KEY NOT NULL,
3
+ "actor_profile_id" text NOT NULL,
4
+ "actor_account_id" text,
5
+ "actor_ip" text,
6
+ "action" text NOT NULL,
7
+ "target_type" text NOT NULL,
8
+ "target_id" text,
9
+ "target_label" text,
10
+ "metadata" jsonb,
11
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
12
+ );
13
+ --> statement-breakpoint
14
+ CREATE INDEX "audit_logs_created_at_idx" ON "audit_logs" USING btree ("created_at" DESC NULLS LAST);--> statement-breakpoint
15
+ CREATE INDEX "audit_logs_actor_profile_idx" ON "audit_logs" USING btree ("actor_profile_id");--> statement-breakpoint
16
+ CREATE INDEX "audit_logs_target_idx" ON "audit_logs" USING btree ("target_type","target_id");