@prodforcode/event-forge-typeorm 1.0.5 → 1.1.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/README.md +81 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migration-list-command.d.ts +8 -0
- package/dist/cli/migration-list-command.d.ts.map +1 -0
- package/dist/cli/migration-list-command.js +110 -0
- package/dist/cli/migration-list-command.js.map +1 -0
- package/dist/cli/migration-rollback-command.d.ts +9 -0
- package/dist/cli/migration-rollback-command.d.ts.map +1 -0
- package/dist/cli/migration-rollback-command.js +116 -0
- package/dist/cli/migration-rollback-command.js.map +1 -0
- package/dist/cli/migration-run-command.d.ts +8 -0
- package/dist/cli/migration-run-command.d.ts.map +1 -0
- package/dist/cli/migration-run-command.js +117 -0
- package/dist/cli/migration-run-command.js.map +1 -0
- package/dist/entities/event-forge-migration.entity.d.ts +7 -0
- package/dist/entities/event-forge-migration.entity.d.ts.map +1 -0
- package/dist/entities/event-forge-migration.entity.js +41 -0
- package/dist/entities/event-forge-migration.entity.js.map +1 -0
- package/dist/entities/inbox-message.entity.d.ts +3 -0
- package/dist/entities/inbox-message.entity.d.ts.map +1 -1
- package/dist/entities/inbox-message.entity.js +15 -0
- package/dist/entities/inbox-message.entity.js.map +1 -1
- package/dist/entities/index.d.ts +1 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +1 -0
- package/dist/entities/index.js.map +1 -1
- package/dist/migrations/1.0.6-001-AddInboxRetryFields.d.ts +3 -0
- package/dist/migrations/1.0.6-001-AddInboxRetryFields.d.ts.map +1 -0
- package/dist/migrations/1.0.6-001-AddInboxRetryFields.js +43 -0
- package/dist/migrations/1.0.6-001-AddInboxRetryFields.js.map +1 -0
- package/dist/migrations/1768259084000-AddInboxRetryFields.d.ts +6 -0
- package/dist/migrations/1768259084000-AddInboxRetryFields.d.ts.map +1 -0
- package/dist/migrations/1768259084000-AddInboxRetryFields.js +42 -0
- package/dist/migrations/1768259084000-AddInboxRetryFields.js.map +1 -0
- package/dist/migrations/index.d.ts +3 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -1
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/migration-discovery.d.ts +12 -0
- package/dist/migrations/migration-discovery.d.ts.map +1 -0
- package/dist/migrations/migration-discovery.js +114 -0
- package/dist/migrations/migration-discovery.js.map +1 -0
- package/dist/migrations/migration-manager.d.ts +20 -0
- package/dist/migrations/migration-manager.d.ts.map +1 -0
- package/dist/migrations/migration-manager.js +194 -0
- package/dist/migrations/migration-manager.js.map +1 -0
- package/dist/migrations/migration.interface.d.ts +21 -0
- package/dist/migrations/migration.interface.d.ts.map +1 -0
- package/dist/migrations/migration.interface.js +3 -0
- package/dist/migrations/migration.interface.js.map +1 -0
- package/dist/migrations/templates.d.ts.map +1 -1
- package/dist/migrations/templates.js +7 -1
- package/dist/migrations/templates.js.map +1 -1
- package/dist/repositories/typeorm-inbox.repository.d.ts +3 -2
- package/dist/repositories/typeorm-inbox.repository.d.ts.map +1 -1
- package/dist/repositories/typeorm-inbox.repository.js +47 -4
- package/dist/repositories/typeorm-inbox.repository.js.map +1 -1
- package/dist/repositories/typeorm-outbox.repository.d.ts +1 -1
- package/dist/repositories/typeorm-outbox.repository.d.ts.map +1 -1
- package/dist/repositories/typeorm-outbox.repository.js +2 -1
- package/dist/repositories/typeorm-outbox.repository.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ npm install @prodforcode/event-forge-typeorm typeorm
|
|
|
15
15
|
- ✅ Optimized repository implementations with SELECT FOR UPDATE SKIP LOCKED
|
|
16
16
|
- ✅ Automatic database migration generation
|
|
17
17
|
- ✅ CLI tool for migration management
|
|
18
|
+
- ✅ **Migration versioning and tracking system**
|
|
19
|
+
- ✅ **Automatic migration discovery and execution**
|
|
18
20
|
- ✅ Full TypeScript support
|
|
19
21
|
|
|
20
22
|
## Quick Start
|
|
@@ -166,11 +168,39 @@ import * as fs from 'fs';
|
|
|
166
168
|
fs.writeFileSync('migration.sql', sqlFile);
|
|
167
169
|
```
|
|
168
170
|
|
|
171
|
+
## Migration Versioning System
|
|
172
|
+
|
|
173
|
+
Event-Forge includes a comprehensive migration management system that tracks applied migrations and automatically discovers pending ones when upgrading between versions.
|
|
174
|
+
|
|
175
|
+
See [MIGRATIONS.md](./MIGRATIONS.md) for complete documentation.
|
|
176
|
+
|
|
177
|
+
### Quick Overview
|
|
178
|
+
|
|
179
|
+
When upgrading Event-Forge (e.g., 1.0.5 → 1.0.6), the migration system:
|
|
180
|
+
|
|
181
|
+
1. Tracks which migrations have been applied
|
|
182
|
+
2. Discovers new migrations from the package
|
|
183
|
+
3. Runs pending migrations automatically or on-demand
|
|
184
|
+
4. Supports rollback if needed
|
|
185
|
+
|
|
186
|
+
### Usage
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# List all migrations with status
|
|
190
|
+
npx event-forge migration:list --data-source=./src/data-source.ts
|
|
191
|
+
|
|
192
|
+
# Run pending migrations
|
|
193
|
+
npx event-forge migration:run --data-source=./src/data-source.ts
|
|
194
|
+
|
|
195
|
+
# Rollback last migration
|
|
196
|
+
npx event-forge migration:rollback --data-source=./src/data-source.ts
|
|
197
|
+
```
|
|
198
|
+
|
|
169
199
|
## CLI Reference
|
|
170
200
|
|
|
171
201
|
### `event-forge migration:generate`
|
|
172
202
|
|
|
173
|
-
Generate Event-Forge database migration.
|
|
203
|
+
Generate Event-Forge database migration for NEW projects.
|
|
174
204
|
|
|
175
205
|
**Options:**
|
|
176
206
|
|
|
@@ -201,6 +231,56 @@ npx event-forge migration:generate \
|
|
|
201
231
|
--filename=1704657600000-EventForge.ts
|
|
202
232
|
```
|
|
203
233
|
|
|
234
|
+
### `event-forge migration:list`
|
|
235
|
+
|
|
236
|
+
List all Event-Forge migrations with their status.
|
|
237
|
+
|
|
238
|
+
**Options:**
|
|
239
|
+
|
|
240
|
+
- `-d, --data-source <path>` - Path to TypeORM DataSource configuration file (required)
|
|
241
|
+
- `-m, --migrations-path <path>` - Custom migrations directory path (optional)
|
|
242
|
+
|
|
243
|
+
**Example:**
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
npx event-forge migration:list --data-source=./src/data-source.ts
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### `event-forge migration:run`
|
|
250
|
+
|
|
251
|
+
Run pending Event-Forge migrations.
|
|
252
|
+
|
|
253
|
+
**Options:**
|
|
254
|
+
|
|
255
|
+
- `-d, --data-source <path>` - Path to TypeORM DataSource configuration file (required)
|
|
256
|
+
- `-m, --migrations-path <path>` - Custom migrations directory path (optional)
|
|
257
|
+
|
|
258
|
+
**Example:**
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npx event-forge migration:run --data-source=./src/data-source.ts
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### `event-forge migration:rollback`
|
|
265
|
+
|
|
266
|
+
Rollback Event-Forge migrations.
|
|
267
|
+
|
|
268
|
+
**Options:**
|
|
269
|
+
|
|
270
|
+
- `-d, --data-source <path>` - Path to TypeORM DataSource configuration file (required)
|
|
271
|
+
- `-m, --migrations-path <path>` - Custom migrations directory path (optional)
|
|
272
|
+
- `-c, --count <number>` - Number of migrations to rollback (default: 1)
|
|
273
|
+
|
|
274
|
+
**Examples:**
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Rollback last migration
|
|
278
|
+
npx event-forge migration:rollback --data-source=./src/data-source.ts
|
|
279
|
+
|
|
280
|
+
# Rollback last 2 migrations
|
|
281
|
+
npx event-forge migration:rollback --data-source=./src/data-source.ts --count=2
|
|
282
|
+
```
|
|
283
|
+
|
|
204
284
|
## Database Schema
|
|
205
285
|
|
|
206
286
|
### Outbox Messages Table
|
package/dist/cli/index.js
CHANGED
|
@@ -5,6 +5,9 @@ const fs_1 = require("fs");
|
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const migration_command_1 = require("./migration-command");
|
|
8
|
+
const migration_list_command_1 = require("./migration-list-command");
|
|
9
|
+
const migration_rollback_command_1 = require("./migration-rollback-command");
|
|
10
|
+
const migration_run_command_1 = require("./migration-run-command");
|
|
8
11
|
const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../package.json'), 'utf-8'));
|
|
9
12
|
const program = new commander_1.Command();
|
|
10
13
|
program
|
|
@@ -12,5 +15,8 @@ program
|
|
|
12
15
|
.description('Event-Forge TypeORM Adapter CLI')
|
|
13
16
|
.version(packageJson.version);
|
|
14
17
|
program.addCommand((0, migration_command_1.createMigrationCommand)());
|
|
18
|
+
program.addCommand((0, migration_list_command_1.createMigrationListCommand)());
|
|
19
|
+
program.addCommand((0, migration_run_command_1.createMigrationRunCommand)());
|
|
20
|
+
program.addCommand((0, migration_rollback_command_1.createMigrationRollbackCommand)());
|
|
15
21
|
program.parse(process.argv);
|
|
16
22
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAQA,2BAAkC;AAClC,+BAA4B;AAE5B,yCAAoC;AAEpC,2DAA6D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAQA,2BAAkC;AAClC,+BAA4B;AAE5B,yCAAoC;AAEpC,2DAA6D;AAC7D,qEAAsE;AACtE,6EAA8E;AAC9E,mEAAoE;AAOpE,MAAM,WAAW,GAAgB,IAAI,CAAC,KAAK,CACzC,IAAA,iBAAY,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAC9C,CAAC;AAEjB,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,CAAC,iCAAiC,CAAC;KAC9C,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AAGhC,OAAO,CAAC,UAAU,CAAC,IAAA,0CAAsB,GAAE,CAAC,CAAC;AAC7C,OAAO,CAAC,UAAU,CAAC,IAAA,mDAA0B,GAAE,CAAC,CAAC;AACjD,OAAO,CAAC,UAAU,CAAC,IAAA,iDAAyB,GAAE,CAAC,CAAC;AAChD,OAAO,CAAC,UAAU,CAAC,IAAA,2DAA8B,GAAE,CAAC,CAAC;AAGrD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface MigrationListOptions {
|
|
3
|
+
dataSource: string;
|
|
4
|
+
migrationsPath?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function executeMigrationList(options: MigrationListOptions): Promise<void>;
|
|
7
|
+
export declare function createMigrationListCommand(): Command;
|
|
8
|
+
//# sourceMappingURL=migration-list-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-list-command.d.ts","sourceRoot":"","sources":["../../src/cli/migration-list-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,WAAW,oBAAoB;IAEnC,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAmCD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAyDf;AAKD,wBAAgB,0BAA0B,IAAI,OAAO,CAkBpD"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.executeMigrationList = executeMigrationList;
|
|
37
|
+
exports.createMigrationListCommand = createMigrationListCommand;
|
|
38
|
+
const commander_1 = require("commander");
|
|
39
|
+
const typeorm_1 = require("typeorm");
|
|
40
|
+
const migration_manager_1 = require("../migrations/migration-manager");
|
|
41
|
+
async function loadDataSource(configPath) {
|
|
42
|
+
try {
|
|
43
|
+
const module = (await Promise.resolve(`${configPath}`).then(s => __importStar(require(s))));
|
|
44
|
+
const dataSource = module.default || module.AppDataSource;
|
|
45
|
+
if (!dataSource || !(dataSource instanceof typeorm_1.DataSource)) {
|
|
46
|
+
throw new Error('Configuration file must export a TypeORM DataSource instance');
|
|
47
|
+
}
|
|
48
|
+
return dataSource;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error(`Failed to load DataSource from ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function executeMigrationList(options) {
|
|
55
|
+
let dataSource = null;
|
|
56
|
+
try {
|
|
57
|
+
console.log('🔄 Loading DataSource configuration...');
|
|
58
|
+
dataSource = await loadDataSource(options.dataSource);
|
|
59
|
+
if (!dataSource.isInitialized) {
|
|
60
|
+
console.log('🔌 Initializing database connection...');
|
|
61
|
+
await dataSource.initialize();
|
|
62
|
+
}
|
|
63
|
+
console.log('✅ Database connected\n');
|
|
64
|
+
const manager = new migration_manager_1.MigrationManager(dataSource, options.migrationsPath);
|
|
65
|
+
console.log('🔍 Loading migrations...');
|
|
66
|
+
const migrations = await manager.listMigrations();
|
|
67
|
+
if (migrations.length === 0) {
|
|
68
|
+
console.log('\n⚠️ No migrations found');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`\n📋 Found ${migrations.length} migration(s):\n`);
|
|
72
|
+
const pendingCount = migrations.filter((m) => !m.applied).length;
|
|
73
|
+
const appliedCount = migrations.filter((m) => m.applied).length;
|
|
74
|
+
console.log(` Applied: ${appliedCount}`);
|
|
75
|
+
console.log(` Pending: ${pendingCount}\n`);
|
|
76
|
+
console.log('Status | Version | Name');
|
|
77
|
+
console.log('-------|---------------|------------------------------');
|
|
78
|
+
migrations.forEach((migration) => {
|
|
79
|
+
const status = migration.applied ? '✅' : '⏳';
|
|
80
|
+
const version = migration.version.padEnd(13);
|
|
81
|
+
const appliedInfo = migration.appliedAt
|
|
82
|
+
? ` (${migration.appliedAt.toISOString()})`
|
|
83
|
+
: '';
|
|
84
|
+
console.log(`${status} | ${version} | ${migration.name}${appliedInfo}`);
|
|
85
|
+
});
|
|
86
|
+
console.log('');
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error('❌ Failed to list migrations:');
|
|
90
|
+
console.error(error instanceof Error ? error.message : 'Unknown error occurred');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
if (dataSource?.isInitialized) {
|
|
95
|
+
await dataSource.destroy();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function createMigrationListCommand() {
|
|
100
|
+
const command = new commander_1.Command('migration:list');
|
|
101
|
+
command
|
|
102
|
+
.description('List all Event-Forge migrations with status')
|
|
103
|
+
.requiredOption('-d, --data-source <path>', 'Path to TypeORM DataSource configuration file')
|
|
104
|
+
.option('-m, --migrations-path <path>', 'Custom migrations directory path')
|
|
105
|
+
.action(async (options) => {
|
|
106
|
+
await executeMigrationList(options);
|
|
107
|
+
});
|
|
108
|
+
return command;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=migration-list-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-list-command.js","sourceRoot":"","sources":["../../src/cli/migration-list-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,oDA2DC;AAKD,gEAkBC;AAlID,yCAAoC;AACpC,qCAAqC;AAErC,uEAAmE;AAuBnE,KAAK,UAAU,cAAc,CAAC,UAAkB;IAC9C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,yBAAa,UAAU,uCAAC,CAAqB,CAAC;QAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,aAAa,CAAC;QAE1D,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,Y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AC;YAAS,CAAC;QACT,IAAI,UAAU,EAAE,aAAa,EAAE,CAAC;YAC9B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC;AAKD,SAAgB,0BAA0B;IACxC,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,gBAAgB,CAAC,CAAC;IAE9C,OAAO;SACJ,WAAW,CAAC,6CAA6C,CAAC;SAC1D,cAAc,CACb,0BAA0B,EAC1B,+CAA+C,CAChD;SACA,MAAM,CACL,8BAA8B,EAC9B,kCAAkC,CACnC;SACA,MAAM,CAAC,KAAK,EAAE,OAA6B,EAAE,EAAE;QAC9C,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface MigrationRollbackOptions {
|
|
3
|
+
dataSource: string;
|
|
4
|
+
migrationsPath?: string;
|
|
5
|
+
count?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function executeMigrationRollback(options: MigrationRollbackOptions): Promise<void>;
|
|
8
|
+
export declare function createMigrationRollbackCommand(): Command;
|
|
9
|
+
//# sourceMappingURL=migration-rollback-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-rollback-command.d.ts","sourceRoot":"","sources":["../../src/cli/migration-rollback-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,WAAW,wBAAwB;IAEvC,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAmCD,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CA4Df;AAKD,wBAAgB,8BAA8B,IAAI,OAAO,CAmBxD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.executeMigrationRollback = executeMigrationRollback;
|
|
37
|
+
exports.createMigrationRollbackCommand = createMigrationRollbackCommand;
|
|
38
|
+
const commander_1 = require("commander");
|
|
39
|
+
const typeorm_1 = require("typeorm");
|
|
40
|
+
const migration_manager_1 = require("../migrations/migration-manager");
|
|
41
|
+
async function loadDataSource(configPath) {
|
|
42
|
+
try {
|
|
43
|
+
const module = (await Promise.resolve(`${configPath}`).then(s => __importStar(require(s))));
|
|
44
|
+
const dataSource = module.default || module.AppDataSource;
|
|
45
|
+
if (!dataSource || !(dataSource instanceof typeorm_1.DataSource)) {
|
|
46
|
+
throw new Error('Configuration file must export a TypeORM DataSource instance');
|
|
47
|
+
}
|
|
48
|
+
return dataSource;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error(`Failed to load DataSource from ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function executeMigrationRollback(options) {
|
|
55
|
+
let dataSource = null;
|
|
56
|
+
try {
|
|
57
|
+
const count = options.count ? parseInt(options.count, 10) : 1;
|
|
58
|
+
if (isNaN(count) || count < 1) {
|
|
59
|
+
throw new Error('Count must be a positive integer');
|
|
60
|
+
}
|
|
61
|
+
console.log('🔄 Loading DataSource configuration...');
|
|
62
|
+
dataSource = await loadDataSource(options.dataSource);
|
|
63
|
+
if (!dataSource.isInitialized) {
|
|
64
|
+
console.log('🔌 Initializing database connection...');
|
|
65
|
+
await dataSource.initialize();
|
|
66
|
+
}
|
|
67
|
+
console.log('✅ Database connected\n');
|
|
68
|
+
const manager = new migration_manager_1.MigrationManager(dataSource, options.migrationsPath);
|
|
69
|
+
console.log(`🔍 Rolling back last ${count} migration(s)...\n`);
|
|
70
|
+
const results = await manager.rollback(count);
|
|
71
|
+
if (results.length === 0) {
|
|
72
|
+
console.log('⚠️ No migrations to rollback');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
console.log('📊 Rollback Results:\n');
|
|
76
|
+
results.forEach((result) => {
|
|
77
|
+
const status = result.success ? '✅' : '❌';
|
|
78
|
+
const time = `(${result.executionTime}ms)`;
|
|
79
|
+
console.log(` ${status} ${result.version} ${result.name} ${time}`);
|
|
80
|
+
if (!result.success && result.error) {
|
|
81
|
+
console.log(` Error: ${result.error}`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const allSuccessful = results.every((r) => r.success);
|
|
85
|
+
if (allSuccessful) {
|
|
86
|
+
console.log('\n✅ All rollbacks completed successfully');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log('\n❌ Some rollbacks failed');
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error('❌ Rollback execution failed:');
|
|
95
|
+
console.error(error instanceof Error ? error.message : 'Unknown error occurred');
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (dataSource?.isInitialized) {
|
|
100
|
+
await dataSource.destroy();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function createMigrationRollbackCommand() {
|
|
105
|
+
const command = new commander_1.Command('migration:rollback');
|
|
106
|
+
command
|
|
107
|
+
.description('Rollback Event-Forge migrations')
|
|
108
|
+
.requiredOption('-d, --data-source <path>', 'Path to TypeORM DataSource configuration file')
|
|
109
|
+
.option('-m, --migrations-path <path>', 'Custom migrations directory path')
|
|
110
|
+
.option('-c, --count <number>', 'Number of migrations to rollback', '1')
|
|
111
|
+
.action(async (options) => {
|
|
112
|
+
await executeMigrationRollback(options);
|
|
113
|
+
});
|
|
114
|
+
return command;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=migration-rollback-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-rollback-command.js","sourceRoot":"","sources":["../../src/cli/migration-rollback-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,4DA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1D,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC9C,OAAO,CAAC,KAAK,CACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAClE,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,IAAI,UAAU,EAAE,aAAa,EAAE,CAAC;YAC9B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC;AAKD,SAAgB,8BAA8B;IAC5C,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,oBAAoB,CAAC,CAAC;IAElD,OAAO;SACJ,WAAW,CAAC,iCAAiC,CAAC;SAC9C,cAAc,CACb,0BAA0B,EAC1B,+CAA+C,CAChD;SACA,MAAM,CACL,8BAA8B,EAC9B,kCAAkC,CACnC;SACA,MAAM,CAAC,sBAAsB,EAAE,kCAAkC,EAAE,GAAG,CAAC;SACvE,MAAM,CAAC,KAAK,EAAE,OAAiC,EAAE,EAAE;QAClD,MAAM,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface MigrationRunOptions {
|
|
3
|
+
dataSource: string;
|
|
4
|
+
migrationsPath?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function executeMigrationRun(options: MigrationRunOptions): Promise<void>;
|
|
7
|
+
export declare function createMigrationRunCommand(): Command;
|
|
8
|
+
//# sourceMappingURL=migration-run-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-run-command.d.ts","sourceRoot":"","sources":["../../src/cli/migration-run-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,WAAW,mBAAmB;IAElC,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAmCD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA8Df;AAKD,wBAAgB,yBAAyB,IAAI,OAAO,CAkBnD"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.executeMigrationRun = executeMigrationRun;
|
|
37
|
+
exports.createMigrationRunCommand = createMigrationRunCommand;
|
|
38
|
+
const commander_1 = require("commander");
|
|
39
|
+
const typeorm_1 = require("typeorm");
|
|
40
|
+
const migration_manager_1 = require("../migrations/migration-manager");
|
|
41
|
+
async function loadDataSource(configPath) {
|
|
42
|
+
try {
|
|
43
|
+
const module = (await Promise.resolve(`${configPath}`).then(s => __importStar(require(s))));
|
|
44
|
+
const dataSource = module.default || module.AppDataSource;
|
|
45
|
+
if (!dataSource || !(dataSource instanceof typeorm_1.DataSource)) {
|
|
46
|
+
throw new Error('Configuration file must export a TypeORM DataSource instance');
|
|
47
|
+
}
|
|
48
|
+
return dataSource;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error(`Failed to load DataSource from ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function executeMigrationRun(options) {
|
|
55
|
+
let dataSource = null;
|
|
56
|
+
try {
|
|
57
|
+
console.log('🔄 Loading DataSource configuration...');
|
|
58
|
+
dataSource = await loadDataSource(options.dataSource);
|
|
59
|
+
if (!dataSource.isInitialized) {
|
|
60
|
+
console.log('🔌 Initializing database connection...');
|
|
61
|
+
await dataSource.initialize();
|
|
62
|
+
}
|
|
63
|
+
console.log('✅ Database connected\n');
|
|
64
|
+
const manager = new migration_manager_1.MigrationManager(dataSource, options.migrationsPath);
|
|
65
|
+
console.log('🔍 Discovering pending migrations...');
|
|
66
|
+
const pending = await manager.getPendingMigrations();
|
|
67
|
+
if (pending.length === 0) {
|
|
68
|
+
console.log('✅ No pending migrations found');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`📋 Found ${pending.length} pending migration(s):\n`);
|
|
72
|
+
pending.forEach((m) => {
|
|
73
|
+
console.log(` - ${m.version} ${m.name}`);
|
|
74
|
+
});
|
|
75
|
+
console.log('\n🚀 Running migrations...\n');
|
|
76
|
+
const results = await manager.runPendingMigrations();
|
|
77
|
+
console.log('📊 Migration Results:\n');
|
|
78
|
+
results.forEach((result) => {
|
|
79
|
+
const status = result.success ? '✅' : '❌';
|
|
80
|
+
const time = `(${result.executionTime}ms)`;
|
|
81
|
+
console.log(` ${status} ${result.version} ${result.name} ${time}`);
|
|
82
|
+
if (!result.success && result.error) {
|
|
83
|
+
console.log(` Error: ${result.error}`);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const allSuccessful = results.every((r) => r.success);
|
|
87
|
+
if (allSuccessful) {
|
|
88
|
+
console.log('\n✅ All migrations completed successfully');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log('\n❌ Some migrations failed');
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error('❌ Migration execution failed:');
|
|
97
|
+
console.error(error instanceof Error ? error.message : 'Unknown error occurred');
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
if (dataSource?.isInitialized) {
|
|
102
|
+
await dataSource.destroy();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function createMigrationRunCommand() {
|
|
107
|
+
const command = new commander_1.Command('migration:run');
|
|
108
|
+
command
|
|
109
|
+
.description('Run pending Event-Forge migrations')
|
|
110
|
+
.requiredOption('-d, --data-source <path>', 'Path to TypeORM DataSource configuration file')
|
|
111
|
+
.option('-m, --migrations-path <path>', 'Custom migrations directory path')
|
|
112
|
+
.action(async (options) => {
|
|
113
|
+
await executeMigrationRun(options);
|
|
114
|
+
});
|
|
115
|
+
return command;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=migration-run-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-run-command.js","sourceRoot":"","sources":["../../src/cli/migration-run-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,kDAgEC;AAKD,8DAkBC;AAvID,yCAAoC;AACpC,qCAAqC;AAErC,uEAAmE;AAuBnE,KAAK,UAAU,cAAc,CAAC,UAAkB;IAC9C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,yBAAa,UAAU,uCAAC,CAAqB,CAAC;QAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,aAAa,CAAC;QAE1D,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,YAAY,oBAAU,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;QACJ,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,kCAAkC,UAAU,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC1G,CAAC;IACJ,CAAC;AACH,CAAC;AAKM,KAAK,UAAU,mBAAmB,CACvC,OAA4B;IAE5B,IAAI,UAAU,GAAsB,IAAI,CAAC;IAEzC,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACtD,UAAU,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,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,EAAE;QAC7C,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-forge-migration.entity.d.ts","sourceRoot":"","sources":["../../src/entities/event-forge-migration.entity.ts"],"names":[],"mappings":"AAeA,qBAEa,yBAAyB;IAEpC,EAAE,EAAE,MAAM,CAAC;IAGX,OAAO,EAAE,MAAM,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IAGb,SAAS,EAAE,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EventForgeMigrationEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let EventForgeMigrationEntity = class EventForgeMigrationEntity {
|
|
15
|
+
id;
|
|
16
|
+
version;
|
|
17
|
+
name;
|
|
18
|
+
appliedAt;
|
|
19
|
+
};
|
|
20
|
+
exports.EventForgeMigrationEntity = EventForgeMigrationEntity;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('increment'),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], EventForgeMigrationEntity.prototype, "id", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255 }),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], EventForgeMigrationEntity.prototype, "version", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255 }),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], EventForgeMigrationEntity.prototype, "name", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typeorm_1.CreateDateColumn)({ name: 'applied_at' }),
|
|
35
|
+
__metadata("design:type", Date)
|
|
36
|
+
], EventForgeMigrationEntity.prototype, "appliedAt", void 0);
|
|
37
|
+
exports.EventForgeMigrationEntity = EventForgeMigrationEntity = __decorate([
|
|
38
|
+
(0, typeorm_1.Entity)('event_forge_migrations'),
|
|
39
|
+
(0, typeorm_1.Index)('idx_ef_migration_version', ['version'], { unique: true })
|
|
40
|
+
], EventForgeMigrationEntity);
|
|
41
|
+
//# sourceMappingURL=event-forge-migration.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-forge-migration.entity.js","sourceRoot":"","sources":["../../src/entities/event-forge-migration.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAMiB;AAWV,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAEpC,EAAE,CAAS;IAGX,OAAO,CAAS;IAGhB,IAAI,CAAS;IAGb,SAAS,CAAO;CACjB,CAAA;AAZY,8DAAyB;AAEpC;IADC,IAAA,gCAAsB,EAAC,WAAW,CAAC;;qDACzB;AAGX;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;0DACzB;AAGhB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;uDAC5B;AAGb;IADC,IAAA,0BAAgB,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;8BAC9B,IAAI;4DAAC;oCAXL,yBAAyB;IAFrC,IAAA,gBAAM,EAAC,wBAAwB,CAAC;IAChC,IAAA,eAAK,EAAC,0BAA0B,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACpD,yBAAyB,CAYrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox-message.entity.d.ts","sourceRoot":"","sources":["../../src/entities/inbox-message.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAcjF,qBAMa,kBAAmB,YAAW,YAAY;IAErD,EAAE,EAAE,MAAM,CAAC;IAGX,SAAS,EAAE,MAAM,CAAC;IAGlB,MAAM,EAAE,MAAM,CAAC;IAGf,SAAS,EAAE,MAAM,CAAC;IAGlB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAOjC,MAAM,EAAE,kBAAkB,CAAC;IAG3B,WAAW,CAAC,EAAE,IAAI,CAAC;IAGnB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,SAAS,EAAE,IAAI,CAAC;IAGhB,UAAU,EAAE,IAAI,CAAC;CAClB"}
|
|
1
|
+
{"version":3,"file":"inbox-message.entity.d.ts","sourceRoot":"","sources":["../../src/entities/inbox-message.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAcjF,qBAMa,kBAAmB,YAAW,YAAY;IAErD,EAAE,EAAE,MAAM,CAAC;IAGX,SAAS,EAAE,MAAM,CAAC;IAGlB,MAAM,EAAE,MAAM,CAAC;IAGf,SAAS,EAAE,MAAM,CAAC;IAGlB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAOjC,MAAM,EAAE,kBAAkB,CAAC;IAG3B,WAAW,CAAC,EAAE,IAAI,CAAC;IAGnB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,UAAU,EAAE,MAAM,CAAC;IAGnB,UAAU,EAAE,MAAM,CAAC;IAGnB,WAAW,CAAC,EAAE,IAAI,CAAC;IAGnB,SAAS,EAAE,IAAI,CAAC;IAGhB,UAAU,EAAE,IAAI,CAAC;CAClB"}
|
|
@@ -21,6 +21,9 @@ let InboxMessageEntity = class InboxMessageEntity {
|
|
|
21
21
|
status;
|
|
22
22
|
processedAt;
|
|
23
23
|
errorMessage;
|
|
24
|
+
retryCount;
|
|
25
|
+
maxRetries;
|
|
26
|
+
scheduledAt;
|
|
24
27
|
createdAt;
|
|
25
28
|
receivedAt;
|
|
26
29
|
};
|
|
@@ -61,6 +64,18 @@ __decorate([
|
|
|
61
64
|
(0, typeorm_1.Column)({ name: 'error_message', type: 'text', nullable: true }),
|
|
62
65
|
__metadata("design:type", String)
|
|
63
66
|
], InboxMessageEntity.prototype, "errorMessage", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, typeorm_1.Column)({ name: 'retry_count', type: 'int', default: 0 }),
|
|
69
|
+
__metadata("design:type", Number)
|
|
70
|
+
], InboxMessageEntity.prototype, "retryCount", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, typeorm_1.Column)({ name: 'max_retries', type: 'int', default: 3 }),
|
|
73
|
+
__metadata("design:type", Number)
|
|
74
|
+
], InboxMessageEntity.prototype, "maxRetries", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, typeorm_1.Column)({ name: 'scheduled_at', type: 'timestamptz', nullable: true }),
|
|
77
|
+
__metadata("design:type", Date)
|
|
78
|
+
], InboxMessageEntity.prototype, "scheduledAt", void 0);
|
|
64
79
|
__decorate([
|
|
65
80
|
(0, typeorm_1.CreateDateColumn)({ name: 'created_at' }),
|
|
66
81
|
__metadata("design:type", Date)
|