@rebasepro/server-postgres 0.10.1-canary.811b3da → 0.10.1-canary.8650626
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/dist/PostgresBootstrapper.d.ts +7 -3
- package/dist/backup/backup-logic.d.ts +23 -0
- package/dist/backup/backup-service.d.ts +44 -2
- package/dist/backup/pg-tools.d.ts +41 -1
- package/dist/cli-helpers.d.ts +33 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1102 -88
- package/dist/index.es.js.map +1 -1
- package/dist/schema/destructive-sql.d.ts +49 -0
- package/dist/services/cdc/CdcListener.d.ts +7 -14
- package/dist/services/channel-bus/ChannelBus.d.ts +29 -0
- package/dist/services/channel-bus/PostgresChannelBus.d.ts +111 -0
- package/dist/services/channel-bus/index.d.ts +55 -0
- package/dist/services/channel-history.d.ts +11 -0
- package/dist/services/channel-presence.d.ts +66 -0
- package/dist/services/pg-notify-listener.d.ts +47 -0
- package/dist/services/realtimeService.d.ts +114 -6
- package/package.json +6 -6
- package/src/PostgresBootstrapper.ts +32 -3
- package/src/backup/backup-cli.ts +60 -1
- package/src/backup/backup-cron.ts +24 -1
- package/src/backup/backup-logic.ts +62 -0
- package/src/backup/backup-service.ts +132 -13
- package/src/backup/pg-tools.ts +70 -2
- package/src/cli-helpers.ts +82 -27
- package/src/cli.ts +152 -6
- package/src/index.ts +4 -0
- package/src/schema/destructive-sql.ts +94 -0
- package/src/services/cdc/CdcListener.ts +27 -91
- package/src/services/channel-bus/ChannelBus.ts +44 -0
- package/src/services/channel-bus/PostgresChannelBus.ts +299 -0
- package/src/services/channel-bus/index.ts +123 -0
- package/src/services/channel-history.ts +35 -0
- package/src/services/channel-presence.ts +148 -0
- package/src/services/pg-notify-listener.ts +137 -0
- package/src/services/realtimeService.ts +383 -14
|
@@ -26,9 +26,13 @@ export interface PostgresDriverConfig {
|
|
|
26
26
|
*/
|
|
27
27
|
introspectionSchema?: string;
|
|
28
28
|
/**
|
|
29
|
-
* Realtime options
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* Realtime options, both opt-in:
|
|
30
|
+
*
|
|
31
|
+
* - `channels` — retention. Without rules no channel keeps any history and
|
|
32
|
+
* broadcast stays fire-and-forget. See {@link ChannelRetentionRule}.
|
|
33
|
+
* - `bus` — the cross-instance transport for channel broadcast and
|
|
34
|
+
* presence. Defaults to in-process only, which is correct for a single
|
|
35
|
+
* instance and wrong for two. See {@link ChannelBusConfig}.
|
|
32
36
|
*/
|
|
33
37
|
realtime?: RealtimeChannelsConfig;
|
|
34
38
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay a `pg_dumpall --globals-only` script one statement at a time,
|
|
3
|
+
* tolerating per-statement failures. On a same-cluster restore the roles
|
|
4
|
+
* usually already exist (`CREATE ROLE` → "already exists") and on a managed
|
|
5
|
+
* provider an `ALTER ROLE <superuser>` may be refused; neither should abort
|
|
6
|
+
* recreation of the roles that *are* missing. Returns how many statements
|
|
7
|
+
* applied vs were skipped.
|
|
8
|
+
*
|
|
9
|
+
* `runStatement` executes one SQL statement and rejects on error.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyGlobalsWith(runStatement: (sql: string) => Promise<void>, globalsSql: string, log?: (message: string) => void): Promise<{
|
|
12
|
+
applied: number;
|
|
13
|
+
skipped: number;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Delete each pruned dump together with its `.globals.sql` roles sidecar, so
|
|
17
|
+
* pruning never orphans the roles file. The sidecar is best-effort — older
|
|
18
|
+
* backups predate it, so a missing-sidecar failure is swallowed while a
|
|
19
|
+
* failure deleting the dump itself propagates.
|
|
20
|
+
*
|
|
21
|
+
* `deleteObject` removes one key and rejects if it cannot (e.g. not found).
|
|
22
|
+
*/
|
|
23
|
+
export declare function pruneWith(keys: string[], deleteObject: (key: string) => Promise<void>): Promise<void>;
|
|
@@ -5,8 +5,8 @@ export declare class BackupToolError extends Error {
|
|
|
5
5
|
readonly hint?: string | undefined;
|
|
6
6
|
constructor(message: string, hint?: string | undefined);
|
|
7
7
|
}
|
|
8
|
-
/** Locate `pg_dump` / `pg_restore`, honouring an env override. */
|
|
9
|
-
export declare function resolvePgBinary(tool: "pg_dump" | "pg_restore", env?: Record<string, string | undefined>): string | null;
|
|
8
|
+
/** Locate `pg_dump` / `pg_restore` / `pg_dumpall`, honouring an env override. */
|
|
9
|
+
export declare function resolvePgBinary(tool: "pg_dump" | "pg_restore" | "pg_dumpall", env?: Record<string, string | undefined>): string | null;
|
|
10
10
|
/** Run `<bin> --version` and extract the major version. */
|
|
11
11
|
export declare function detectToolMajor(bin: string): Promise<number | null>;
|
|
12
12
|
/** Query the server for its major version via `server_version_num`. */
|
|
@@ -27,11 +27,22 @@ export interface BackupResult {
|
|
|
27
27
|
localFile: string;
|
|
28
28
|
fileName: string;
|
|
29
29
|
sizeBytes: number;
|
|
30
|
+
/**
|
|
31
|
+
* Absolute path of the `.globals.sql` sidecar holding cluster-wide roles
|
|
32
|
+
* (present unless globals capture was disabled or unavailable).
|
|
33
|
+
*/
|
|
34
|
+
globalsFile?: string;
|
|
35
|
+
globalsSizeBytes?: number;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Produce a custom-format dump on local disk. When `outDir` is omitted the
|
|
33
39
|
* file is written to the OS temp directory (used by the upload path, which
|
|
34
40
|
* cleans it up afterwards).
|
|
41
|
+
*
|
|
42
|
+
* Alongside the `-Fc` dump it writes a `<name>.globals.sql` sidecar via
|
|
43
|
+
* `pg_dumpall --globals-only` so the roles the dump's GRANT/RLS statements
|
|
44
|
+
* depend on can be recreated on restore. Set `includeGlobals: false` to skip
|
|
45
|
+
* it (e.g. when the caller has no privilege to read cluster globals).
|
|
35
46
|
*/
|
|
36
47
|
export declare function createDump(opts: {
|
|
37
48
|
connectionString: string;
|
|
@@ -41,19 +52,50 @@ export declare function createDump(opts: {
|
|
|
41
52
|
excludeSchemas?: string[];
|
|
42
53
|
noOwner?: boolean;
|
|
43
54
|
inheritStdio?: boolean;
|
|
55
|
+
includeGlobals?: boolean;
|
|
44
56
|
env?: Record<string, string | undefined>;
|
|
45
57
|
}): Promise<BackupResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Cheap integrity check on a freshly written dump: it must be non-empty and
|
|
60
|
+
* `pg_restore --list` must parse its table of contents without error. Used
|
|
61
|
+
* before pruning older backups so a corrupt-but-exit-0 dump never becomes
|
|
62
|
+
* the reason the last good backup is deleted.
|
|
63
|
+
*/
|
|
64
|
+
export declare function validateDump(localFile: string, env?: Record<string, string | undefined>): Promise<{
|
|
65
|
+
ok: boolean;
|
|
66
|
+
reason?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Replay a `pg_dumpall --globals-only` script to recreate cluster roles
|
|
70
|
+
* before a restore, so the dump's GRANT/RLS statements (which reference
|
|
71
|
+
* `rebase_user` and any owner roles) actually apply. Runs statement by
|
|
72
|
+
* statement and tolerates per-statement failures — on a same-cluster restore
|
|
73
|
+
* the roles usually already exist (`CREATE ROLE` → "already exists"), and on
|
|
74
|
+
* a managed provider an `ALTER ROLE <superuser>` may be refused; neither
|
|
75
|
+
* should abort role recreation. Returns how many statements applied vs were
|
|
76
|
+
* skipped.
|
|
77
|
+
*/
|
|
78
|
+
export declare function applyGlobals(connectionString: string, globalsSql: string, log?: (message: string) => void): Promise<{
|
|
79
|
+
applied: number;
|
|
80
|
+
skipped: number;
|
|
81
|
+
}>;
|
|
46
82
|
/**
|
|
47
83
|
* Restore a custom-format dump into the database named by
|
|
48
84
|
* `connectionString`. Destructive when `clean` is set (drops objects
|
|
49
85
|
* first). Never called automatically — the CLI gates it behind explicit
|
|
50
86
|
* confirmation.
|
|
87
|
+
*
|
|
88
|
+
* Runs with `--exit-on-error` by default: a restore that logs-and-continues
|
|
89
|
+
* past a failed GRANT (because a role was missing) reports success with RLS
|
|
90
|
+
* un-enforced. Callers should recreate roles first (see {@link applyGlobals})
|
|
91
|
+
* and only set `exitOnError: false` deliberately.
|
|
51
92
|
*/
|
|
52
93
|
export declare function restoreDump(opts: {
|
|
53
94
|
connectionString: string;
|
|
54
95
|
inputFile: string;
|
|
55
96
|
clean?: boolean;
|
|
56
97
|
noOwner?: boolean;
|
|
98
|
+
exitOnError?: boolean;
|
|
57
99
|
inheritStdio?: boolean;
|
|
58
100
|
env?: Record<string, string | undefined>;
|
|
59
101
|
}): Promise<void>;
|
|
@@ -99,10 +99,50 @@ export declare function buildPgRestoreArgs(opts: {
|
|
|
99
99
|
inputFile: string;
|
|
100
100
|
/** Drop objects before recreating them (destructive but idempotent). */
|
|
101
101
|
clean?: boolean;
|
|
102
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Abort on the first error instead of logging and continuing. Defaults
|
|
104
|
+
* ON: a restore that silently skips failed GRANT/RLS statements (because
|
|
105
|
+
* a role is missing) "succeeds" with RLS un-enforced — a security hole.
|
|
106
|
+
* Fail loudly instead so the operator knows the restore is incomplete.
|
|
107
|
+
*/
|
|
103
108
|
exitOnError?: boolean;
|
|
104
109
|
noOwner?: boolean;
|
|
105
110
|
}): string[];
|
|
111
|
+
/**
|
|
112
|
+
* Assemble the `pg_restore --list` argument vector. Reading a dump's table
|
|
113
|
+
* of contents parses the whole archive without touching a database, so it is
|
|
114
|
+
* a cheap integrity check that the file isn't truncated or corrupt.
|
|
115
|
+
*/
|
|
116
|
+
export declare function buildPgRestoreListArgs(inputFile: string): string[];
|
|
117
|
+
/**
|
|
118
|
+
* Assemble the `pg_dumpall --globals-only` argument vector. Roles (and other
|
|
119
|
+
* cluster-wide objects) live outside any single database, so a per-database
|
|
120
|
+
* `pg_dump` omits them. Without the `rebase_user` role the RLS GRANT
|
|
121
|
+
* statements in the main dump fail on restore and RLS is silently lost — so
|
|
122
|
+
* every backup captures the globals into a sidecar `.globals.sql`.
|
|
123
|
+
*
|
|
124
|
+
* `--no-role-passwords` keeps role secrets out of the artifact (backups may
|
|
125
|
+
* be shipped off-box); roles are recreated password-less and re-secured by
|
|
126
|
+
* the operator.
|
|
127
|
+
*/
|
|
128
|
+
export declare function buildPgDumpallGlobalsArgs(opts: {
|
|
129
|
+
connectionString: string;
|
|
130
|
+
outFile: string;
|
|
131
|
+
}): string[];
|
|
132
|
+
/**
|
|
133
|
+
* Derive the globals sidecar path/key for a given `.dump` file. Keeps the
|
|
134
|
+
* two artifacts adjacent so listing, uploading and pruning can find one from
|
|
135
|
+
* the other. A name that doesn't end in `.dump` is returned unchanged with a
|
|
136
|
+
* `.globals.sql` suffix appended.
|
|
137
|
+
*/
|
|
138
|
+
export declare function globalsFileForDump(dumpPath: string): string;
|
|
139
|
+
/**
|
|
140
|
+
* Split a `pg_dumpall --globals-only` script into individual statements.
|
|
141
|
+
* Used when replaying globals on restore so each `CREATE ROLE` / `GRANT`
|
|
142
|
+
* can run independently and a benign "role already exists" on one doesn't
|
|
143
|
+
* abort the rest. Drops `--` comment lines and blank statements.
|
|
144
|
+
*/
|
|
145
|
+
export declare function splitGlobalsStatements(sql: string): string[];
|
|
106
146
|
/**
|
|
107
147
|
* Resolve the Postgres connection string the backup commands should use,
|
|
108
148
|
* mirroring the precedence the branch command already relies on.
|
package/dist/cli-helpers.d.ts
CHANGED
|
@@ -4,4 +4,36 @@ export declare function getTableIncludesFromCollections(collections: CollectionC
|
|
|
4
4
|
export declare function getTableIncludes(collectionsPath: string): Promise<string[]>;
|
|
5
5
|
export declare function getDevDatabaseUrl(databaseUrl: string): string;
|
|
6
6
|
export declare function ensureDevDatabaseExists(databaseUrl: string, devDatabaseUrl: string): Promise<void>;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Query the live database for every user table/view outside the system
|
|
9
|
+
* catalogs. Separated from {@link getTableExcludes} so its failure mode can
|
|
10
|
+
* be handled explicitly (fail closed) and so tests can inject a stub.
|
|
11
|
+
*/
|
|
12
|
+
export declare function queryExistingTables(databaseUrl: string): Promise<string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Raised when the exclude list could not be built. `db push` MUST abort on
|
|
15
|
+
* this rather than continue: the exclude list is the only thing shielding
|
|
16
|
+
* non-collection (user/system) tables from the auto-approved declarative
|
|
17
|
+
* apply. A partial list — the old fail-open behaviour — meant a transient
|
|
18
|
+
* introspection hiccup dropped every table not present in `schema.sql`.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ExcludeIntrospectionError extends Error {
|
|
21
|
+
readonly cause?: unknown | undefined;
|
|
22
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the `--exclude` list that protects tables Rebase doesn't manage from
|
|
26
|
+
* the declarative apply. Anything not backing a collection (or its M2M
|
|
27
|
+
* junctions) is excluded so Atlas never drops it.
|
|
28
|
+
*
|
|
29
|
+
* Fails **closed**: if the database can't be introspected we cannot know
|
|
30
|
+
* which tables to protect, so we throw {@link ExcludeIntrospectionError}
|
|
31
|
+
* instead of returning a near-empty list and letting the caller drop
|
|
32
|
+
* everything.
|
|
33
|
+
*
|
|
34
|
+
* `deps` is injectable for tests; production uses the real pg-backed queries.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getTableExcludes(databaseUrl: string, collectionsPath: string, deps?: {
|
|
37
|
+
queryExistingTables?: (databaseUrl: string) => Promise<string[]>;
|
|
38
|
+
getIncludes?: (collectionsPath: string) => Promise<string[]>;
|
|
39
|
+
}): Promise<string[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./schema/generate-drizzle-schema-logic";
|
|
|
7
7
|
export * from "./schema/generate-drizzle-schema";
|
|
8
8
|
export * from "./utils/drizzle-conditions";
|
|
9
9
|
export * from "./services/realtimeService";
|
|
10
|
+
export * from "./services/channel-bus";
|
|
10
11
|
export * from "./websocket";
|
|
11
12
|
export * from "./collections/PostgresCollectionRegistry";
|
|
12
13
|
export * from "./services/BranchService";
|