-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigration.bat
More file actions
282 lines (247 loc) · 5.49 KB
/
migration.bat
File metadata and controls
282 lines (247 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
:: English output setup
color 0F
:HEADER
cls
echo.
echo =========================================
echo MSSQL Data Migration Tool v1.0
echo =========================================
echo.
:: Check Node.js installation
node --version >nul 2>&1
if %errorlevel% neq 0 (
echo Node.js is not installed.
echo Please install Node.js from https://nodejs.org
echo.
pause
exit /b 1
)
:MENU
echo =========================================
echo Menu Selection
echo =========================================
echo 1. Validate Query Definition File Syntax
echo 2. Test DB Connection (including connectivity)
echo 3. Execute Data Migration
echo 4. Show Help
echo 0. Exit
echo =========================================
echo.
set /p choice=Please select (0-4):
if "%choice%"=="1" goto VALIDATE
if "%choice%"=="2" goto TEST
if "%choice%"=="3" goto MIGRATE
if "%choice%"=="4" goto HELP
if "%choice%"=="0" goto EXIT
echo Invalid selection. Please try again.
echo.
pause
goto MENU
:VALIDATE
echo.
echo =========================================
echo Query Definition File Validation
echo =========================================
echo.
echo.
echo Available query definition files:
echo.
if exist "queries\*.xml" (
for %%f in (queries\*.xml) do echo - %%f
)
if exist "queries\*.json" (
for %%f in (queries\*.json) do echo - %%f
)
echo.
echo Please enter the query definition file path (e.g., queries/my-config.xml):
set /p config_file=
if "%config_file%"=="" (
echo Query definition file path was not entered.
echo.
pause
goto MENU
)
echo.
echo Validating query definition file...
echo.
node src/migrate-cli.js validate --query "%config_file%"
if %errorlevel% equ 0 (
echo.
echo Query definition file validation completed successfully.
) else (
echo.
echo There are errors in the query definition file.
)
echo.
pause
goto MENU
:TEST
echo.
echo =========================================
echo Database Connection Test
echo =========================================
echo.
echo Testing database connection...
echo.
node src/migrate-cli.js list-dbs
if %errorlevel% equ 0 (
echo.
echo Database connection test was successful.
) else (
echo.
echo Database connection failed.
echo Please check the connection information in the .env file.
)
echo.
pause
goto MENU
:MIGRATE
echo.
echo =========================================
echo Execute Data Migration
echo =========================================
echo.
echo Available query definition files:
echo.
if exist "queries\*.xml" (
for %%f in (queries\*.xml) do echo - %%f
)
if exist "queries\*.json" (
for %%f in (queries\*.json) do echo - %%f
)
echo.
echo.
echo Please enter the query definition file path (e.g., queries/my-config.xml):
set /p config_file=
if "%config_file%"=="" (
echo Query definition file path was not entered.
echo.
pause
goto MENU
)
echo.
echo Do you really want to execute data migration? (Y/N)
set /p confirm=
if /i "!confirm!" neq "Y" (
echo Migration was cancelled.
echo.
pause
goto MENU
)
echo.
echo Starting data migration...
echo.
:: Record start time
set start_time=%time%
node src/migrate-cli.js migrate --query "%config_file%"
if %errorlevel% equ 0 (
echo.
echo Data migration completed successfully.
echo Start time: %start_time%
echo End time: %time%
) else (
echo.
echo An error occurred during data migration.
echo Please check the log files.
)
echo.
pause
goto MENU
:HELP
echo.
echo =========================================
echo Help
echo =========================================
echo.
npm run help
echo.
pause
goto MENU
:LOGS
echo.
echo =========================================
echo View Log Files
echo =========================================
echo.
if not exist "logs" (
echo Log directory does not exist.
echo.
pause
goto MENU
)
echo Recent log files:
echo.
dir /b /o-d logs\*.log 2>nul
if %errorlevel% neq 0 (
echo No log files found.
echo.
pause
goto MENU
)
echo.
echo Please enter the log file name you want to view (filename only, not full path):
set /p logfile=
if exist "logs\%logfile%" (
echo.
echo === %logfile% content ===
echo.
type "logs\%logfile%"
) else (
echo The specified log file was not found.
)
echo.
pause
goto MENU
:EDIT
echo.
echo =========================================
echo Edit Query Definition File
echo =========================================
echo.
echo Please select a file to edit:
echo.
echo 1. .env (Database connection settings)
echo 2. Custom query definition file
echo 3. Go back
echo.
set /p edit_choice=Please select (1-3):
if "%edit_choice%"=="1" (
if exist ".env" (
notepad .env
) else (
echo .env file does not exist. Please copy env.example to create .env file.
echo.
echo Do you want to copy env.example? (Y/N)
set /p copy_env=
if /i "!copy_env!"=="Y" (
copy "env.example" ".env"
echo .env file has been created. You can now edit it.
notepad .env
)
)
) else if "%edit_choice%"=="2" (
echo.
echo Please enter the path of the query definition file to edit:
set /p edit_file=
if exist "!edit_file!" (
notepad "!edit_file!"
) else (
echo The specified file was not found: !edit_file!
)
) else if "%edit_choice%"=="3" (
goto MENU
) else (
echo Invalid selection.
)
echo.
pause
goto MENU
:EXIT
echo.
echo Exiting the program.
echo.
pause
exit /b 0