<?php
/** CLI: first argument is the site root. Adds frequency without changing existing rows. */
if(PHP_SAPI!=='cli')exit;
$root=$argv[1]??'D:/phpstudy_pro/WWW/cqoms.com';
require rtrim($root,'/\\').'/vendor/autoload.php';
$app=new \think\App(rtrim($root,'/\\').'/');$app->initialize();
$c=\think\facade\Db::connect()->getConfig();$table=$c['prefix'].'me_check_list';
if(!preg_match('/^[a-zA-Z0-9_]+$/D',$table))throw new RuntimeException('Invalid table');
$columns=\think\facade\Db::query("SHOW COLUMNS FROM `".$table."` LIKE 'freq'");
if(!$columns)\think\facade\Db::execute('ALTER TABLE `'.$table.'` ADD COLUMN `freq` TINYINT NOT NULL DEFAULT 1 AFTER `num`');
echo json_encode(['database'=>$c['database'],'table'=>$table,'freq'=>$columns?'already exists':'added'],JSON_UNESCAPED_UNICODE),PHP_EOL;
