migrate_water_agent_hierarchy.php 912 B

1234567891011121314
  1. <?php
  2. /** Add explicit water-agent hierarchy without inferring legacy organizational levels. */
  3. require dirname(__DIR__).'/vendor/autoload.php';
  4. \Dotenv\Dotenv::createUnsafeMutable(dirname(__DIR__))->load();
  5. \support\App::loadAllConfig(['route']);
  6. use plugin\saiadmin\app\model\water\WaterAgent;
  7. $schema=(new WaterAgent())->getConnection()->getSchemaBuilder();
  8. if (!in_array('--apply',$argv,true)) { echo "Plan: add nullable parent_id to water agents; existing levels remain unconfigured.\n"; exit; }
  9. if (!$schema->hasColumn('sa_water_agent','parent_id')) {
  10. $schema->table('sa_water_agent',function (\Illuminate\Database\Schema\Blueprint $table) {
  11. $table->unsignedBigInteger('parent_id')->nullable()->index()->comment('NULL未设置,0一级代理,其余为上级供水代理ID');
  12. });
  13. }
  14. echo "Applied: agent parent_id available; existing accounts, permissions and business data preserved.\n";