@zintrust/d1-migrator 0.4.0 → 0.4.4
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/LICENSE.md +21 -0
- package/dist/build-manifest.json +179 -0
- package/dist/cli/DataMigrator.js +2 -2
- package/dist/cli/MigrateToD1Command.js +4 -4
- package/dist/index.js +9 -9
- package/dist/register.d.ts +3 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +28 -0
- package/dist/schema/SchemaBuilder.js +2 -2
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -8
- package/README.md +0 -871
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ZinTrust
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zintrust/d1-migrator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"buildDate": "2026-03-20T13:11:40.471Z",
|
|
5
|
+
"buildEnvironment": {
|
|
6
|
+
"node": "v22.22.1",
|
|
7
|
+
"platform": "darwin",
|
|
8
|
+
"arch": "arm64"
|
|
9
|
+
},
|
|
10
|
+
"git": {
|
|
11
|
+
"commit": "e0e7e31c",
|
|
12
|
+
"branch": "release"
|
|
13
|
+
},
|
|
14
|
+
"package": {
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20.0.0"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": [
|
|
19
|
+
"@zintrust/db-mysql",
|
|
20
|
+
"@zintrust/db-postgres",
|
|
21
|
+
"@zintrust/db-sqlite",
|
|
22
|
+
"@zintrust/db-sqlserver",
|
|
23
|
+
"@zintrust/db-d1"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": [
|
|
26
|
+
"@zintrust/core"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"files": {
|
|
30
|
+
"build-manifest.json": {
|
|
31
|
+
"size": 5804,
|
|
32
|
+
"sha256": "d093f50bf4b90acf6721932a0c2a3eb6a27a3790a38947e80b653ea5a3e67726"
|
|
33
|
+
},
|
|
34
|
+
"cli/DataMigrator.d.ts": {
|
|
35
|
+
"size": 3355,
|
|
36
|
+
"sha256": "f7ce0a06282ab0d08a90cca9b0d2cc4ec5a8df91c9e65425aaf342ef005b5af6"
|
|
37
|
+
},
|
|
38
|
+
"cli/DataMigrator.d.ts.map": {
|
|
39
|
+
"size": 2120,
|
|
40
|
+
"sha256": "a5014c02e70e462fd5729418e1bf1b3d4823105bb37512f43b82c609cc4970a0"
|
|
41
|
+
},
|
|
42
|
+
"cli/DataMigrator.js": {
|
|
43
|
+
"size": 17563,
|
|
44
|
+
"sha256": "ea88b7ee3d2f2696a6b55d420fb90cb87cf2a27bc98efd495b286f2f31ace69b"
|
|
45
|
+
},
|
|
46
|
+
"cli/MigrateToD1Command.d.ts": {
|
|
47
|
+
"size": 1589,
|
|
48
|
+
"sha256": "c1bffb405e91cc1ff61507a51bf80baaeb89ce5a1a98ae591ecaa8e35450a8d2"
|
|
49
|
+
},
|
|
50
|
+
"cli/MigrateToD1Command.d.ts.map": {
|
|
51
|
+
"size": 1232,
|
|
52
|
+
"sha256": "3101b87c31658e34a9e25b703e40b6918b293e7310fbd57bddee3f48e9390fab"
|
|
53
|
+
},
|
|
54
|
+
"cli/MigrateToD1Command.js": {
|
|
55
|
+
"size": 25636,
|
|
56
|
+
"sha256": "8a9c816b014648a0afd0a2a7fde150a00c124b240e08fdf51023753249793f73"
|
|
57
|
+
},
|
|
58
|
+
"cli/ProgressTracker.d.ts": {
|
|
59
|
+
"size": 942,
|
|
60
|
+
"sha256": "653253439befb42b452a743588253f6156bb8af1953eadc67f27a4a7ab8cff3d"
|
|
61
|
+
},
|
|
62
|
+
"cli/ProgressTracker.d.ts.map": {
|
|
63
|
+
"size": 467,
|
|
64
|
+
"sha256": "7d38bb24d3744f54059534f4d3c935ac21e1e3ed54e2b4d68af6326e5893a3a0"
|
|
65
|
+
},
|
|
66
|
+
"cli/ProgressTracker.js": {
|
|
67
|
+
"size": 3243,
|
|
68
|
+
"sha256": "2bc54ddac7783047dc71b46cdcafabb9b3a8938f35e352328caf2fa32c6ef500"
|
|
69
|
+
},
|
|
70
|
+
"cli/SchemaAnalyzer.d.ts": {
|
|
71
|
+
"size": 4476,
|
|
72
|
+
"sha256": "effe7d9d164ce65815a31b09ab63a3e376a1fd5bdbc0fd6e7598e8895acc08de"
|
|
73
|
+
},
|
|
74
|
+
"cli/SchemaAnalyzer.d.ts.map": {
|
|
75
|
+
"size": 2707,
|
|
76
|
+
"sha256": "24236361782ae02bfdb1d12f05ae8c4ad7a0abc27aad23a0ae50e6f05477e4e1"
|
|
77
|
+
},
|
|
78
|
+
"cli/SchemaAnalyzer.js": {
|
|
79
|
+
"size": 24687,
|
|
80
|
+
"sha256": "0155f90ab2490ef4fe590f2ab054dd9579555802d761e8e2f2f426a8efad90cd"
|
|
81
|
+
},
|
|
82
|
+
"index.d.ts": {
|
|
83
|
+
"size": 1913,
|
|
84
|
+
"sha256": "1cc13fa32042969f2f426fb3c2971049df657bdbbda8275562ab72395fd2426b"
|
|
85
|
+
},
|
|
86
|
+
"index.d.ts.map": {
|
|
87
|
+
"size": 1564,
|
|
88
|
+
"sha256": "685c4e8b49c8a86f53feacb7c42e3b8268b9402ae3ae7e47cb46e7b78a9bf78b"
|
|
89
|
+
},
|
|
90
|
+
"index.js": {
|
|
91
|
+
"size": 1204,
|
|
92
|
+
"sha256": "a4c5cc454b6a6ebd61ec92822d3147b75a39c588f518bb2bb4c9c6f824d73bf9"
|
|
93
|
+
},
|
|
94
|
+
"register.d.ts": {
|
|
95
|
+
"size": 159,
|
|
96
|
+
"sha256": "e60a21d17e51095a4a8a9c4a2fae45c902305635998782b8194eb968d8083cb2"
|
|
97
|
+
},
|
|
98
|
+
"register.d.ts.map": {
|
|
99
|
+
"size": 211,
|
|
100
|
+
"sha256": "6743ba50c90440882096f5eaf09a2fff4c901ba238c604d2240ba072b5754632"
|
|
101
|
+
},
|
|
102
|
+
"register.js": {
|
|
103
|
+
"size": 857,
|
|
104
|
+
"sha256": "949f1d93c92a2b9ec1e7d388b4723f8f7012e57eaded61589d205709f0f7a5fe"
|
|
105
|
+
},
|
|
106
|
+
"schema/SchemaBuilder.d.ts": {
|
|
107
|
+
"size": 1443,
|
|
108
|
+
"sha256": "46c568eef17ab0b0b1a59cfef0bf06f85d06de6e6d5479429e6a566b43ec87a7"
|
|
109
|
+
},
|
|
110
|
+
"schema/SchemaBuilder.d.ts.map": {
|
|
111
|
+
"size": 670,
|
|
112
|
+
"sha256": "e183f412ae963da070abad7a6ecdc042f9d474ffe685139ba7cb438065afd2ec"
|
|
113
|
+
},
|
|
114
|
+
"schema/SchemaBuilder.js": {
|
|
115
|
+
"size": 5781,
|
|
116
|
+
"sha256": "1d68db37d8831881374cdb46b3ed78672cae90ab3ff2e1045e4ab32aa9bebc77"
|
|
117
|
+
},
|
|
118
|
+
"schema/TypeConverter.d.ts": {
|
|
119
|
+
"size": 989,
|
|
120
|
+
"sha256": "cca9b405c198b91062c4f44bba7acb0a36dedbca0cb3f523ba576eb5fa375efd"
|
|
121
|
+
},
|
|
122
|
+
"schema/TypeConverter.d.ts.map": {
|
|
123
|
+
"size": 431,
|
|
124
|
+
"sha256": "cef867ebdec5573d7199095d074e55d4222de7516eabaff1913ea377abca6a71"
|
|
125
|
+
},
|
|
126
|
+
"schema/TypeConverter.js": {
|
|
127
|
+
"size": 5844,
|
|
128
|
+
"sha256": "fd108420aaa34f06d970a53557f9ddf3942866122bb93053b32fd93836682776"
|
|
129
|
+
},
|
|
130
|
+
"schema/Validator.d.ts": {
|
|
131
|
+
"size": 2129,
|
|
132
|
+
"sha256": "3970191b0e8e2d1e19ae60303d2d549cc7a4cc2c7ec24b1b41878adb68354146"
|
|
133
|
+
},
|
|
134
|
+
"schema/Validator.d.ts.map": {
|
|
135
|
+
"size": 1206,
|
|
136
|
+
"sha256": "f6c526a78303423112e7916093bbeed2d7355ab5db5f74ce2c84e56ca9e82837"
|
|
137
|
+
},
|
|
138
|
+
"schema/Validator.js": {
|
|
139
|
+
"size": 8868,
|
|
140
|
+
"sha256": "e8349ddbbf3c969468d741e634a50422847052f21afa38e63493853273945e6e"
|
|
141
|
+
},
|
|
142
|
+
"types.d.ts": {
|
|
143
|
+
"size": 4098,
|
|
144
|
+
"sha256": "a03fc55513b8d5c7d0cae3f417fad9e5dcaaee511b4868cdae8cd3061af84a6c"
|
|
145
|
+
},
|
|
146
|
+
"types.d.ts.map": {
|
|
147
|
+
"size": 4181,
|
|
148
|
+
"sha256": "4dff98570f92baca6dee52a13a1942e124e3b6a386b0d19381b8e7319a623bae"
|
|
149
|
+
},
|
|
150
|
+
"types.js": {
|
|
151
|
+
"size": 85,
|
|
152
|
+
"sha256": "f3a7356e481968927c5e7e784706d8d88a0fa07a742b72216751d6ef0016eb48"
|
|
153
|
+
},
|
|
154
|
+
"utils/CheckpointManager.d.ts": {
|
|
155
|
+
"size": 1408,
|
|
156
|
+
"sha256": "4b0d63804ff4a4013114903f64b65e17f7f184cfc302bfb50d08a41dc68077bb"
|
|
157
|
+
},
|
|
158
|
+
"utils/CheckpointManager.d.ts.map": {
|
|
159
|
+
"size": 736,
|
|
160
|
+
"sha256": "d47def494117ec256c191d30e60353ec3d8340e471f802ff3e8413d7e62b5625"
|
|
161
|
+
},
|
|
162
|
+
"utils/CheckpointManager.js": {
|
|
163
|
+
"size": 7293,
|
|
164
|
+
"sha256": "630d69a08996eac1e4d6a7606db896807dda467f17875fb1514a51c2386d4896"
|
|
165
|
+
},
|
|
166
|
+
"utils/DataValidator.d.ts": {
|
|
167
|
+
"size": 1512,
|
|
168
|
+
"sha256": "b7d9127f9d12a7705c454173e6b8c7e6aea66a1143399f7eed9708e37dce2aa3"
|
|
169
|
+
},
|
|
170
|
+
"utils/DataValidator.d.ts.map": {
|
|
171
|
+
"size": 781,
|
|
172
|
+
"sha256": "bfbff6541c2232782cd82baa04492949c4420155b187ceb2dbaa6905dc06118b"
|
|
173
|
+
},
|
|
174
|
+
"utils/DataValidator.js": {
|
|
175
|
+
"size": 5337,
|
|
176
|
+
"sha256": "08be6df9d5138697e5d7e76f8adb81e44f380ed4da2fb5bee188b8b18485c9d5"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
package/dist/cli/DataMigrator.js
CHANGED
|
@@ -8,8 +8,8 @@ import { MySQLAdapter } from '@zintrust/db-mysql';
|
|
|
8
8
|
import { PostgreSQLAdapter } from '@zintrust/db-postgres';
|
|
9
9
|
import { SQLiteAdapter } from '@zintrust/db-sqlite';
|
|
10
10
|
import { SQLServerAdapter } from '@zintrust/db-sqlserver';
|
|
11
|
-
import { SchemaBuilder } from '../schema/SchemaBuilder';
|
|
12
|
-
import { SchemaAnalyzer } from './SchemaAnalyzer';
|
|
11
|
+
import { SchemaBuilder } from '../schema/SchemaBuilder.js';
|
|
12
|
+
import { SchemaAnalyzer } from './SchemaAnalyzer.js';
|
|
13
13
|
const parseConnectionDetails = (connectionString, defaultPort, defaultDatabase, defaultUsername) => {
|
|
14
14
|
try {
|
|
15
15
|
const parsed = new URL(connectionString);
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ErrorFactory, Logger } from '@zintrust/core';
|
|
6
6
|
import { BaseCommand } from '@zintrust/core/cli';
|
|
7
|
-
import { SchemaBuilder } from '../schema/SchemaBuilder';
|
|
8
|
-
import { SchemaValidator } from '../schema/Validator';
|
|
9
|
-
import { DataMigrator } from './DataMigrator';
|
|
10
|
-
import { SchemaAnalyzer } from './SchemaAnalyzer';
|
|
7
|
+
import { SchemaBuilder } from '../schema/SchemaBuilder.js';
|
|
8
|
+
import { SchemaValidator } from '../schema/Validator.js';
|
|
9
|
+
import { DataMigrator } from './DataMigrator.js';
|
|
10
|
+
import { SchemaAnalyzer } from './SchemaAnalyzer.js';
|
|
11
11
|
const SOURCE_DRIVER_MAP = Object.freeze({
|
|
12
12
|
mysql: 'mysql',
|
|
13
13
|
postgresql: 'postgresql',
|
package/dist/index.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* Migrate any database to Cloudflare D1 with resumable operations
|
|
4
4
|
*/
|
|
5
5
|
// CLI Commands
|
|
6
|
-
import { MigrateToD1Command } from './cli/MigrateToD1Command';
|
|
6
|
+
import { MigrateToD1Command } from './cli/MigrateToD1Command.js';
|
|
7
7
|
// Utilities
|
|
8
|
-
import { CheckpointManager } from './utils/CheckpointManager';
|
|
9
|
-
import { DataValidator } from './utils/DataValidator';
|
|
8
|
+
import { CheckpointManager } from './utils/CheckpointManager.js';
|
|
9
|
+
import { DataValidator } from './utils/DataValidator.js';
|
|
10
10
|
// CLI Components
|
|
11
|
-
import { DataMigrator } from './cli/DataMigrator';
|
|
12
|
-
import { ProgressTracker } from './cli/ProgressTracker';
|
|
13
|
-
import { SchemaAnalyzer } from './cli/SchemaAnalyzer';
|
|
11
|
+
import { DataMigrator } from './cli/DataMigrator.js';
|
|
12
|
+
import { ProgressTracker } from './cli/ProgressTracker.js';
|
|
13
|
+
import { SchemaAnalyzer } from './cli/SchemaAnalyzer.js';
|
|
14
14
|
// Schema Components
|
|
15
|
-
import { SchemaBuilder } from './schema/SchemaBuilder';
|
|
16
|
-
import { TypeConverter } from './schema/TypeConverter';
|
|
17
|
-
import { SchemaValidator } from './schema/Validator';
|
|
15
|
+
import { SchemaBuilder } from './schema/SchemaBuilder.js';
|
|
16
|
+
import { TypeConverter } from './schema/TypeConverter.js';
|
|
17
|
+
import { SchemaValidator } from './schema/Validator.js';
|
|
18
18
|
export const D1Migrator = Object.freeze({
|
|
19
19
|
// CLI Commands
|
|
20
20
|
MigrateToD1Command,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgD,QAAQ,EAAE,MAAM,YAAY,CAAC;AAUzF,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAElE"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const commandModule = (await (async () => {
|
|
2
|
+
try {
|
|
3
|
+
return (await import('./cli/MigrateToD1Command.js'));
|
|
4
|
+
}
|
|
5
|
+
catch {
|
|
6
|
+
return (await import('./cli/MigrateToD1Command.js'));
|
|
7
|
+
}
|
|
8
|
+
})());
|
|
9
|
+
export function registerD1MigratorCommand(registry) {
|
|
10
|
+
registry.register('migrate-to-d1', commandModule.MigrateToD1Command);
|
|
11
|
+
}
|
|
12
|
+
const globalWithRegistry = globalThis;
|
|
13
|
+
const globalRegistry = globalWithRegistry.__zintrust_cli_command_registry__ ??
|
|
14
|
+
(globalWithRegistry.__zintrust_cli_command_registry__ = new Map());
|
|
15
|
+
registerD1MigratorCommand({
|
|
16
|
+
register: (id, provider) => {
|
|
17
|
+
globalRegistry.set(id, provider);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
const core = (await import('@zintrust/core'));
|
|
22
|
+
if (core.OptionalCliCommandRegistry !== undefined) {
|
|
23
|
+
registerD1MigratorCommand(core.OptionalCliCommandRegistry);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// no-op
|
|
28
|
+
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Builds D1/SQLite compatible schemas from source schemas
|
|
4
4
|
*/
|
|
5
5
|
import { Logger } from '@zintrust/core';
|
|
6
|
-
import { DataValidator } from '../utils/DataValidator';
|
|
7
|
-
import { TypeConverter } from './TypeConverter';
|
|
6
|
+
import { DataValidator } from '../utils/DataValidator.js';
|
|
7
|
+
import { TypeConverter } from './TypeConverter.js';
|
|
8
8
|
/**
|
|
9
9
|
* SchemaBuilder - Sealed namespace for schema building
|
|
10
10
|
* Provides D1 schema generation from source schemas
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* D1 Migrator Types
|
|
3
3
|
* Type definitions for migration operations
|
|
4
4
|
*/
|
|
5
|
+
import type { Command } from 'commander';
|
|
5
6
|
export type SourceDatabaseDriver = 'mysql' | 'postgresql' | 'sqlite' | 'sqlserver';
|
|
6
7
|
export interface MigrationConfig {
|
|
7
8
|
sourceConnection: string;
|
|
@@ -142,4 +143,14 @@ export interface DataValidationResult {
|
|
|
142
143
|
extraRows?: string[];
|
|
143
144
|
errors: string[];
|
|
144
145
|
}
|
|
146
|
+
export type CliCommandProvider = {
|
|
147
|
+
getCommand: () => Command;
|
|
148
|
+
name?: string;
|
|
149
|
+
};
|
|
150
|
+
export type Registry = {
|
|
151
|
+
register: (id: string, provider: CliCommandProvider) => void;
|
|
152
|
+
};
|
|
153
|
+
export type D1MigratorRegisterModule = {
|
|
154
|
+
MigrateToD1Command: CliCommandProvider;
|
|
155
|
+
};
|
|
145
156
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEnF,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,oBAAoB,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,IAAI,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;IAClE,SAAS,EAAE,IAAI,CAAC;IAChB,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CA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,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAC9D,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/d1-migrator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"LICENSE.md"
|
|
10
11
|
],
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
14
15
|
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./register": {
|
|
18
|
+
"types": "./dist/register.d.ts",
|
|
19
|
+
"default": "./dist/register.js"
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"engines": {
|
|
18
23
|
"node": ">=20.0.0"
|
|
19
24
|
},
|
|
20
25
|
"peerDependencies": {
|
|
21
|
-
"@zintrust/core": "^0.4.
|
|
26
|
+
"@zintrust/core": "^0.4.3"
|
|
22
27
|
},
|
|
23
28
|
"publishConfig": {
|
|
24
29
|
"access": "public"
|
|
25
30
|
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "tsc -p tsconfig.json",
|
|
28
|
-
"prepublishOnly": "npm run build"
|
|
29
|
-
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"@zintrust/db-mysql": "0.4.0",
|
|
32
33
|
"@zintrust/db-postgres": "0.4.0",
|
|
@@ -34,4 +35,4 @@
|
|
|
34
35
|
"@zintrust/db-sqlserver": "0.4.0",
|
|
35
36
|
"@zintrust/db-d1": "0.4.0"
|
|
36
37
|
}
|
|
37
|
-
}
|
|
38
|
+
}
|
package/README.md
DELETED
|
@@ -1,871 +0,0 @@
|
|
|
1
|
-
# @zintrust/d1-migrator
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@zintrust/d1-migrator)
|
|
4
|
-
[](https://nodejs.org/)
|
|
5
|
-
[](https://www.typescriptlang.org/)
|
|
6
|
-
[](LICENSE.md)
|
|
7
|
-
|
|
8
|
-
> **Reliable, resumable database migrations to Cloudflare D1 with full data integrity verification.**
|
|
9
|
-
|
|
10
|
-
Migrate any database (MySQL, PostgreSQL, SQLite, SQL Server) to Cloudflare D1 with resumable operations, checkpoint recovery, and comprehensive data validation. Built for production use with careful attention to data integrity and operational safety.
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
- **Multi-source Support**: Migrate from MySQL, PostgreSQL, SQLite, or SQL Server
|
|
15
|
-
- **Resumable Operations**: Automatic checkpointing allows recovery from failures without data loss
|
|
16
|
-
- **Data Integrity**: Row-count verification, checksums, and validation at every step
|
|
17
|
-
- **D1 Compatibility**: Automatic schema conversion and value transformation for SQLite compatibility
|
|
18
|
-
- **Dry-Run Mode**: Test migrations safely before executing
|
|
19
|
-
- **Interactive Mode**: Get guidance for complex migrations with compatibility issues
|
|
20
|
-
- **Batch Processing**: Configurable batch sizes for memory efficiency
|
|
21
|
-
- **Progress Tracking**: Real-time migration progress with detailed metrics
|
|
22
|
-
- **Error Resilience**: Comprehensive error handling with detailed reporting
|
|
23
|
-
- **Zero Downtime**: Works with live databases without requiring offline periods
|
|
24
|
-
- **TypeScript First**: Full type safety and IDE support out of the box
|
|
25
|
-
|
|
26
|
-
## Requirements
|
|
27
|
-
|
|
28
|
-
- **Node.js**: >= 20.0.0 (ESM support required)
|
|
29
|
-
- **TypeScript**: >= 5.0.0
|
|
30
|
-
- **@zintrust/core**: Latest version
|
|
31
|
-
- **Wrangler**: >= 2.0.0 (for D1 management)
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
Install the package with your preferred package manager:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm install @zintrust/d1-migrator
|
|
39
|
-
# or
|
|
40
|
-
yarn add @zintrust/d1-migrator
|
|
41
|
-
# or
|
|
42
|
-
pnpm add @zintrust/d1-migrator
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
The package requires source database adapters depending on which database you're migrating from. These are automatically included as dependencies:
|
|
46
|
-
|
|
47
|
-
- MySQL → `@zintrust/db-mysql`
|
|
48
|
-
- PostgreSQL → `@zintrust/db-postgres`
|
|
49
|
-
- SQLite → `@zintrust/db-sqlite`
|
|
50
|
-
- SQL Server → `@zintrust/db-sqlserver`
|
|
51
|
-
- Target → `@zintrust/db-d1`
|
|
52
|
-
|
|
53
|
-
## Quick Start
|
|
54
|
-
|
|
55
|
-
### Via CLI (Recommended)
|
|
56
|
-
|
|
57
|
-
#### Zero-arg command (env-driven)
|
|
58
|
-
|
|
59
|
-
Set env vars once, then run the command without flags:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
export DB_CONNECTION=mysql
|
|
63
|
-
export DB_READ_HOSTS=127.0.0.1
|
|
64
|
-
export DB_PORT=3306
|
|
65
|
-
export DB_DATABASE=zintrust
|
|
66
|
-
export DB_USERNAME=root
|
|
67
|
-
export DB_PASSWORD=secret
|
|
68
|
-
# Optional (defaults to "d1" when omitted)
|
|
69
|
-
export D1_TARGET_DB=zintrust-live-test
|
|
70
|
-
|
|
71
|
-
zin migrate-to-d1
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
The command resolves values in this order: **CLI flag → environment variable → built-in default**.
|
|
75
|
-
|
|
76
|
-
#### Explicit flags
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
# Analyze and migrate a MySQL database to D1
|
|
80
|
-
zin migrate-to-d1 \
|
|
81
|
-
--from mysql \
|
|
82
|
-
--source-connection "mysql://user:password@localhost:3306/mydb" \
|
|
83
|
-
--to d1 \
|
|
84
|
-
--target-database my-d1-db
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Via TypeScript
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
91
|
-
|
|
92
|
-
const config = {
|
|
93
|
-
sourceConnection: 'mysql://user:password@localhost:3306/mydb',
|
|
94
|
-
sourceDriver: 'mysql',
|
|
95
|
-
targetDatabase: 'my-d1-db',
|
|
96
|
-
targetType: 'd1',
|
|
97
|
-
batchSize: 1000,
|
|
98
|
-
checkpointInterval: 10000,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const progress = await D1Migrator.DataMigrator.migrateData(config);
|
|
102
|
-
console.log(`Migration complete: ${progress.processedRows} rows migrated`);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
## Usage Guide
|
|
106
|
-
|
|
107
|
-
### CLI Commands
|
|
108
|
-
|
|
109
|
-
#### Basic Migration
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
zin migrate-to-d1 \
|
|
113
|
-
--from mysql \
|
|
114
|
-
--source-connection "mysql://user:password@localhost:3306/sourcedb" \
|
|
115
|
-
--to d1 \
|
|
116
|
-
--target-database target-d1-db
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
#### With Custom Batch Size
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
zin migrate-to-d1 \
|
|
123
|
-
--from postgresql \
|
|
124
|
-
--source-connection "postgresql://user:password@localhost:5432/sourcedb" \
|
|
125
|
-
--to d1-remote \
|
|
126
|
-
--target-database my-d1-remote \
|
|
127
|
-
--batch-size 5000 \
|
|
128
|
-
--checkpoint-interval 25000
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
#### Dry Run (Test Mode)
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
zin migrate-to-d1 \
|
|
135
|
-
--from mysql \
|
|
136
|
-
--source-connection "mysql://user:password@localhost:3306/sourcedb" \
|
|
137
|
-
--to d1 \
|
|
138
|
-
--target-database test-d1-db \
|
|
139
|
-
--dry-run
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
#### Schema-Only Analysis
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
zin migrate-to-d1 \
|
|
146
|
-
--from sqlserver \
|
|
147
|
-
--source-connection "mssql://user:password@localhost:1433/sourcedb" \
|
|
148
|
-
--to d1 \
|
|
149
|
-
--target-database target-d1-db \
|
|
150
|
-
--schema-only
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
#### Interactive Mode
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
zin migrate-to-d1 \
|
|
157
|
-
--from mysql \
|
|
158
|
-
--source-connection "mysql://user:password@localhost:3306/sourcedb" \
|
|
159
|
-
--to d1 \
|
|
160
|
-
--target-database target-d1-db \
|
|
161
|
-
--interactive
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
#### Resume Failed Migration
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
zin migrate-to-d1 \
|
|
168
|
-
--resume \
|
|
169
|
-
--migration-id abc123def456
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### CLI Options
|
|
173
|
-
|
|
174
|
-
| Option | Short | Type | Required | Default | Description |
|
|
175
|
-
| ----------------------- | ----- | ------- | -------- | ------- | ------------------------------------------------------------------ |
|
|
176
|
-
| `--from` | `-f` | string | ✗ | — | Source database type: `mysql`, `postgresql`, `sqlite`, `sqlserver` |
|
|
177
|
-
| `--to` | `-t` | string | ✗ | `d1` | Target: `d1` (local) or `d1-remote` |
|
|
178
|
-
| `--source-connection` | `-s` | string | ✗ | — | Source connection URI (falls back to env or DB\_\* composition) |
|
|
179
|
-
| `--target-database` | `-d` | string | ✗ | `d1` | Target D1 database identifier (or env fallback) |
|
|
180
|
-
| `--batch-size` | `-b` | number | ✗ | `1000` | Records per batch during data copy |
|
|
181
|
-
| `--checkpoint-interval` | `-c` | number | ✗ | `10000` | Save checkpoint every N rows |
|
|
182
|
-
| `--dry-run` | — | boolean | ✗ | `false` | Test migration without making changes |
|
|
183
|
-
| `--schema-only` | — | boolean | ✗ | `false` | Analyze and convert schema only |
|
|
184
|
-
| `--interactive` | `-i` | boolean | ✗ | `false` | Interactive mode for complex migrations |
|
|
185
|
-
| `--resume` | `-r` | boolean | ✗ | `false` | Resume a previously paused/failed migration |
|
|
186
|
-
| `--migration-id` | — | string | ✗ | — | Migration ID to resume (required with `--resume`) |
|
|
187
|
-
|
|
188
|
-
### Environment Variable Fallbacks
|
|
189
|
-
|
|
190
|
-
The command supports env-based execution for all CLI settings.
|
|
191
|
-
|
|
192
|
-
| Setting | Env variables (priority order) |
|
|
193
|
-
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
194
|
-
| Source driver (`--from`) | `MIGRATE_TO_D1_FROM`, `MIGRATE_TO_D1_SOURCE_DRIVER`, `D1_MIGRATOR_SOURCE_DRIVER`, `DB_CONNECTION` |
|
|
195
|
-
| Source URI (`--source-connection`) | `MIGRATE_TO_D1_SOURCE_CONNECTION`, `D1_MIGRATOR_SOURCE_CONNECTION`, `SOURCE_DATABASE_URL`, `DATABASE_URL`, `DB_URL` |
|
|
196
|
-
| Target type (`--to`) | `MIGRATE_TO_D1_TO`, `MIGRATE_TO_D1_TARGET_TYPE`, `D1_MIGRATOR_TARGET_TYPE`, `D1_TARGET_TYPE` |
|
|
197
|
-
| Target DB (`--target-database`) | `MIGRATE_TO_D1_TARGET_DATABASE`, `D1_MIGRATOR_TARGET_DATABASE`, `D1_TARGET_DB`, `D1_DATABASE`, `D1_DATABASE_ID`, `DB_DATABASE` |
|
|
198
|
-
| Batch size (`--batch-size`) | `MIGRATE_TO_D1_BATCH_SIZE`, `D1_MIGRATOR_BATCH_SIZE` |
|
|
199
|
-
| Checkpoint interval (`--checkpoint-interval`) | `MIGRATE_TO_D1_CHECKPOINT_INTERVAL`, `D1_MIGRATOR_CHECKPOINT_INTERVAL` |
|
|
200
|
-
| Dry run (`--dry-run`) | `MIGRATE_TO_D1_DRY_RUN`, `D1_MIGRATOR_DRY_RUN` |
|
|
201
|
-
| Schema only (`--schema-only`) | `MIGRATE_TO_D1_SCHEMA_ONLY`, `D1_MIGRATOR_SCHEMA_ONLY` |
|
|
202
|
-
| Interactive (`--interactive`) | `MIGRATE_TO_D1_INTERACTIVE`, `D1_MIGRATOR_INTERACTIVE` |
|
|
203
|
-
| Resume (`--resume`) | `MIGRATE_TO_D1_RESUME`, `D1_MIGRATOR_RESUME` |
|
|
204
|
-
| Migration ID (`--migration-id`) | `MIGRATE_TO_D1_MIGRATION_ID`, `D1_MIGRATOR_MIGRATION_ID` |
|
|
205
|
-
|
|
206
|
-
If `--source-connection` is not provided, the command automatically composes a URI from `DB_*` values for MySQL/PostgreSQL/SQL Server, and uses `DB_PATH`/`DB_DATABASE` for SQLite. Host fallback prefers `DB_READ_HOSTS`, then `DB_HOSTS`, then `DB_HOST`.
|
|
207
|
-
|
|
208
|
-
### Programmatic Usage
|
|
209
|
-
|
|
210
|
-
#### Basic Migration
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
214
|
-
|
|
215
|
-
const config = {
|
|
216
|
-
sourceConnection: 'mysql://user:password@localhost:3306/mydb',
|
|
217
|
-
sourceDriver: 'mysql' as const,
|
|
218
|
-
targetDatabase: 'my-d1-db',
|
|
219
|
-
targetType: 'd1' as const,
|
|
220
|
-
batchSize: 1000,
|
|
221
|
-
checkpointInterval: 10000,
|
|
222
|
-
migrationId: 'migration-' + Date.now(),
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
const progress = await D1Migrator.DataMigrator.migrateData(config);
|
|
227
|
-
|
|
228
|
-
console.log('Migration Results:');
|
|
229
|
-
console.log(`- Status: ${progress.status}`);
|
|
230
|
-
console.log(`- Tables: ${progress.totalTables}`);
|
|
231
|
-
console.log(`- Rows: ${progress.processedRows}/${progress.totalRows}`);
|
|
232
|
-
console.log(`- Errors: ${Object.keys(progress.errors).length}`);
|
|
233
|
-
|
|
234
|
-
if (progress.status === 'failed') {
|
|
235
|
-
console.error('Migration errors:', progress.errors);
|
|
236
|
-
}
|
|
237
|
-
} catch (error) {
|
|
238
|
-
console.error('Migration failed:', error);
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
#### Schema Analysis Only
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
246
|
-
|
|
247
|
-
const connection = {
|
|
248
|
-
driver: 'mysql' as const,
|
|
249
|
-
connectionString: 'mysql://user:password@localhost:3306/mydb',
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const schema = await D1Migrator.SchemaAnalyzer.analyzeSchema(connection);
|
|
253
|
-
|
|
254
|
-
console.log(`Found ${schema.tables.length} tables`);
|
|
255
|
-
schema.tables.forEach((table) => {
|
|
256
|
-
console.log(`- ${table.name}: ${table.columns.length} columns, ${table.rowCount} rows`);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// Check D1 compatibility
|
|
260
|
-
const compatibility = D1Migrator.SchemaAnalyzer.checkD1Compatibility(schema);
|
|
261
|
-
if (!compatibility.compatible) {
|
|
262
|
-
console.warn('Compatibility issues:', compatibility.issues);
|
|
263
|
-
}
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
#### Schema Conversion
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
270
|
-
|
|
271
|
-
const sourceSchema = await D1Migrator.SchemaAnalyzer.analyzeSchema(connection);
|
|
272
|
-
const d1Schema = D1Migrator.SchemaBuilder.buildD1Schema(sourceSchema.tables, 'mysql');
|
|
273
|
-
|
|
274
|
-
// d1Schema contains D1-compatible CREATE TABLE statements
|
|
275
|
-
console.log(d1Schema);
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
#### Data Validation
|
|
279
|
-
|
|
280
|
-
```typescript
|
|
281
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
282
|
-
|
|
283
|
-
const results = await D1Migrator.DataValidator.validateMigration(
|
|
284
|
-
config,
|
|
285
|
-
sourceSchema,
|
|
286
|
-
targetDatabase
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
results.forEach((result) => {
|
|
290
|
-
console.log(`Table: ${result.table}`);
|
|
291
|
-
console.log(`- Source rows: ${result.sourceCount}`);
|
|
292
|
-
console.log(`- Target rows: ${result.targetCount}`);
|
|
293
|
-
console.log(`- Match: ${result.checksumMatch ? '✓' : '✗'}`);
|
|
294
|
-
|
|
295
|
-
if (!result.checksumMatch) {
|
|
296
|
-
console.warn('- Missing rows:', result.missingRows?.length);
|
|
297
|
-
console.warn('- Extra rows:', result.extraRows?.length);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
## Connection Strings
|
|
303
|
-
|
|
304
|
-
### MySQL
|
|
305
|
-
|
|
306
|
-
```
|
|
307
|
-
mysql://[username]:[password]@[host]:[port]/[database]
|
|
308
|
-
|
|
309
|
-
Examples:
|
|
310
|
-
mysql://root:password@localhost:3306/mydb
|
|
311
|
-
mysql://user:pass@db.example.com:3306/production
|
|
312
|
-
mysql://root@127.0.0.1/app_db
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
### PostgreSQL
|
|
316
|
-
|
|
317
|
-
```
|
|
318
|
-
postgresql://[username]:[password]@[host]:[port]/[database]
|
|
319
|
-
|
|
320
|
-
Examples:
|
|
321
|
-
postgresql://user:password@localhost:5432/mydb
|
|
322
|
-
postgresql://postgres:secret@db.example.com:5432/prod
|
|
323
|
-
postgresql://user@127.0.0.1/app_db
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
### SQLite
|
|
327
|
-
|
|
328
|
-
```
|
|
329
|
-
sqlite://[path/to/database.db]
|
|
330
|
-
or
|
|
331
|
-
/path/to/database.db
|
|
332
|
-
|
|
333
|
-
Examples:
|
|
334
|
-
sqlite:///data/app.db
|
|
335
|
-
/Users/user/projects/db.sqlite
|
|
336
|
-
./data/local.db
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
### SQL Server
|
|
340
|
-
|
|
341
|
-
```
|
|
342
|
-
mssql://[username]:[password]@[host]:[port]/[database]
|
|
343
|
-
|
|
344
|
-
Examples:
|
|
345
|
-
mssql://sa:Password123@localhost:1433/mydb
|
|
346
|
-
mssql://user:pass@db.example.com:1433/production
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
## Configuration Reference
|
|
350
|
-
|
|
351
|
-
### MigrationConfig
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
interface MigrationConfig {
|
|
355
|
-
// Source database connection
|
|
356
|
-
sourceConnection: string; // Connection URI
|
|
357
|
-
sourceDriver: SourceDatabaseDriver; // mysql | postgresql | sqlite | sqlserver
|
|
358
|
-
|
|
359
|
-
// Target D1 database
|
|
360
|
-
targetDatabase: string; // D1 database identifier
|
|
361
|
-
targetType: 'd1' | 'd1-remote'; // Local or remote D1
|
|
362
|
-
|
|
363
|
-
// Migration behavior (optional)
|
|
364
|
-
batchSize?: number; // Records per batch (default: 1000)
|
|
365
|
-
checkpointInterval?: number; // Save checkpoint every N rows (default: 10000)
|
|
366
|
-
dryRun?: boolean; // Test without changes (default: false)
|
|
367
|
-
interactive?: boolean; // Interactive mode (default: false)
|
|
368
|
-
migrationId?: string; // Migration identifier for resume
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
### MigrationProgress
|
|
373
|
-
|
|
374
|
-
```typescript
|
|
375
|
-
interface MigrationProgress {
|
|
376
|
-
migrationId: string;
|
|
377
|
-
currentTable: string;
|
|
378
|
-
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
379
|
-
processedRows: number;
|
|
380
|
-
totalRows: number;
|
|
381
|
-
totalTables: number;
|
|
382
|
-
percentage: number;
|
|
383
|
-
errors: Record<string, string>; // table -> error message
|
|
384
|
-
startTime?: Date;
|
|
385
|
-
endTime?: Date;
|
|
386
|
-
}
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
## Advanced Features
|
|
390
|
-
|
|
391
|
-
### Checkpoint Recovery
|
|
392
|
-
|
|
393
|
-
Migrations are automatically checkpointed every N rows (default 10,000). If a migration fails, you can resume from the last checkpoint:
|
|
394
|
-
|
|
395
|
-
```bash
|
|
396
|
-
# View checkpoint information
|
|
397
|
-
ls -la .wrangler/state/v3/migrations/
|
|
398
|
-
|
|
399
|
-
# Resume migration from checkpoint
|
|
400
|
-
zin migrate-to-d1 --resume --migration-id abc123def456
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
### Custom Batch Sizing
|
|
404
|
-
|
|
405
|
-
Batch size affects both performance and memory usage:
|
|
406
|
-
|
|
407
|
-
```typescript
|
|
408
|
-
// Small batches: slower but more memory-efficient
|
|
409
|
-
// Good for resource-constrained environments
|
|
410
|
-
batchSize: 500,
|
|
411
|
-
checkpointInterval: 2500,
|
|
412
|
-
|
|
413
|
-
// Large batches: faster but uses more memory
|
|
414
|
-
// Good for high-performance environments
|
|
415
|
-
batchSize: 5000,
|
|
416
|
-
checkpointInterval: 25000,
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### Dry-Run Mode
|
|
420
|
-
|
|
421
|
-
Always test migrations in dry-run mode first to catch issues:
|
|
422
|
-
|
|
423
|
-
```bash
|
|
424
|
-
zin migrate-to-d1 \
|
|
425
|
-
--from mysql \
|
|
426
|
-
--source-connection "mysql://user:password@localhost:3306/mydb" \
|
|
427
|
-
--to d1 \
|
|
428
|
-
--target-database test-db \
|
|
429
|
-
--dry-run
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
### Interactive Mode
|
|
433
|
-
|
|
434
|
-
For complex migrations with compatibility warnings, use interactive mode:
|
|
435
|
-
|
|
436
|
-
```bash
|
|
437
|
-
zin migrate-to-d1 \
|
|
438
|
-
--from sqlserver \
|
|
439
|
-
--source-connection "mssql://user:password@localhost:1433/mydb" \
|
|
440
|
-
--to d1 \
|
|
441
|
-
--target-database target-db \
|
|
442
|
-
--interactive
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
The interactive mode will:
|
|
446
|
-
|
|
447
|
-
- Show all compatibility warnings
|
|
448
|
-
- Ask for confirmation before proceeding
|
|
449
|
-
- Suggest workarounds for unsupported features
|
|
450
|
-
- Allow manual schema adjustments
|
|
451
|
-
|
|
452
|
-
## Type Conversions
|
|
453
|
-
|
|
454
|
-
### Automatic Data Transformations
|
|
455
|
-
|
|
456
|
-
The migrator automatically converts data types for D1 compatibility:
|
|
457
|
-
|
|
458
|
-
| Source Type | SQLite Type | Notes |
|
|
459
|
-
| ------------------- | --------------- | -------------------------------- |
|
|
460
|
-
| DATETIME, TIMESTAMP | TEXT (ISO 8601) | Converted to ISO 8601 strings |
|
|
461
|
-
| BIGINT | TEXT | Large integers stored as strings |
|
|
462
|
-
| DECIMAL, NUMERIC | TEXT | Precision preserved as strings |
|
|
463
|
-
| JSON | TEXT | JSON objects stored as strings |
|
|
464
|
-
| BLOB | BLOB | Binary data preserved |
|
|
465
|
-
| NULL | NULL | Null values preserved |
|
|
466
|
-
|
|
467
|
-
### Manual Value Transformation
|
|
468
|
-
|
|
469
|
-
For custom value transformations:
|
|
470
|
-
|
|
471
|
-
```typescript
|
|
472
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
473
|
-
|
|
474
|
-
const transformed = D1Migrator.TypeConverter.transformValue(value, sourceType, 'sqlite');
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
## Error Handling
|
|
478
|
-
|
|
479
|
-
### Common Errors and Solutions
|
|
480
|
-
|
|
481
|
-
#### Connection Failed
|
|
482
|
-
|
|
483
|
-
```
|
|
484
|
-
Error: Unable to connect to source database
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
**Solution**: Check connection string format and network connectivity.
|
|
488
|
-
|
|
489
|
-
```bash
|
|
490
|
-
# Verify connection
|
|
491
|
-
mysql -h localhost -u user -p -D database -e "SELECT 1;"
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
#### Schema Incompatibility
|
|
495
|
-
|
|
496
|
-
```
|
|
497
|
-
Error: Schema compatibility issues prevent migration
|
|
498
|
-
- Unsupported column type: GEOMETRY
|
|
499
|
-
- Unsupported feature: PARTITION BY
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
**Solution**: Use interactive mode to review and accept changes:
|
|
503
|
-
|
|
504
|
-
```bash
|
|
505
|
-
zin migrate-to-d1 --from mysql --to d1 --interactive
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
#### Row Count Mismatch
|
|
509
|
-
|
|
510
|
-
```
|
|
511
|
-
Error: Data migration verification failed
|
|
512
|
-
Expected rows: 1000, Inserted rows: 998
|
|
513
|
-
```
|
|
514
|
-
|
|
515
|
-
**Solution**: Review specific table logs:
|
|
516
|
-
|
|
517
|
-
1. Check for NULL values in unique/primary key columns
|
|
518
|
-
2. Verify foreign key constraints on source
|
|
519
|
-
3. Run validation to identify missing rows:
|
|
520
|
-
|
|
521
|
-
```typescript
|
|
522
|
-
const validation = await D1Migrator.DataValidator.validateMigration(config);
|
|
523
|
-
validation.forEach((result) => {
|
|
524
|
-
if (!result.checksumMatch) {
|
|
525
|
-
console.log(`Missing rows in ${result.table}:`, result.missingRows);
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
#### Out of Memory
|
|
531
|
-
|
|
532
|
-
```
|
|
533
|
-
Error: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
**Solution**: Reduce batch size:
|
|
537
|
-
|
|
538
|
-
```bash
|
|
539
|
-
zin migrate-to-d1 \
|
|
540
|
-
--source-connection "..." \
|
|
541
|
-
--batch-size 500 \
|
|
542
|
-
--checkpoint-interval 2500
|
|
543
|
-
```
|
|
544
|
-
|
|
545
|
-
## Performance Tuning
|
|
546
|
-
|
|
547
|
-
### Optimization Guidelines
|
|
548
|
-
|
|
549
|
-
1. **Batch Size**: Balance between memory and speed
|
|
550
|
-
- Test with 1000-2000 records first
|
|
551
|
-
- Increase if memory available and no OOM errors
|
|
552
|
-
- Decrease if experiencing memory pressure
|
|
553
|
-
|
|
554
|
-
2. **Checkpoint Interval**: Balance between durability and speed
|
|
555
|
-
- Set to 5-10x batch size
|
|
556
|
-
- More checkpoints = slower but safer
|
|
557
|
-
- Fewer checkpoints = faster but riskier
|
|
558
|
-
|
|
559
|
-
3. **Connection Pooling**: Configure at adapter level
|
|
560
|
-
- MySQL: Best with 5-10 connections
|
|
561
|
-
- PostgreSQL: Best with 2-5 connections
|
|
562
|
-
- SQLite: Single connection optimal
|
|
563
|
-
|
|
564
|
-
4. **Network**: For remote sources
|
|
565
|
-
- Ensure low latency connection
|
|
566
|
-
- Consider regional endpoints if available
|
|
567
|
-
- Use compression if supported
|
|
568
|
-
|
|
569
|
-
### Benchmarks (Typical Performance)
|
|
570
|
-
|
|
571
|
-
| Source | Size | Time | Type |
|
|
572
|
-
| --------------- | --------- | ------- | ---------- |
|
|
573
|
-
| MySQL 5.7 | 100k rows | ~5 min | 1000 batch |
|
|
574
|
-
| PostgreSQL 13 | 500k rows | ~25 min | 2000 batch |
|
|
575
|
-
| SQL Server 2019 | 1M rows | ~50 min | 2000 batch |
|
|
576
|
-
| SQLite 3 | 100k rows | ~2 min | 1000 batch |
|
|
577
|
-
|
|
578
|
-
## Examples
|
|
579
|
-
|
|
580
|
-
### Complete Migration Workflow
|
|
581
|
-
|
|
582
|
-
```typescript
|
|
583
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
584
|
-
import { Logger } from '@zintrust/core';
|
|
585
|
-
|
|
586
|
-
async function migrateDatabase() {
|
|
587
|
-
try {
|
|
588
|
-
// Step 1: Analyze source schema
|
|
589
|
-
Logger.info('Analyzing source database...');
|
|
590
|
-
const connection = {
|
|
591
|
-
driver: 'mysql' as const,
|
|
592
|
-
connectionString: process.env.DB_SOURCE_URL!,
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
const schema = await D1Migrator.SchemaAnalyzer.analyzeSchema(connection);
|
|
596
|
-
Logger.info(`Found ${schema.tables.length} tables`);
|
|
597
|
-
|
|
598
|
-
// Step 2: Check D1 compatibility
|
|
599
|
-
const compatibility = D1Migrator.SchemaAnalyzer.checkD1Compatibility(schema);
|
|
600
|
-
if (!compatibility.compatible) {
|
|
601
|
-
throw new Error(`Compatibility issues: ${compatibility.issues.join(', ')}`);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// Step 3: Build D1 schema
|
|
605
|
-
const d1Schema = D1Migrator.SchemaBuilder.buildD1Schema(schema.tables, 'mysql');
|
|
606
|
-
Logger.info('D1 schema built successfully');
|
|
607
|
-
|
|
608
|
-
// Step 4: Migrate data
|
|
609
|
-
Logger.info('Starting data migration...');
|
|
610
|
-
const config = {
|
|
611
|
-
sourceConnection: process.env.DB_SOURCE_URL!,
|
|
612
|
-
sourceDriver: 'mysql' as const,
|
|
613
|
-
targetDatabase: process.env.D1_DATABASE!,
|
|
614
|
-
targetType: 'd1' as const,
|
|
615
|
-
batchSize: 1000,
|
|
616
|
-
checkpointInterval: 10000,
|
|
617
|
-
migrationId: 'migration-' + Date.now(),
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
const progress = await D1Migrator.DataMigrator.migrateData(config);
|
|
621
|
-
|
|
622
|
-
if (progress.status === 'failed') {
|
|
623
|
-
Logger.error('Migration failed:', progress.errors);
|
|
624
|
-
throw new Error('Migration failed with errors');
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// Step 5: Validate migration
|
|
628
|
-
Logger.info('Validating migrated data...');
|
|
629
|
-
const validation = await D1Migrator.DataValidator.validateMigration(
|
|
630
|
-
config,
|
|
631
|
-
schema,
|
|
632
|
-
process.env.D1_DATABASE!
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
const allValid = validation.every((r) => r.checksumMatch);
|
|
636
|
-
if (!allValid) {
|
|
637
|
-
Logger.warn('Validation warnings found');
|
|
638
|
-
validation.forEach((r) => {
|
|
639
|
-
if (!r.checksumMatch) {
|
|
640
|
-
Logger.warn(`${r.table}: source=${r.sourceCount}, target=${r.targetCount}`);
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
Logger.info('Migration completed successfully!');
|
|
646
|
-
Logger.info(`Total rows: ${progress.processedRows}`);
|
|
647
|
-
Logger.info(
|
|
648
|
-
`Duration: ${(progress.endTime!.getTime() - progress.startTime!.getTime()) / 1000}s`
|
|
649
|
-
);
|
|
650
|
-
} catch (error) {
|
|
651
|
-
Logger.error('Migration failed:', error);
|
|
652
|
-
throw error;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
// Execute
|
|
657
|
-
migrateDatabase().catch(console.error);
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
### Monitor Migration Progress
|
|
661
|
-
|
|
662
|
-
```typescript
|
|
663
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
664
|
-
|
|
665
|
-
async function monitorMigration(config: MigrationConfig) {
|
|
666
|
-
const trackProgress = setInterval(async () => {
|
|
667
|
-
try {
|
|
668
|
-
const state = await D1Migrator.CheckpointManager.getCheckpointState(config.migrationId);
|
|
669
|
-
|
|
670
|
-
if (state) {
|
|
671
|
-
const percentage = (state.processedRows / state.totalRows) * 100;
|
|
672
|
-
console.log(
|
|
673
|
-
`Progress: ${percentage.toFixed(1)}% (${state.processedRows}/${state.totalRows})`
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
} catch (error) {
|
|
677
|
-
console.error('Failed to get progress:', error);
|
|
678
|
-
}
|
|
679
|
-
}, 5000); // Update every 5 seconds
|
|
680
|
-
|
|
681
|
-
const progress = await D1Migrator.DataMigrator.migrateData(config);
|
|
682
|
-
|
|
683
|
-
clearInterval(trackProgress);
|
|
684
|
-
return progress;
|
|
685
|
-
}
|
|
686
|
-
```
|
|
687
|
-
|
|
688
|
-
## Troubleshooting
|
|
689
|
-
|
|
690
|
-
### Debug Logging
|
|
691
|
-
|
|
692
|
-
Enable verbose logging to diagnose issues:
|
|
693
|
-
|
|
694
|
-
```bash
|
|
695
|
-
LOG_LEVEL=debug zin migrate-to-d1 \
|
|
696
|
-
--from mysql \
|
|
697
|
-
--source-connection "mysql://user:password@localhost:3306/mydb" \
|
|
698
|
-
--to d1 \
|
|
699
|
-
--target-database target-db
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
### Test Connection
|
|
703
|
-
|
|
704
|
-
Verify source database connectivity:
|
|
705
|
-
|
|
706
|
-
```bash
|
|
707
|
-
# MySQL
|
|
708
|
-
mysql -h localhost -u user -p -D database -e "SELECT 1;"
|
|
709
|
-
|
|
710
|
-
# PostgreSQL
|
|
711
|
-
psql -h localhost -U user -d database -c "SELECT 1;"
|
|
712
|
-
|
|
713
|
-
# SQL Server
|
|
714
|
-
sqlcmd -S localhost -U sa -P password -Q "SELECT 1;"
|
|
715
|
-
|
|
716
|
-
# SQLite
|
|
717
|
-
sqlite3 /path/to/database.db "SELECT 1;"
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
### Inspect D1 Database
|
|
721
|
-
|
|
722
|
-
```bash
|
|
723
|
-
# List D1 databases
|
|
724
|
-
wrangler d1 list
|
|
725
|
-
|
|
726
|
-
# Query D1 database
|
|
727
|
-
wrangler d1 execute my-d1-db --remote --command "SELECT COUNT(*) FROM table_name;"
|
|
728
|
-
|
|
729
|
-
# Backup D1
|
|
730
|
-
wrangler d1 backup create my-d1-db --remote
|
|
731
|
-
```
|
|
732
|
-
|
|
733
|
-
### Review Checkpoint Data
|
|
734
|
-
|
|
735
|
-
```bash
|
|
736
|
-
# Find checkpoint files
|
|
737
|
-
find .wrangler/state/v3/migrations -name "*.json" -type f
|
|
738
|
-
|
|
739
|
-
# View checkpoint content
|
|
740
|
-
cat .wrangler/state/v3/migrations/migration-123456.json
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
## Architecture
|
|
744
|
-
|
|
745
|
-
### Module Structure
|
|
746
|
-
|
|
747
|
-
```
|
|
748
|
-
packages/d1-migrator/
|
|
749
|
-
├── src/
|
|
750
|
-
│ ├── index.ts # Entry point, sealed namespace export
|
|
751
|
-
│ ├── types.ts # Type definitions
|
|
752
|
-
│ ├── cli/ # CLI components
|
|
753
|
-
│ │ ├── MigrateToD1Command.ts # CLI command definition
|
|
754
|
-
│ │ ├── DataMigrator.ts # Core migration orchestrator
|
|
755
|
-
│ │ ├── SchemaAnalyzer.ts # Source schema introspection
|
|
756
|
-
│ │ └── ProgressTracker.ts # Migration progress tracking
|
|
757
|
-
│ ├── schema/ # Schema conversion
|
|
758
|
-
│ │ ├── SchemaBuilder.ts # Builds D1-compatible schemas
|
|
759
|
-
│ │ ├── TypeConverter.ts # Type transformations
|
|
760
|
-
│ │ └── Validator.ts # Schema validation
|
|
761
|
-
│ └── utils/ # Utilities
|
|
762
|
-
│ ├── CheckpointManager.ts # Resumable migration checkpoints
|
|
763
|
-
│ └── DataValidator.ts # Data integrity validation
|
|
764
|
-
└── package.json
|
|
765
|
-
```
|
|
766
|
-
|
|
767
|
-
### Data Flow
|
|
768
|
-
|
|
769
|
-
```
|
|
770
|
-
Source Database
|
|
771
|
-
↓
|
|
772
|
-
[SchemaAnalyzer] ← Introspect tables, columns, keys, indexes
|
|
773
|
-
↓
|
|
774
|
-
Database Schema Object
|
|
775
|
-
↓
|
|
776
|
-
[Compatibility Check] ← Verify D1 support
|
|
777
|
-
↓
|
|
778
|
-
[SchemaBuilder] ← Convert to D1-compatible schema
|
|
779
|
-
↓
|
|
780
|
-
[DataMigrator] ← Migrate data in batches
|
|
781
|
-
├─ [TypeConverter] ← Transform values
|
|
782
|
-
├─ [CheckpointManager] ← Save progress
|
|
783
|
-
└─ [DataValidator] ← Verify rows
|
|
784
|
-
↓
|
|
785
|
-
D1 Database
|
|
786
|
-
```
|
|
787
|
-
|
|
788
|
-
## Development
|
|
789
|
-
|
|
790
|
-
### Building from Source
|
|
791
|
-
|
|
792
|
-
```bash
|
|
793
|
-
# Install dependencies
|
|
794
|
-
npm install
|
|
795
|
-
|
|
796
|
-
# Build TypeScript
|
|
797
|
-
npm run build
|
|
798
|
-
|
|
799
|
-
# Run tests
|
|
800
|
-
npm test
|
|
801
|
-
|
|
802
|
-
# Type checking
|
|
803
|
-
npm run type-check
|
|
804
|
-
|
|
805
|
-
# Linting
|
|
806
|
-
npm run lint
|
|
807
|
-
```
|
|
808
|
-
|
|
809
|
-
### Testing Locally
|
|
810
|
-
|
|
811
|
-
```typescript
|
|
812
|
-
// tests/integration/migration.test.ts
|
|
813
|
-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
814
|
-
import { D1Migrator } from '@zintrust/d1-migrator';
|
|
815
|
-
|
|
816
|
-
describe('D1 Migration', () => {
|
|
817
|
-
it('should migrate MySQL data successfully', async () => {
|
|
818
|
-
const config = {
|
|
819
|
-
sourceConnection: process.env.TEST_MYSQL_URL!,
|
|
820
|
-
sourceDriver: 'mysql' as const,
|
|
821
|
-
targetDatabase: 'test-d1',
|
|
822
|
-
targetType: 'd1' as const,
|
|
823
|
-
};
|
|
824
|
-
|
|
825
|
-
const progress = await D1Migrator.DataMigrator.migrateData(config);
|
|
826
|
-
expect(progress.status).toBe('completed');
|
|
827
|
-
expect(progress.processedRows).toBeGreaterThan(0);
|
|
828
|
-
});
|
|
829
|
-
});
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
## Contributing
|
|
833
|
-
|
|
834
|
-
Contributions are welcome! Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) for details on our code of conduct and process for submitting pull requests.
|
|
835
|
-
|
|
836
|
-
### Bug Reports
|
|
837
|
-
|
|
838
|
-
[GitHub Issues](https://github.com/ZinTrust/zintrust/issues)
|
|
839
|
-
|
|
840
|
-
## License
|
|
841
|
-
|
|
842
|
-
MIT License - see [LICENSE.md](../../LICENSE.md) for details
|
|
843
|
-
|
|
844
|
-
## Support
|
|
845
|
-
|
|
846
|
-
- **Documentation**: [Full Documentation](../../docs/adapters.md)
|
|
847
|
-
- **Issues**: [GitHub Issues](https://github.com/ZinTrust/zintrust/issues)
|
|
848
|
-
- **Discussions**: [GitHub Discussions](https://github.com/ZinTrust/zintrust/discussions)
|
|
849
|
-
- **Email**: support@zintrust.dev
|
|
850
|
-
|
|
851
|
-
## Roadmap
|
|
852
|
-
|
|
853
|
-
- [ ] Resume from checkpoints (in progress)
|
|
854
|
-
- [ ] MongoDB source support
|
|
855
|
-
- [ ] GraphQL schema introspection
|
|
856
|
-
- [ ] Data anonymization during migration
|
|
857
|
-
- [ ] Real-time replication mode
|
|
858
|
-
- [ ] Web UI for migration management
|
|
859
|
-
|
|
860
|
-
## Related Packages
|
|
861
|
-
|
|
862
|
-
- [@zintrust/core](../core) - Core framework
|
|
863
|
-
- [@zintrust/db-mysql](../db-mysql) - MySQL adapter
|
|
864
|
-
- [@zintrust/db-postgres](../db-postgres) - PostgreSQL adapter
|
|
865
|
-
- [@zintrust/db-sqlite](../db-sqlite) - SQLite adapter
|
|
866
|
-
- [@zintrust/db-sqlserver](../db-sqlserver) - SQL Server adapter
|
|
867
|
-
- [@zintrust/db-d1](../db-d1) - D1 adapter
|
|
868
|
-
|
|
869
|
-
---
|
|
870
|
-
|
|
871
|
-
Made with ❤️ by ZinTrust
|