mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-10-29 08:58:22 +08:00
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>
This commit is contained in:
36
database/migrations/20260909130000_system_init_data.php
Normal file
36
database/migrations/20260909130000_system_init_data.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use app\admin\service\InitDataAlignService;
|
||||
use think\console\Output;
|
||||
use think\migration\Migrator;
|
||||
|
||||
/**
|
||||
* 系统初始化数据对齐 - 种子退役后初始数据的唯一安装途径
|
||||
*
|
||||
* 背景:seed:run 退役,migrate:run 成为唯一安装命令(建表 + 全部初始数据)。
|
||||
* 本迁移调用 InitDataAlignService 把 adminInitData/ 快照对齐到当前库:
|
||||
* - 超管 id=1 只插不改(密码永不覆盖,软删行不复活)
|
||||
* - 角色 id=1/id=6 逐行只插
|
||||
* - 权限节点跳过(注解动态扫描)
|
||||
* - 配置按 (group, name) 只插缺失,插后清 sysconfig 缓存
|
||||
* - 快捷入口按 href 只插缺失(软删行不复活)
|
||||
* - 商城演示分表守卫(cate/goods/tag 各自空则插)
|
||||
*
|
||||
* 幂等:phinxlog 按文件记账保证只执行一次;重放由服务内的存在性检查兜底。
|
||||
* down:数据对齐迁移不提供对称回滚(无法精确还原对齐前的用户态数据),
|
||||
* 如需回退参考 adminInitData/ 下各快照手工处理。
|
||||
*/
|
||||
class SystemInitData extends Migrator
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$service = new InitDataAlignService(new Output());
|
||||
|
||||
$service->align();
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// 有意留空:见类注释 down 说明
|
||||
}
|
||||
}
|
||||
1
database/seeds/.gitkeep
Normal file
1
database/seeds/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 种子已退役:migrate:run 是唯一安装命令;下游业务仍可放自己的种子文件
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
use app\admin\model\SystemConfig;
|
||||
use app\admin\service\AdminInitService;
|
||||
use app\admin\service\TriggerService;
|
||||
use think\migration\Seeder;
|
||||
|
||||
class InitBaseAdminData extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run Method.
|
||||
*
|
||||
* Write your database seeder using this method.
|
||||
*
|
||||
* More information on writing seeders is available here:
|
||||
* http://docs.phinx.org/en/latest/seeding.html
|
||||
*/
|
||||
public function run():void
|
||||
{
|
||||
$output = $this->getOutput();
|
||||
|
||||
TriggerService::updateSysconfig();
|
||||
|
||||
$install_lock = sysconfig('base_admin_install', true, 0);
|
||||
|
||||
if ($install_lock == 1) {
|
||||
$output->writeln('系统已初始化,跳过当前程序');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$model_config = SystemConfig::where('group', 'system')
|
||||
->where('name', 'base_admin_install')
|
||||
->find();
|
||||
|
||||
if (empty($model_config)) {
|
||||
$model_config = new SystemConfig();
|
||||
|
||||
$model_config->group = 'system';
|
||||
$model_config->name = 'base_admin_install';
|
||||
$model_config->remark = '系统初始化锁定,请勿修改,避免插入重复数据';
|
||||
}
|
||||
|
||||
$model_config->value = 1;
|
||||
|
||||
$model_config->save();
|
||||
|
||||
TriggerService::updateSysconfig();
|
||||
|
||||
(new AdminInitService($output))->init();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user