Files
ulthon_admin/tests/setup_test_db.ps1
augushong 553047025c refactor(install): 种子退役,migrate:run 一条命令完成建表与初始数据
新增 InitDataAlignService 六域对齐(超管/角色/权限节点/配置/快捷入口/商城演示)与 20260909130000 迁移;SystemAdmin 快照以字面量哈希入库;删除种子三件与安装锁依赖,seeds 目录留 .gitkeep;README/tests/规则等 11 处说明同步。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-09 14:38:10 +00:00

47 lines
1.6 KiB
PowerShell

<#
.SYNOPSIS
Test database setup (Windows / PowerShell wrapper).
.DESCRIPTION
Calls the PHP runner tests/setup_test_db.php, which in a single process:
1. reads connection params from .env (hostname/hostport/username/password/
charset/prefix/database)
2. derives the test DB name as {env.database} + '_test'
(e.g. ulthon_admin -> ulthon_admin_test)
3. CREATE DATABASE IF NOT EXISTS on the same MySQL instance (no Docker)
4. config-level override connections.main -> test DB
5. php think migrate:run -> system/framework tables + all initial data
(database/migrations/)
6. php think scheme:sync -> business tables (app/admin/scheme/)
7. queries information_schema to verify the tables landed in the test DB
Fully parameterized: no hardcoded host/port/credentials. The MySQL instance
is whatever .env points at (typically a single local MySQL).
.NOTES
ASCII-only on purpose: PowerShell 5.1 mis-decodes BOM-less UTF-8 CJK.
#>
# Runner lives next to this script.
$Runner = Join-Path $PSScriptRoot 'setup_test_db.php'
# 1. Ensure php is on PATH.
$phpCmd = Get-Command php -ErrorAction SilentlyContinue
if (-not $phpCmd) {
Write-Host "[ERROR] 'php' not found on PATH. Install PHP 8+ and add it to PATH." -ForegroundColor Red
exit 1
}
# 2. Run the PHP runner.
Write-Host "==== Running setup_test_db.php ====" -ForegroundColor Cyan
& php $Runner
$code = $LASTEXITCODE
Write-Host ""
if ($code -eq 0) {
Write-Host "==== Done. PHP exit code = $code ====" -ForegroundColor Green
} else {
Write-Host "==== Done. PHP exit code = $code ====" -ForegroundColor Red
}
exit $code