dbdock 1.1.15 → 1.1.17
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 +473 -580
- package/dist/cli/commands/analyze.d.ts +1 -0
- package/dist/cli/commands/analyze.js +135 -0
- package/dist/cli/commands/analyze.js.map +1 -0
- package/dist/cli/commands/cross-migrate.d.ts +11 -0
- package/dist/cli/commands/cross-migrate.js +307 -0
- package/dist/cli/commands/cross-migrate.js.map +1 -0
- package/dist/cli/index.js +20 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/migration/analyzers/mongodb.analyzer.d.ts +3 -0
- package/dist/migration/analyzers/mongodb.analyzer.js +208 -0
- package/dist/migration/analyzers/mongodb.analyzer.js.map +1 -0
- package/dist/migration/analyzers/postgres.analyzer.d.ts +3 -0
- package/dist/migration/analyzers/postgres.analyzer.js +176 -0
- package/dist/migration/analyzers/postgres.analyzer.js.map +1 -0
- package/dist/migration/config.manager.d.ts +3 -0
- package/dist/migration/config.manager.js +80 -0
- package/dist/migration/config.manager.js.map +1 -0
- package/dist/migration/engines/migration.engine.d.ts +6 -0
- package/dist/migration/engines/migration.engine.js +62 -0
- package/dist/migration/engines/migration.engine.js.map +1 -0
- package/dist/migration/engines/mongo-to-postgres.engine.d.ts +2 -0
- package/dist/migration/engines/mongo-to-postgres.engine.js +409 -0
- package/dist/migration/engines/mongo-to-postgres.engine.js.map +1 -0
- package/dist/migration/engines/postgres-to-mongo.engine.d.ts +2 -0
- package/dist/migration/engines/postgres-to-mongo.engine.js +192 -0
- package/dist/migration/engines/postgres-to-mongo.engine.js.map +1 -0
- package/dist/migration/mappers/mongo-to-postgres.mapper.d.ts +2 -0
- package/dist/migration/mappers/mongo-to-postgres.mapper.js +263 -0
- package/dist/migration/mappers/mongo-to-postgres.mapper.js.map +1 -0
- package/dist/migration/mappers/postgres-to-mongo.mapper.d.ts +2 -0
- package/dist/migration/mappers/postgres-to-mongo.mapper.js +174 -0
- package/dist/migration/mappers/postgres-to-mongo.mapper.js.map +1 -0
- package/dist/migration/reference.detector.d.ts +2 -0
- package/dist/migration/reference.detector.js +57 -0
- package/dist/migration/reference.detector.js.map +1 -0
- package/dist/migration/type.mapper.d.ts +12 -0
- package/dist/migration/type.mapper.js +197 -0
- package/dist/migration/type.mapper.js.map +1 -0
- package/dist/migration/types.d.ts +183 -0
- package/dist/migration/types.js +11 -0
- package/dist/migration/types.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectIdToUuid = objectIdToUuid;
|
|
4
|
+
exports.mongoTypeToPgType = mongoTypeToPgType;
|
|
5
|
+
exports.pgTypeToMongoType = pgTypeToMongoType;
|
|
6
|
+
exports.detectMongoFieldType = detectMongoFieldType;
|
|
7
|
+
exports.resolveMajorityType = resolveMajorityType;
|
|
8
|
+
exports.coerceValue = coerceValue;
|
|
9
|
+
exports.singularize = singularize;
|
|
10
|
+
exports.toSnakeCase = toSnakeCase;
|
|
11
|
+
exports.pluralize = pluralize;
|
|
12
|
+
const uuid_1 = require("uuid");
|
|
13
|
+
const DBDOCK_UUID_NAMESPACE = '9f5b5c5a-7b1a-4e3d-b8f2-1a2b3c4d5e6f';
|
|
14
|
+
function objectIdToUuid(objectId) {
|
|
15
|
+
return (0, uuid_1.v5)(objectId, DBDOCK_UUID_NAMESPACE);
|
|
16
|
+
}
|
|
17
|
+
function mongoTypeToPgType(mongoType) {
|
|
18
|
+
const typeMap = {
|
|
19
|
+
string: 'text',
|
|
20
|
+
number: 'numeric',
|
|
21
|
+
int: 'integer',
|
|
22
|
+
long: 'bigint',
|
|
23
|
+
double: 'double precision',
|
|
24
|
+
decimal: 'numeric',
|
|
25
|
+
boolean: 'boolean',
|
|
26
|
+
date: 'timestamptz',
|
|
27
|
+
objectId: 'uuid',
|
|
28
|
+
binData: 'bytea',
|
|
29
|
+
null: 'text',
|
|
30
|
+
regex: 'text',
|
|
31
|
+
timestamp: 'timestamptz',
|
|
32
|
+
undefined: 'text',
|
|
33
|
+
};
|
|
34
|
+
return typeMap[mongoType] || 'jsonb';
|
|
35
|
+
}
|
|
36
|
+
function pgTypeToMongoType(pgType) {
|
|
37
|
+
const normalized = pgType.toLowerCase();
|
|
38
|
+
if (['integer', 'smallint', 'int2', 'int4', 'serial', 'smallserial'].includes(normalized))
|
|
39
|
+
return 'int';
|
|
40
|
+
if (['bigint', 'int8', 'bigserial'].includes(normalized))
|
|
41
|
+
return 'long';
|
|
42
|
+
if ([
|
|
43
|
+
'numeric',
|
|
44
|
+
'decimal',
|
|
45
|
+
'real',
|
|
46
|
+
'float4',
|
|
47
|
+
'double precision',
|
|
48
|
+
'float8',
|
|
49
|
+
].includes(normalized))
|
|
50
|
+
return 'double';
|
|
51
|
+
if (['boolean', 'bool'].includes(normalized))
|
|
52
|
+
return 'bool';
|
|
53
|
+
if ([
|
|
54
|
+
'timestamp',
|
|
55
|
+
'timestamptz',
|
|
56
|
+
'timestamp without time zone',
|
|
57
|
+
'timestamp with time zone',
|
|
58
|
+
'date',
|
|
59
|
+
'time',
|
|
60
|
+
'timetz',
|
|
61
|
+
].includes(normalized))
|
|
62
|
+
return 'date';
|
|
63
|
+
if (['uuid'].includes(normalized))
|
|
64
|
+
return 'string';
|
|
65
|
+
if (['jsonb', 'json'].includes(normalized))
|
|
66
|
+
return 'object';
|
|
67
|
+
if (['bytea'].includes(normalized))
|
|
68
|
+
return 'binData';
|
|
69
|
+
if (normalized.endsWith('[]'))
|
|
70
|
+
return 'array';
|
|
71
|
+
return 'string';
|
|
72
|
+
}
|
|
73
|
+
function detectMongoFieldType(value) {
|
|
74
|
+
if (value === null)
|
|
75
|
+
return 'null';
|
|
76
|
+
if (value === undefined)
|
|
77
|
+
return 'undefined';
|
|
78
|
+
if (typeof value === 'string')
|
|
79
|
+
return 'string';
|
|
80
|
+
if (typeof value === 'boolean')
|
|
81
|
+
return 'boolean';
|
|
82
|
+
if (typeof value === 'number') {
|
|
83
|
+
if (Number.isInteger(value)) {
|
|
84
|
+
if (value > 2147483647 || value < -2147483648)
|
|
85
|
+
return 'long';
|
|
86
|
+
return 'int';
|
|
87
|
+
}
|
|
88
|
+
return 'double';
|
|
89
|
+
}
|
|
90
|
+
if (value instanceof Date)
|
|
91
|
+
return 'date';
|
|
92
|
+
if (Array.isArray(value))
|
|
93
|
+
return 'array';
|
|
94
|
+
if (typeof value === 'object') {
|
|
95
|
+
if (value._bsontype === 'ObjectId' || value._bsontype === 'ObjectID')
|
|
96
|
+
return 'objectId';
|
|
97
|
+
if (value._bsontype === 'Decimal128')
|
|
98
|
+
return 'decimal';
|
|
99
|
+
if (value._bsontype === 'Long')
|
|
100
|
+
return 'long';
|
|
101
|
+
if (value._bsontype === 'Binary')
|
|
102
|
+
return 'binData';
|
|
103
|
+
if (value._bsontype === 'Timestamp')
|
|
104
|
+
return 'timestamp';
|
|
105
|
+
if (value._bsontype === 'BSONRegExp')
|
|
106
|
+
return 'regex';
|
|
107
|
+
const oid = value.toString?.();
|
|
108
|
+
if (oid && /^[a-f0-9]{24}$/.test(oid) && value.constructor?.name === 'ObjectId')
|
|
109
|
+
return 'objectId';
|
|
110
|
+
return 'object';
|
|
111
|
+
}
|
|
112
|
+
return 'string';
|
|
113
|
+
}
|
|
114
|
+
function resolveMajorityType(typeCounts) {
|
|
115
|
+
const entries = Object.entries(typeCounts).filter(([t]) => t !== 'null' && t !== 'undefined');
|
|
116
|
+
if (entries.length === 0)
|
|
117
|
+
return 'string';
|
|
118
|
+
entries.sort((a, b) => b[1] - a[1]);
|
|
119
|
+
return entries[0][0];
|
|
120
|
+
}
|
|
121
|
+
function coerceValue(value, fromType, toType) {
|
|
122
|
+
try {
|
|
123
|
+
if (value === null || value === undefined)
|
|
124
|
+
return { success: true, value: null };
|
|
125
|
+
if (fromType === toType)
|
|
126
|
+
return { success: true, value };
|
|
127
|
+
if (toType === 'numeric' || toType === 'double precision' || toType === 'integer' || toType === 'bigint') {
|
|
128
|
+
const num = Number(value);
|
|
129
|
+
if (isNaN(num))
|
|
130
|
+
return { success: false, value };
|
|
131
|
+
if (toType === 'integer' && !Number.isInteger(num))
|
|
132
|
+
return { success: true, value: Math.round(num) };
|
|
133
|
+
return { success: true, value: num };
|
|
134
|
+
}
|
|
135
|
+
if (toType === 'text')
|
|
136
|
+
return { success: true, value: String(value) };
|
|
137
|
+
if (toType === 'boolean') {
|
|
138
|
+
if (typeof value === 'string') {
|
|
139
|
+
if (['true', '1', 'yes'].includes(value.toLowerCase()))
|
|
140
|
+
return { success: true, value: true };
|
|
141
|
+
if (['false', '0', 'no'].includes(value.toLowerCase()))
|
|
142
|
+
return { success: true, value: false };
|
|
143
|
+
return { success: false, value };
|
|
144
|
+
}
|
|
145
|
+
return { success: true, value: Boolean(value) };
|
|
146
|
+
}
|
|
147
|
+
if (toType === 'timestamptz') {
|
|
148
|
+
const d = new Date(value);
|
|
149
|
+
if (isNaN(d.getTime()))
|
|
150
|
+
return { success: false, value };
|
|
151
|
+
return { success: true, value: d };
|
|
152
|
+
}
|
|
153
|
+
if (toType === 'uuid') {
|
|
154
|
+
if (typeof value === 'string' && /^[a-f0-9]{24}$/.test(value)) {
|
|
155
|
+
return { success: true, value: objectIdToUuid(value) };
|
|
156
|
+
}
|
|
157
|
+
if (typeof value === 'object' && value.toString) {
|
|
158
|
+
const str = value.toString();
|
|
159
|
+
if (/^[a-f0-9]{24}$/.test(str)) {
|
|
160
|
+
return { success: true, value: objectIdToUuid(str) };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { success: true, value: String(value) };
|
|
164
|
+
}
|
|
165
|
+
return { success: true, value };
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return { success: false, value };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function singularize(word) {
|
|
172
|
+
if (word.endsWith('ies'))
|
|
173
|
+
return word.slice(0, -3) + 'y';
|
|
174
|
+
if (word.endsWith('ses') || word.endsWith('xes') || word.endsWith('zes'))
|
|
175
|
+
return word.slice(0, -2);
|
|
176
|
+
if (word.endsWith('s') && !word.endsWith('ss'))
|
|
177
|
+
return word.slice(0, -1);
|
|
178
|
+
return word;
|
|
179
|
+
}
|
|
180
|
+
function toSnakeCase(str) {
|
|
181
|
+
return str
|
|
182
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
183
|
+
.replace(/[\s\-\.]+/g, '_')
|
|
184
|
+
.toLowerCase();
|
|
185
|
+
}
|
|
186
|
+
function pluralize(word) {
|
|
187
|
+
if (word.endsWith('y') && !/[aeiou]y$/.test(word))
|
|
188
|
+
return word.slice(0, -1) + 'ies';
|
|
189
|
+
if (word.endsWith('s') ||
|
|
190
|
+
word.endsWith('x') ||
|
|
191
|
+
word.endsWith('z') ||
|
|
192
|
+
word.endsWith('ch') ||
|
|
193
|
+
word.endsWith('sh'))
|
|
194
|
+
return word + 'es';
|
|
195
|
+
return word + 's';
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=type.mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.mapper.js","sourceRoot":"","sources":["../../src/migration/type.mapper.ts"],"names":[],"mappings":";;AAIA,wCAEC;AAED,8CAkBC;AAED,8CAwCC;AAED,oDAkCC;AAED,kDASC;AAED,kCAuDC;AAED,kCAMC;AAED,kCAKC;AAED,8BAYC;AAzMD,+BAAoC;AAEpC,MAAM,qBAAqB,GAAG,sCAAsC,CAAC;AAErE,SAAgB,cAAc,CAAC,QAAgB;IAC7C,OAAO,IAAA,SAAM,EAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;AACjD,CAAC;AAED,SAAgB,iBAAiB,CAAC,SAAiB;IACjD,MAAM,OAAO,GAA2B;QACtC,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,SAAS;QACjB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,kBAAk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atabaseUrl {
|
|
3
|
+
type: DatabaseType;
|
|
4
|
+
url: string;
|
|
5
|
+
database: string;
|
|
6
|
+
host: string;
|
|
7
|
+
port: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MongoFieldInfo {
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
types: Record<string, number>;
|
|
13
|
+
totalCount: number;
|
|
14
|
+
frequency: number;
|
|
15
|
+
isArray: boolean;
|
|
16
|
+
isObjectId: boolean;
|
|
17
|
+
isNestedObject: boolean;
|
|
18
|
+
nestedFields?: MongoFieldInfo[];
|
|
19
|
+
arrayElementType?: string;
|
|
20
|
+
possibleReference?: string;
|
|
21
|
+
sampleValues: any[];
|
|
22
|
+
depth: number;
|
|
23
|
+
}
|
|
24
|
+
export interface MongoCollectionAnalysis {
|
|
25
|
+
name: string;
|
|
26
|
+
documentCount: number;
|
|
27
|
+
fields: MongoFieldInfo[];
|
|
28
|
+
indexes: Array<{
|
|
29
|
+
name: string;
|
|
30
|
+
key: Record<string, number>;
|
|
31
|
+
unique?: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export interface MongoAnalysisResult {
|
|
35
|
+
database: string;
|
|
36
|
+
type: 'mongodb';
|
|
37
|
+
collections: MongoCollectionAnalysis[];
|
|
38
|
+
totalDocuments: number;
|
|
39
|
+
}
|
|
40
|
+
export interface PgColumnInfo {
|
|
41
|
+
name: string;
|
|
42
|
+
dataType: string;
|
|
43
|
+
udtName: string;
|
|
44
|
+
isNullable: boolean;
|
|
45
|
+
columnDefault: string | null;
|
|
46
|
+
isPrimaryKey: boolean;
|
|
47
|
+
isUnique: boolean;
|
|
48
|
+
characterMaxLength: number | null;
|
|
49
|
+
numericPrecision: number | null;
|
|
50
|
+
}
|
|
51
|
+
export interface PgForeignKey {
|
|
52
|
+
constraintName: string;
|
|
53
|
+
columnName: string;
|
|
54
|
+
referencedTable: string;
|
|
55
|
+
referencedColumn: string;
|
|
56
|
+
}
|
|
57
|
+
export interface PgIndexInfo {
|
|
58
|
+
name: string;
|
|
59
|
+
columns: string[];
|
|
60
|
+
isUnique: boolean;
|
|
61
|
+
isPrimary: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface PgTableAnalysis {
|
|
64
|
+
name: string;
|
|
65
|
+
schema: string;
|
|
66
|
+
columns: PgColumnInfo[];
|
|
67
|
+
foreignKeys: PgForeignKey[];
|
|
68
|
+
indexes: PgIndexInfo[];
|
|
69
|
+
rowCount: number;
|
|
70
|
+
}
|
|
71
|
+
export interface PgAnalysisResult {
|
|
72
|
+
database: string;
|
|
73
|
+
type: 'postgresql';
|
|
74
|
+
tables: PgTableAnalysis[];
|
|
75
|
+
totalRows: number;
|
|
76
|
+
}
|
|
77
|
+
export type AnalysisResult = MongoAnalysisResult | PgAnalysisResult;
|
|
78
|
+
export interface FieldMapping {
|
|
79
|
+
sourceField: string;
|
|
80
|
+
targetColumn: string;
|
|
81
|
+
targetType: string;
|
|
82
|
+
transform?: 'cast' | 'jsonb' | 'array' | 'uuid_from_objectid';
|
|
83
|
+
nullable: boolean;
|
|
84
|
+
isUnique: boolean;
|
|
85
|
+
isPrimaryKey: boolean;
|
|
86
|
+
defaultValue?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface NestedMapping {
|
|
89
|
+
sourceField: string;
|
|
90
|
+
targetTable: string;
|
|
91
|
+
strategy: 'table' | 'jsonb';
|
|
92
|
+
parentForeignKey: string;
|
|
93
|
+
fields?: FieldMapping[];
|
|
94
|
+
relationType: '1:1' | '1:many';
|
|
95
|
+
}
|
|
96
|
+
export interface ArrayMapping {
|
|
97
|
+
sourceField: string;
|
|
98
|
+
targetTable: string;
|
|
99
|
+
strategy: 'junction' | 'array_column' | 'child_table';
|
|
100
|
+
parentForeignKey: string;
|
|
101
|
+
elementType?: string;
|
|
102
|
+
fields?: FieldMapping[];
|
|
103
|
+
}
|
|
104
|
+
export interface DetectedReference {
|
|
105
|
+
sourceField: string;
|
|
106
|
+
targetCollection: string;
|
|
107
|
+
foreignKeyColumn: string;
|
|
108
|
+
foreignKeyTable: string;
|
|
109
|
+
}
|
|
110
|
+
export interface TableMapping {
|
|
111
|
+
sourceCollection: string;
|
|
112
|
+
targetTable: string;
|
|
113
|
+
fields: FieldMapping[];
|
|
114
|
+
nestedMappings: NestedMapping[];
|
|
115
|
+
arrayMappings: ArrayMapping[];
|
|
116
|
+
detectedReferences: DetectedReference[];
|
|
117
|
+
}
|
|
118
|
+
export interface EmbedConfig {
|
|
119
|
+
sourceTable: string;
|
|
120
|
+
foreignKey: string;
|
|
121
|
+
embedAs: string;
|
|
122
|
+
isArray: boolean;
|
|
123
|
+
}
|
|
124
|
+
export interface RefConfig {
|
|
125
|
+
sourceTable: string;
|
|
126
|
+
foreignKey: string;
|
|
127
|
+
refField: string;
|
|
128
|
+
}
|
|
129
|
+
export interface DocumentMapping {
|
|
130
|
+
primaryTable: string;
|
|
131
|
+
targetCollection: string;
|
|
132
|
+
fieldMappings: Record<string, string>;
|
|
133
|
+
embeddings: EmbedConfig[];
|
|
134
|
+
references: RefConfig[];
|
|
135
|
+
}
|
|
136
|
+
export interface MigrationConflict {
|
|
137
|
+
type: 'type_mismatch' | 'missing_field' | 'reference_ambiguous';
|
|
138
|
+
location: string;
|
|
139
|
+
field: string;
|
|
140
|
+
details: string;
|
|
141
|
+
suggestion: string;
|
|
142
|
+
}
|
|
143
|
+
export interface MigrationOptions {
|
|
144
|
+
batchSize: number;
|
|
145
|
+
maxNestingDepth: number;
|
|
146
|
+
dryRun: boolean;
|
|
147
|
+
incremental: boolean;
|
|
148
|
+
since?: string;
|
|
149
|
+
createErrorsTable: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface MigrationPlan {
|
|
152
|
+
version: string;
|
|
153
|
+
direction: 'mongo_to_postgres' | 'postgres_to_mongo';
|
|
154
|
+
source: {
|
|
155
|
+
type: DatabaseType;
|
|
156
|
+
url: string;
|
|
157
|
+
database: string;
|
|
158
|
+
};
|
|
159
|
+
target: {
|
|
160
|
+
type: DatabaseType;
|
|
161
|
+
url: string;
|
|
162
|
+
database: string;
|
|
163
|
+
};
|
|
164
|
+
tableMappings?: TableMapping[];
|
|
165
|
+
documentMappings?: DocumentMapping[];
|
|
166
|
+
conflicts: MigrationConflict[];
|
|
167
|
+
options: MigrationOptions;
|
|
168
|
+
}
|
|
169
|
+
export interface TableMigrationResult {
|
|
170
|
+
name: string;
|
|
171
|
+
sourceCount: number;
|
|
172
|
+
targetCount: number;
|
|
173
|
+
failedCount: number;
|
|
174
|
+
status: 'success' | 'partial' | 'failed';
|
|
175
|
+
}
|
|
176
|
+
export interface MigrationResult {
|
|
177
|
+
success: boolean;
|
|
178
|
+
tables: TableMigrationResult[];
|
|
179
|
+
totalErrors: number;
|
|
180
|
+
duration: number;
|
|
181
|
+
dryRun: boolean;
|
|
182
|
+
}
|
|
183
|
+
export declare const DEFAULT_MIGRATION_OPTIONS: MigrationOptions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MIGRATION_OPTIONS = void 0;
|
|
4
|
+
exports.DEFAULT_MIGRATION_OPTIONS = {
|
|
5
|
+
batchSize: 1000,
|
|
6
|
+
maxNestingDepth: 2,
|
|
7
|
+
dryRun: false,
|
|
8
|
+
incremental: false,
|
|
9
|
+
createErrorsTable: true,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/migration/types.ts"],"names":[],"mappings":";;;AAsMa,QAAA,yBAAyB,GAAqB;IACzD,SAAS,EAAE,IAAI;IACf,eAAe,EAAE,CAAC;IAClB,MAAM,EAAE,KAAK;IACb,WAAW,EAAE,KAAK;IAClB,iBAAiB,EAAE,IAAI;CACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbdock",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Enterprise-grade
|
|
3
|
+
"version": "1.1.17",
|
|
4
|
+
"description": "Enterprise-grade database backup, restore, and cross-database migration (MongoDB ↔ PostgreSQL). CLI-first tool with encryption, compression, and multi-cloud storage.",
|
|
5
5
|
"author": "Naheem Olaide <naheemolaide@gmail.com>",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "MIT",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"keywords": [
|
|
21
21
|
"postgresql",
|
|
22
22
|
"postgres",
|
|
23
|
+
"mongodb",
|
|
24
|
+
"migration",
|
|
25
|
+
"cross-database",
|
|
26
|
+
"schema-migration",
|
|
23
27
|
"backup",
|
|
24
28
|
"restore",
|
|
25
29
|
"database",
|
|
@@ -92,8 +96,11 @@
|
|
|
92
96
|
"commander": "^14.0.2",
|
|
93
97
|
"dotenv": "^17.2.3",
|
|
94
98
|
"inquirer": "^9.3.8",
|
|
99
|
+
"js-yaml": "^4.1.1",
|
|
100
|
+
"mongodb": "^7.1.0",
|
|
95
101
|
"nodemailer": "^7.0.10",
|
|
96
102
|
"ora": "^9.0.0",
|
|
103
|
+
"pg": "^8.20.0",
|
|
97
104
|
"reflect-metadata": "^0.2.2",
|
|
98
105
|
"rxjs": "^7.8.1",
|
|
99
106
|
"uuid": "^13.0.0"
|
|
@@ -107,8 +114,10 @@
|
|
|
107
114
|
"@types/express": "^5.0.0",
|
|
108
115
|
"@types/inquirer": "^9.0.9",
|
|
109
116
|
"@types/jest": "^30.0.0",
|
|
117
|
+
"@types/js-yaml": "^4.0.9",
|
|
110
118
|
"@types/node": "^22.10.7",
|
|
111
119
|
"@types/nodemailer": "^7.0.4",
|
|
120
|
+
"@types/pg": "^8.18.0",
|
|
112
121
|
"@types/supertest": "^6.0.2",
|
|
113
122
|
"eslint": "^9.18.0",
|
|
114
123
|
"eslint-config-prettier": "^10.0.1",
|