@memberjunction/schema-engine 0.0.1 → 5.17.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/dist/DDLGenerator.d.ts +48 -0
- package/dist/DDLGenerator.d.ts.map +1 -0
- package/dist/DDLGenerator.js +159 -0
- package/dist/DDLGenerator.js.map +1 -0
- package/dist/MigrationFileWriter.d.ts +32 -0
- package/dist/MigrationFileWriter.d.ts.map +1 -0
- package/dist/MigrationFileWriter.js +69 -0
- package/dist/MigrationFileWriter.js.map +1 -0
- package/dist/RSUMetrics.d.ts +48 -0
- package/dist/RSUMetrics.d.ts.map +1 -0
- package/dist/RSUMetrics.js +102 -0
- package/dist/RSUMetrics.js.map +1 -0
- package/dist/RuntimeSchemaManager.d.ts +454 -0
- package/dist/RuntimeSchemaManager.d.ts.map +1 -0
- package/dist/RuntimeSchemaManager.js +1395 -0
- package/dist/RuntimeSchemaManager.js.map +1 -0
- package/dist/SchemaEngine.d.ts +51 -0
- package/dist/SchemaEngine.d.ts.map +1 -0
- package/dist/SchemaEngine.js +100 -0
- package/dist/SchemaEngine.js.map +1 -0
- package/dist/SchemaEvolution.d.ts +30 -0
- package/dist/SchemaEvolution.d.ts.map +1 -0
- package/dist/SchemaEvolution.js +95 -0
- package/dist/SchemaEvolution.js.map +1 -0
- package/dist/SchemaValidator.d.ts +22 -0
- package/dist/SchemaValidator.d.ts.map +1 -0
- package/dist/SchemaValidator.js +93 -0
- package/dist/SchemaValidator.js.map +1 -0
- package/dist/SoftFKConfigEmitter.d.ts +59 -0
- package/dist/SoftFKConfigEmitter.d.ts.map +1 -0
- package/dist/SoftFKConfigEmitter.js +87 -0
- package/dist/SoftFKConfigEmitter.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +175 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +9 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -0
- package/package.json +31 -7
- package/README.md +0 -45
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RuntimeSchemaManager — Pipeline orchestrator for runtime schema changes.
|
|
3
|
+
*
|
|
4
|
+
* Chains: validate input → SchemaEngine.generateDDL() → write migration file →
|
|
5
|
+
* run migration → run CodeGen → restart MJAPI via PM2.
|
|
6
|
+
*
|
|
7
|
+
* Gated by ALLOW_RUNTIME_SCHEMA_UPDATE=1 environment variable.
|
|
8
|
+
* Hard-blocks CREATE/ALTER/DROP in __mj schema.
|
|
9
|
+
* In-memory concurrency mutex (one operation at a time).
|
|
10
|
+
*/
|
|
11
|
+
import { BaseSingleton } from '@memberjunction/global';
|
|
12
|
+
import { type DatabaseProviderBase } from '@memberjunction/core';
|
|
13
|
+
/**
|
|
14
|
+
* Input to the RSU pipeline.
|
|
15
|
+
*/
|
|
16
|
+
export interface RSUPipelineInput {
|
|
17
|
+
/** The migration SQL to execute (from SchemaEngine or any other source). */
|
|
18
|
+
MigrationSQL: string;
|
|
19
|
+
/** Descriptive name for this schema change. */
|
|
20
|
+
Description: string;
|
|
21
|
+
/** Tables being created or modified (used in branch naming and logging). */
|
|
22
|
+
AffectedTables: string[];
|
|
23
|
+
/** Optional: additionalSchemaInfo JSON content for soft FKs. */
|
|
24
|
+
AdditionalSchemaInfo?: string;
|
|
25
|
+
/** Optional: metadata JSON files for mj-sync. */
|
|
26
|
+
MetadataFiles?: Array<{
|
|
27
|
+
Path: string;
|
|
28
|
+
Content: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** If true, skip the git commit/push step (Phase 2). */
|
|
31
|
+
SkipGitCommit?: boolean;
|
|
32
|
+
/** If true, skip MJAPI restart (useful for batching multiple changes). */
|
|
33
|
+
SkipRestart?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Optional files to write to disk before restart. RSU does not read or
|
|
36
|
+
* interpret these — it simply persists them so they survive the process
|
|
37
|
+
* restart. The caller is responsible for reading them on the other side.
|
|
38
|
+
*/
|
|
39
|
+
PostRestartFiles?: Array<{
|
|
40
|
+
Path: string;
|
|
41
|
+
Content: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result of a single pipeline step.
|
|
46
|
+
*/
|
|
47
|
+
export interface RSUPipelineStep {
|
|
48
|
+
Name: string;
|
|
49
|
+
Status: 'success' | 'failed' | 'skipped';
|
|
50
|
+
DurationMs: number;
|
|
51
|
+
Message: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Result of a full RSU pipeline run.
|
|
55
|
+
*/
|
|
56
|
+
export interface RSUPipelineResult {
|
|
57
|
+
Success: boolean;
|
|
58
|
+
BranchName?: string;
|
|
59
|
+
MigrationFilePath?: string;
|
|
60
|
+
EntitiesProcessed?: number;
|
|
61
|
+
APIRestarted: boolean;
|
|
62
|
+
GitCommitSuccess: boolean;
|
|
63
|
+
Steps: RSUPipelineStep[];
|
|
64
|
+
ErrorMessage?: string;
|
|
65
|
+
ErrorStep?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Batch result wrapping per-item results with summary counts.
|
|
69
|
+
*/
|
|
70
|
+
export interface RSUPipelineBatchResult {
|
|
71
|
+
/** Per-item results in the same order as the inputs. */
|
|
72
|
+
Results: RSUPipelineResult[];
|
|
73
|
+
/** Number of migrations that succeeded. */
|
|
74
|
+
SuccessCount: number;
|
|
75
|
+
/** Number of migrations that failed. */
|
|
76
|
+
FailureCount: number;
|
|
77
|
+
/** Total number of inputs in the batch. */
|
|
78
|
+
TotalCount: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Use RSUPipelineInput.PostRestartFiles instead. This type is
|
|
82
|
+
* retained temporarily for backward compatibility with existing callers.
|
|
83
|
+
*/
|
|
84
|
+
export interface RSUPendingWork {
|
|
85
|
+
CompanyIntegrationID: string;
|
|
86
|
+
SourceObjectNames: string[];
|
|
87
|
+
/** Per-object field selections. Key = source object name, value = field names (null = all fields). */
|
|
88
|
+
SourceObjectFields?: Record<string, string[] | null>;
|
|
89
|
+
SchemaName: string;
|
|
90
|
+
CreatedAt: string;
|
|
91
|
+
CronExpression?: string;
|
|
92
|
+
ScheduleTimezone?: string;
|
|
93
|
+
StartSync?: boolean;
|
|
94
|
+
FullSync?: boolean;
|
|
95
|
+
SyncScope?: 'created' | 'all';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Dry-run preview of what the pipeline would do.
|
|
99
|
+
*/
|
|
100
|
+
export interface RSUPreviewResult {
|
|
101
|
+
MigrationSQL: string;
|
|
102
|
+
AffectedTables: string[];
|
|
103
|
+
ValidationErrors: string[];
|
|
104
|
+
WouldExecute: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Current status of the RSU system.
|
|
108
|
+
*/
|
|
109
|
+
export interface RSUStatus {
|
|
110
|
+
Enabled: boolean;
|
|
111
|
+
Running: boolean;
|
|
112
|
+
OutOfSync: boolean;
|
|
113
|
+
OutOfSyncSince: Date | null;
|
|
114
|
+
LastRunAt: Date | null;
|
|
115
|
+
LastRunResult: string | null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Interface for in-process CodeGen execution.
|
|
119
|
+
* Injected by the server at startup so SchemaEngine doesn't depend on CodeGenLib directly.
|
|
120
|
+
*/
|
|
121
|
+
export interface IRSUCodeGenRunner {
|
|
122
|
+
/** Run CodeGen in-process. Returns true on success. */
|
|
123
|
+
RunInProcess(skipDatabaseGeneration?: boolean): Promise<boolean>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Result of SQL migration validation.
|
|
127
|
+
*/
|
|
128
|
+
export interface SQLValidationResult {
|
|
129
|
+
Valid: boolean;
|
|
130
|
+
Errors: string[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Validate that migration SQL does not target protected schemas.
|
|
134
|
+
* The __mj schema is ALWAYS protected regardless of configuration.
|
|
135
|
+
*/
|
|
136
|
+
export declare function ValidateMigrationSQL(sql: string, additionalProtectedSchemas?: string[]): SQLValidationResult;
|
|
137
|
+
/**
|
|
138
|
+
* Singleton pipeline orchestrator for runtime schema changes.
|
|
139
|
+
*
|
|
140
|
+
* Usage:
|
|
141
|
+
* const rsm = RuntimeSchemaManager.Instance;
|
|
142
|
+
* if (!rsm.IsEnabled) throw new Error('RSU is disabled');
|
|
143
|
+
* const result = await rsm.RunPipeline(input);
|
|
144
|
+
*/
|
|
145
|
+
export declare class RuntimeSchemaManager extends BaseSingleton<RuntimeSchemaManager> {
|
|
146
|
+
protected constructor();
|
|
147
|
+
static get Instance(): RuntimeSchemaManager;
|
|
148
|
+
private _isRunning;
|
|
149
|
+
private _ddlProvider;
|
|
150
|
+
private _codeGenRunner;
|
|
151
|
+
private _codeGenOutputPaths;
|
|
152
|
+
private _outOfSync;
|
|
153
|
+
private _outOfSyncSince;
|
|
154
|
+
private _lastRunAt;
|
|
155
|
+
private _lastRunResult;
|
|
156
|
+
/**
|
|
157
|
+
* Set a dedicated provider for DDL operations (CREATE TABLE, CREATE SCHEMA, etc.).
|
|
158
|
+
* Should be configured with elevated credentials (e.g. MJ_CodeGen with db_owner).
|
|
159
|
+
* If not set, falls back to the default Metadata.Provider.
|
|
160
|
+
*/
|
|
161
|
+
SetDDLProvider(provider: DatabaseProviderBase): void;
|
|
162
|
+
/**
|
|
163
|
+
* Set the in-process CodeGen runner.
|
|
164
|
+
* Injected by the server at startup so RSU can run CodeGen without shelling out.
|
|
165
|
+
*/
|
|
166
|
+
SetCodeGenRunner(runner: IRSUCodeGenRunner): void;
|
|
167
|
+
/**
|
|
168
|
+
* Set the CodeGen output directory paths (from mj.config.cjs output[].directory).
|
|
169
|
+
* Used by the git step to stage only CodeGen-produced source files.
|
|
170
|
+
*/
|
|
171
|
+
SetCodeGenOutputPaths(paths: string[]): void;
|
|
172
|
+
/** Write pending work to disk so it can be processed after restart. */
|
|
173
|
+
WritePendingWork(data: RSUPendingWork): Promise<string>;
|
|
174
|
+
/** Read all pending work files, return them, and delete them. */
|
|
175
|
+
ReadAndClearPendingWork(): Promise<RSUPendingWork[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Write PostRestartFiles from all pipeline inputs to disk.
|
|
178
|
+
* RSU does not interpret these — callers provide arbitrary files
|
|
179
|
+
* that need to survive the process restart.
|
|
180
|
+
*/
|
|
181
|
+
private writePostRestartFiles;
|
|
182
|
+
/** Whether RSU is enabled based on ALLOW_RUNTIME_SCHEMA_UPDATE=1. */
|
|
183
|
+
get IsEnabled(): boolean;
|
|
184
|
+
/** Whether a pipeline is currently running (concurrency mutex). */
|
|
185
|
+
get IsRunning(): boolean;
|
|
186
|
+
/** Whether the local API is out of sync with the git repo. */
|
|
187
|
+
get IsOutOfSync(): boolean;
|
|
188
|
+
/** When the out-of-sync state was first detected. */
|
|
189
|
+
get OutOfSyncSince(): Date | null;
|
|
190
|
+
/** When the last pipeline run completed. */
|
|
191
|
+
get LastRunAt(): Date | null;
|
|
192
|
+
/** Result of the last pipeline run. */
|
|
193
|
+
get LastRunResult(): string | null;
|
|
194
|
+
/** Current status snapshot. */
|
|
195
|
+
GetStatus(): RSUStatus;
|
|
196
|
+
/**
|
|
197
|
+
* Execute the RSU pipeline for a single input. Convenience wrapper
|
|
198
|
+
* around RunPipelineBatch — a batch of 1.
|
|
199
|
+
*/
|
|
200
|
+
RunPipeline(input: RSUPipelineInput): Promise<RSUPipelineResult>;
|
|
201
|
+
/**
|
|
202
|
+
* Execute the RSU pipeline for a batch of inputs.
|
|
203
|
+
*
|
|
204
|
+
* Correctness guarantee: migrations and CodeGen never overlap.
|
|
205
|
+
* All migrations execute under one lock, then CodeGen runs once
|
|
206
|
+
* against the fully-committed schema.
|
|
207
|
+
*
|
|
208
|
+
* Flow:
|
|
209
|
+
* 1. Validate all inputs (fail fast — reject entire batch on validation error)
|
|
210
|
+
* 2. Lock
|
|
211
|
+
* 3. For each input: write migration file → execute SQL (independent success/failure)
|
|
212
|
+
* 4. Unlock
|
|
213
|
+
* 5. ONE CodeGen run (covers all successful migrations)
|
|
214
|
+
* 6. ONE compile
|
|
215
|
+
* 7. ONE restart
|
|
216
|
+
* 8. ONE git commit (all migration files)
|
|
217
|
+
* 9. Resolve each caller with per-item migration result + shared post-migration result
|
|
218
|
+
*/
|
|
219
|
+
RunPipelineBatch(inputs: RSUPipelineInput[]): Promise<RSUPipelineBatchResult>;
|
|
220
|
+
/** Phase 1: Validate environment and all migration SQL. Returns a batch failure result if validation fails, null on success. */
|
|
221
|
+
private validateBatch;
|
|
222
|
+
/** Phase 2: Acquire lock, write and execute each migration, release lock. */
|
|
223
|
+
private executeMigrations;
|
|
224
|
+
/** Phase 3: CodeGen, compile, restart, and git commit for successful migrations. */
|
|
225
|
+
private runPostMigrationPipeline;
|
|
226
|
+
/** Phase 4: Assemble per-caller RSUPipelineResult entries with audit and metrics. */
|
|
227
|
+
private buildPerCallerResults;
|
|
228
|
+
/** Record metrics for a single pipeline item (best-effort, errors are logged). */
|
|
229
|
+
private recordMetrics;
|
|
230
|
+
/**
|
|
231
|
+
* Run the RSU pipeline with automatic retry for transient failures.
|
|
232
|
+
* Only retries steps that are known to be transient (SQL execution, CodeGen, compilation, restart).
|
|
233
|
+
* Validation and git steps are not retried.
|
|
234
|
+
*
|
|
235
|
+
* @param input Pipeline input
|
|
236
|
+
* @param maxRetries Maximum number of retries (default: 2, so 3 total attempts)
|
|
237
|
+
* @param baseDelayMs Base delay for exponential backoff (default: 5000ms)
|
|
238
|
+
*/
|
|
239
|
+
RunPipelineWithRetry(input: RSUPipelineInput, maxRetries?: number, baseDelayMs?: number): Promise<RSUPipelineResult>;
|
|
240
|
+
/**
|
|
241
|
+
* Dry-run: validate the SQL and return what would happen.
|
|
242
|
+
*/
|
|
243
|
+
Preview(input: RSUPipelineInput): RSUPreviewResult;
|
|
244
|
+
/** Mark the API as running code that is out-of-sync with the git repo. */
|
|
245
|
+
MarkOutOfSync(): void;
|
|
246
|
+
/** Clear the out-of-sync flag (called when CI/CD deployment lands). */
|
|
247
|
+
ClearOutOfSync(): void;
|
|
248
|
+
private validateEnvironment;
|
|
249
|
+
/**
|
|
250
|
+
* Verify ALL filesystem paths RSU may write to are actually writable.
|
|
251
|
+
* Paths checked:
|
|
252
|
+
* - MigrationsPath (migration SQL files)
|
|
253
|
+
* - PendingWorkPath (post-restart task JSONs)
|
|
254
|
+
* - AdditionalSchemaInfoPath parent dir (soft FK / soft PK config)
|
|
255
|
+
* - CodeGenDir (temp codegen script)
|
|
256
|
+
* - WorkDir (pipeline log file)
|
|
257
|
+
*/
|
|
258
|
+
private validateFilesystemWritable;
|
|
259
|
+
/** Waiters queued behind the current lock holder. */
|
|
260
|
+
private _lockWaiters;
|
|
261
|
+
/**
|
|
262
|
+
* Acquire the migration lock. If another migration is in progress,
|
|
263
|
+
* the caller awaits (event-driven, no polling) until the lock is free.
|
|
264
|
+
* This ensures concurrent RunPipeline calls serialize safely instead
|
|
265
|
+
* of throwing CONCURRENT errors.
|
|
266
|
+
*/
|
|
267
|
+
private acquireLock;
|
|
268
|
+
/** Wake the next waiter in line (if any). */
|
|
269
|
+
private notifyNextWaiter;
|
|
270
|
+
private releaseLock;
|
|
271
|
+
/**
|
|
272
|
+
* Write the migration file to the configured migrations directory.
|
|
273
|
+
* Returns the file path of the written migration.
|
|
274
|
+
*
|
|
275
|
+
* Writes the migration file to the configured migrations directory (RSU_MIGRATIONS_PATH,
|
|
276
|
+
* defaults to 'migrations/v5'). The git commit step then picks up the file.
|
|
277
|
+
*/
|
|
278
|
+
private writeMigrationFile;
|
|
279
|
+
/**
|
|
280
|
+
* Write/merge AdditionalSchemaInfo (soft PK/FK config) to disk so CodeGen can find it.
|
|
281
|
+
* Path comes from RSU_ADDITIONAL_SCHEMA_INFO_PATH config, resolved relative to WorkDir.
|
|
282
|
+
*/
|
|
283
|
+
private writeAdditionalSchemaInfo;
|
|
284
|
+
/**
|
|
285
|
+
* Execute the migration SQL against the database.
|
|
286
|
+
* Delegates CLI tool selection to the DBExecProvider abstraction.
|
|
287
|
+
*/
|
|
288
|
+
private executeMigration;
|
|
289
|
+
/**
|
|
290
|
+
* Run CodeGen programmatically.
|
|
291
|
+
*
|
|
292
|
+
* Writes a temporary .mjs script that imports CodeGenLib directly (bypassing
|
|
293
|
+
* the oclif-based `mj` CLI which has heavy dependencies). The script:
|
|
294
|
+
* 1. Loads dotenv/config for DB env vars
|
|
295
|
+
* 2. Bootstraps class registrations via server-bootstrap-lite
|
|
296
|
+
* 3. Initializes config from mj.config.cjs
|
|
297
|
+
* 4. Runs full CodeGen pipeline (metadata + SQL + TypeScript generation)
|
|
298
|
+
*
|
|
299
|
+
* Override via RSU_CODEGEN_COMMAND env var for custom setups.
|
|
300
|
+
*/
|
|
301
|
+
private runCodeGen;
|
|
302
|
+
/**
|
|
303
|
+
* Compile affected TypeScript packages after CodeGen.
|
|
304
|
+
*
|
|
305
|
+
* Uses turbo to build the specified packages. Turbo handles the full
|
|
306
|
+
* dependency graph and caches unchanged packages automatically.
|
|
307
|
+
*
|
|
308
|
+
* Default targets: MJCoreEntities, MJServer, MJAPI (the primary CodeGen outputs).
|
|
309
|
+
* Override via RSU_COMPILE_PACKAGES (comma-separated npm package names).
|
|
310
|
+
*
|
|
311
|
+
* Set RSU_COMPILE_COMMAND to override the entire build command (e.g. for
|
|
312
|
+
* environments without turbo).
|
|
313
|
+
*/
|
|
314
|
+
private compileTypeScript;
|
|
315
|
+
/**
|
|
316
|
+
* Restart MJAPI via PM2.
|
|
317
|
+
*
|
|
318
|
+
* If MJAPI isn't currently managed by PM2, starts it using the ecosystem
|
|
319
|
+
* config. After restart, polls the GraphQL endpoint until the server is
|
|
320
|
+
* ready to accept requests.
|
|
321
|
+
*/
|
|
322
|
+
private restartMJAPI;
|
|
323
|
+
/**
|
|
324
|
+
* Check if a PM2 process exists (running or stopped).
|
|
325
|
+
*/
|
|
326
|
+
private isPM2ProcessRunning;
|
|
327
|
+
/**
|
|
328
|
+
* Poll the MJAPI GraphQL endpoint until the server responds.
|
|
329
|
+
* Uses a simple GET to the server root — Apollo Server returns a landing
|
|
330
|
+
* page or 400 (both indicate the server is up and accepting connections).
|
|
331
|
+
*/
|
|
332
|
+
private waitForMJAPI;
|
|
333
|
+
/**
|
|
334
|
+
* Git commit for a CodeGen cycle batch — commits all migration files,
|
|
335
|
+
* CodeGen outputs, and metadata from all requests in the batch.
|
|
336
|
+
* Returns the branch name on success.
|
|
337
|
+
*
|
|
338
|
+
* Uses Octokit GitHub API exclusively — no shell-outs, no git binary dependency.
|
|
339
|
+
* Works in any environment: local dev, Docker, Azure, CI/CD.
|
|
340
|
+
*/
|
|
341
|
+
private gitCommitAndPRForCycle;
|
|
342
|
+
/**
|
|
343
|
+
* Git commit and PR using Octokit GitHub API exclusively.
|
|
344
|
+
* For Docker/CI environments without a local `.git` directory.
|
|
345
|
+
*/
|
|
346
|
+
private gitCommitAndPRViaAPI;
|
|
347
|
+
/**
|
|
348
|
+
* Resolve GitHub owner/repo from RSU_GITHUB_REPO env var or by parsing the git remote URL.
|
|
349
|
+
* In Octokit-only mode, RSU_GITHUB_REPO is required since there's no local git remote.
|
|
350
|
+
*/
|
|
351
|
+
private resolveGitHubOwnerRepo;
|
|
352
|
+
/** Get the SHA of the tip of a branch via Octokit. */
|
|
353
|
+
private apiGetBranchSha;
|
|
354
|
+
/** Create a new branch ref via Octokit. */
|
|
355
|
+
private apiCreateBranch;
|
|
356
|
+
/**
|
|
357
|
+
* Build a git tree from files via Octokit using inline content.
|
|
358
|
+
* This sends all files in a single createTree call instead of
|
|
359
|
+
* N+1 individual createBlob calls, avoiding GitHub's secondary rate limit.
|
|
360
|
+
*
|
|
361
|
+
* Files > 1 MB fall back to createBlob (GitHub rejects inline content above that).
|
|
362
|
+
*/
|
|
363
|
+
private apiCreateTreeFromFiles;
|
|
364
|
+
/** Create a commit via Octokit. Returns the commit SHA. */
|
|
365
|
+
private apiCreateCommit;
|
|
366
|
+
/** Update a branch ref to point to a new commit SHA via Octokit. */
|
|
367
|
+
private apiUpdateBranchRef;
|
|
368
|
+
/** Create a PR via Octokit (API-only mode). */
|
|
369
|
+
private apiCreatePullRequest;
|
|
370
|
+
/**
|
|
371
|
+
* Collect all RSU-produced files that should be committed.
|
|
372
|
+
* Returns objects with both the absolute path (for reading) and
|
|
373
|
+
* the repo-relative path (for the git tree).
|
|
374
|
+
*/
|
|
375
|
+
/** Check if a path is gitignored by asking git. */
|
|
376
|
+
private isGitIgnored;
|
|
377
|
+
private collectAllRSUFiles;
|
|
378
|
+
/** Convert an absolute path to a repo-relative path (forward slashes). */
|
|
379
|
+
private toRepoRelativePath;
|
|
380
|
+
/** Recursively collect all files in a directory. */
|
|
381
|
+
private collectFilesRecursively;
|
|
382
|
+
/** Build the PR body markdown. */
|
|
383
|
+
private buildPRBody;
|
|
384
|
+
/** Create an authenticated Octokit instance from environment token. */
|
|
385
|
+
private createOctokit;
|
|
386
|
+
/**
|
|
387
|
+
* Generate a branch name from affected table names.
|
|
388
|
+
* Format: rsu/{YYYYMMDDHHmm}-{table-slugs}
|
|
389
|
+
*/
|
|
390
|
+
private generateBranchName;
|
|
391
|
+
/** Whether the DB-backed lock is enabled via RSU_DB_LOCK_ENABLED=1. */
|
|
392
|
+
private get IsDBLockEnabled();
|
|
393
|
+
/**
|
|
394
|
+
* Try to acquire a DB-backed lock by inserting a row into the RSULock table.
|
|
395
|
+
* Uses SQLDialect for DDL generation and DBExecProvider for CLI execution.
|
|
396
|
+
* Returns true if the lock was acquired, false if another instance holds it.
|
|
397
|
+
*/
|
|
398
|
+
private acquireDBLock;
|
|
399
|
+
private _dbLockId;
|
|
400
|
+
/**
|
|
401
|
+
* Release the DB-backed lock by deleting the lock row.
|
|
402
|
+
*/
|
|
403
|
+
private releaseDBLock;
|
|
404
|
+
/**
|
|
405
|
+
* Write an audit log entry for a pipeline run to the RSUAuditLog table.
|
|
406
|
+
*
|
|
407
|
+
* This is called automatically at the end of RunPipeline() if the DB
|
|
408
|
+
* is available and RSU_AUDIT_LOG_ENABLED is not explicitly '0'.
|
|
409
|
+
*/
|
|
410
|
+
private writeAuditLog;
|
|
411
|
+
/** Resolve the database platform from environment configuration. */
|
|
412
|
+
private get Platform();
|
|
413
|
+
/** Get the SQLDialect for the configured platform (SQL generation). */
|
|
414
|
+
private get Dialect();
|
|
415
|
+
/** Get the database provider for DDL operations. Prefers the dedicated DDL provider if set. */
|
|
416
|
+
private getDBProvider;
|
|
417
|
+
/**
|
|
418
|
+
* Generate SQL to create the RSULock table (if not exists), clean expired locks,
|
|
419
|
+
* and attempt to acquire the lock.
|
|
420
|
+
*/
|
|
421
|
+
private buildAcquireLockSQL;
|
|
422
|
+
/** Generate SQL to create the RSUAuditLog table if it doesn't exist. */
|
|
423
|
+
private buildAuditTableDDL;
|
|
424
|
+
/**
|
|
425
|
+
* Write the audit log INSERT using parameterized query to prevent SQL injection.
|
|
426
|
+
* The CREATE TABLE DDL runs separately (no user input, safe as-is).
|
|
427
|
+
*/
|
|
428
|
+
private writeAuditInsert;
|
|
429
|
+
/** Build a failed RSUPipelineResult for early-exit scenarios (validation, lock). */
|
|
430
|
+
private buildFailedResult;
|
|
431
|
+
private buildBatchResult;
|
|
432
|
+
private getProtectedSchemas;
|
|
433
|
+
/**
|
|
434
|
+
* Helper to execute shell commands asynchronously.
|
|
435
|
+
*/
|
|
436
|
+
private getExecAsync;
|
|
437
|
+
/**
|
|
438
|
+
* Run a named pipeline step, capturing timing and errors.
|
|
439
|
+
* Returns the step's return value on success, or undefined on failure.
|
|
440
|
+
*/
|
|
441
|
+
private runStep;
|
|
442
|
+
/**
|
|
443
|
+
* Log to both console and file. File path: RSU_WORK_DIR/rsu-pipeline.log.
|
|
444
|
+
*/
|
|
445
|
+
private rsuLog;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* RSU-specific error with a step code for structured error handling.
|
|
449
|
+
*/
|
|
450
|
+
export declare class RSUError extends Error {
|
|
451
|
+
readonly Code: string;
|
|
452
|
+
constructor(code: string, message: string);
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=RuntimeSchemaManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeSchemaManager.d.ts","sourceRoot":"","sources":["../src/RuntimeSchemaManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAsB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAqFrF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IAEpB,4EAA4E;IAC5E,cAAc,EAAE,MAAM,EAAE,CAAC;IAEzB,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,iDAAiD;IACjD,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEzD,wDAAwD;IACxD,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,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