v1.12.31 불필요 파일 정리 및 업로드·배포 안정성 보강
This commit is contained in:
@@ -63,3 +63,36 @@ test('운영 이미지 빌드는 읽을 수 없는 환경 파일을 거부한다
|
||||
rmSync(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('운영 마이그레이션은 SQL과 이력을 같은 트랜잭션으로 실행하고 실패하면 중단한다', () => {
|
||||
const directory = mkdtempSync(join(tmpdir(), 'sori-migration-test-'))
|
||||
try {
|
||||
const logPath = join(directory, 'docker.log')
|
||||
const envPath = join(directory, 'production.env')
|
||||
writeFileSync(envPath, 'COMPOSE_PROJECT_NAME=sori-studio\n')
|
||||
writeFileSync(join(directory, 'docker'), `#!/bin/sh
|
||||
printf "<%s>" "$@" >> "$SORI_TEST_DOCKER_LOG"
|
||||
printf "\\n" >> "$SORI_TEST_DOCKER_LOG"
|
||||
for argument in "$@"; do
|
||||
case "$argument" in
|
||||
*"to_regclass('public.schema_migrations')"*) printf 't\\n' ;;
|
||||
--single-transaction) exit 19 ;;
|
||||
esac
|
||||
done
|
||||
`, { mode: 0o755 })
|
||||
const result = spawnSync('sh', ['scripts/migrate-production-db.sh', 'migrate'], {
|
||||
cwd: root, encoding: 'utf8',
|
||||
env: { ...process.env, PATH: `${directory}:${process.env.PATH}`, ENV_FILE: envPath, SORI_TEST_DOCKER_LOG: logPath }
|
||||
})
|
||||
assert.equal(result.status, 19, result.stderr)
|
||||
const calls = readFileSync(logPath, 'utf8').trim().split('\n')
|
||||
const transactions = calls.filter(call => call.includes('<--single-transaction>'))
|
||||
assert.equal(transactions.length, 1)
|
||||
assert.ok(transactions[0].startsWith(`<compose><-f><${join(root, 'docker-compose.yaml')}><--env-file><${envPath}>`))
|
||||
assert.match(transactions[0], /<-f><\/docker-entrypoint-initdb.d\/001_[^>]+\.sql>/)
|
||||
assert.match(transactions[0], /<-c><INSERT INTO schema_migrations \(file_name\) VALUES \('001_[^']+\.sql'\)/)
|
||||
assert.doesNotMatch(result.stdout, /마이그레이션 실행 완료/)
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user