refactor: 일반 실행 경로의 DB 변경을 버전형 마이그레이션으로 이전
과거 누적 DDL과 데이터 보정을 시점별 SQL로 분리하고 관리자·CLI 실행기를 제공한다. 실행 순서, 잠금, 체크섬, 성공·실패 이력 및 개별 실행의 선행 조건을 검증한다. 기존 스키마의 부분 적용 복구와 설치 SQL 정합성 검사를 추가하고 실행·복구 절차를 문서화한다.
This commit is contained in:
1 parent
d111100856
commit
5bdbf360b0
76 files changed
+1826
-2182
No files matched your search
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit("CLI에서만 실행할 수 있습니다.\n");
|
||||
}
|
||||
|
||||
$root = dirname(dirname(__FILE__));
|
||||
chdir($root);
|
||||
|
||||
define('G5_IS_CLI', true);
|
||||
$_SERVER['SCRIPT_FILENAME'] = $root . '/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
$_SERVER['REQUEST_URI'] = '/';
|
||||
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||
$_SERVER['SERVER_PORT'] = 80;
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['REQUEST_METHOD'] = 'CLI';
|
||||
|
||||
require_once $root . '/common.php';
|
||||
require_once G5_LIB_PATH . '/migration.lib.php';
|
||||
|
||||
$command = isset($argv[1]) ? $argv[1] : 'status';
|
||||
|
||||
if ($command === 'status') {
|
||||
$statuses = g5_migration_status();
|
||||
foreach ($statuses as $status) {
|
||||
if (isset($status['error'])) {
|
||||
fwrite(STDERR, '[오류] ' . $status['error'] . "\n");
|
||||
exit(1);
|
||||
}
|
||||
$label = g5_migration_status_label($status['status'], $status['checksum_changed']);
|
||||
echo '[' . $label . '] ' . $status['id'] . ' ' . $status['description'] . "\n";
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ($command !== 'migrate') {
|
||||
fwrite(STDERR, "사용법: php bin/db-migrate.php status | migrate [마이그레이션_ID]\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$target_id = isset($argv[2]) && $argv[2] !== '--all' ? $argv[2] : '';
|
||||
$result = g5_migration_run($target_id);
|
||||
if (!$result['success']) {
|
||||
foreach ($result['errors'] as $error) {
|
||||
fwrite(STDERR, '[실패] ' . $error . "\n");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo '적용: ' . $result['applied'] . ', 기존 스키마 확인: ' . $result['skipped'] . "\n";
|
||||
Reference in new issue
Block a user