27 lines
3.5 KiB
PHP
27 lines
3.5 KiB
PHP
<?php
|
|
/** Run seed against a migrated V3 database, then migrate V4, then verify. Disposable DB only. */
|
|
require dirname(__DIR__).'/bootstrap.php';
|
|
use App\{DB,Seasons,ClubRoles};
|
|
if(getenv('ESBSC_TEST_DATABASE')!=='1')exit('Base jetable requise');
|
|
if(($argv[1]??'')==='seed'){
|
|
DB::query("INSERT INTO users(name,email,password_hash,role,must_change_password) VALUES('Admin','upgrade@example.test','inutilisable','admin',0)");$actor=DB::conn()->lastInsertId();
|
|
DB::query("INSERT INTO players(person_number,licence_number,last_name,first_name,active,member_role,usual_team_id) VALUES('1100000999','12345678','LEGACY','Alex',1,'player_staff',2)");$p=DB::conn()->lastInsertId();
|
|
$season=App\Regulations::season(date('Y-m-d'));DB::query("INSERT INTO person_licences(player_id,season,licence_number,licence_type) VALUES(?,?,?,'Libre')",[$p,$season,'12345678']);DB::query("INSERT INTO person_licences(player_id,season,licence_number,licence_type) VALUES(?,?,?,'Dirigeant')",[$p,$season,'87654321']);
|
|
DB::query("INSERT INTO person_roles(player_id,role_id,team_id) VALUES(?,(SELECT id FROM club_roles WHERE kind='sport' LIMIT 1),2)",[$p]);
|
|
DB::query("INSERT INTO matches(fff_match_id,team_id,match_date,opponent,competition,home_away,status,counts_for_purge) VALUES('UPGRADE',2,?,'Adversaire','Championnat','home','played',1)",[date('Y-m-d',strtotime('-7 days'))]);$mid=DB::conn()->lastInsertId();
|
|
DB::query("INSERT INTO sanctions(player_id,sanction_type,status,effective_date,matches_required,label) VALUES(?,'commission','official',?,4,'Décision à conserver')",[$p,date('Y-m-d',strtotime('-14 days'))]);
|
|
DB::query("INSERT INTO fmi_uploads(actor_id,match_id,filename,file_key,file_hash,payload,base_revision,status) VALUES(?,?,'fixture.pdf',?,?,?,1,'applied')",[$actor,$mid,str_repeat('a',32),str_repeat('b',64),'{}']);$fid=DB::conn()->lastInsertId();
|
|
DB::query('INSERT INTO match_participations(match_id,player_id,upload_id,shirt_number,starter,participated) VALUES(?,?,?,9,1,1)',[$mid,$p,$fid]);
|
|
DB::query('INSERT INTO squads(match_id,updated_by) VALUES(?,?)',[$mid,$actor]);$sid=DB::conn()->lastInsertId();DB::query('INSERT INTO squad_players VALUES(?,?)',[$sid,$p]);DB::query('INSERT INTO squad_staff VALUES(?,?)',[$sid,$p]);
|
|
DB::query("INSERT INTO reports(title,match_id,generated_by,revision,snapshot) VALUES('Archive',?,?,1,?)",[$mid,$actor,'{"fixture":"conserver"}']);
|
|
echo "Fixture V3 créée : double licence, staff, FMI, sanction, groupe et rapport.\n";
|
|
}else{
|
|
$p=DB::one("SELECT * FROM players WHERE person_number='1100000999'");
|
|
foreach(['person_licences'=>2,'person_roles'=>1,'matches'=>1,'sanctions'=>1,'fmi_uploads'=>1,'match_participations'=>1,'squads'=>1,'squad_players'=>1,'squad_staff'=>1,'reports'=>1] as $table=>$n)if((int)DB::value("SELECT COUNT(*) FROM $table")!==$n)throw new RuntimeException('Perte de données : '.$table);
|
|
if(DB::value('SELECT snapshot FROM reports')!=='{"fixture":"conserver"}')throw new RuntimeException('Rapport modifié');
|
|
$members=Seasons::decorate([$p]);if(count($members)!==1||$members[0]['usual_team_id']!=2||$members[0]['member_role']!=='player_staff')throw new RuntimeException('Effectif migré incorrectement');
|
|
if(count(ClubRoles::index()[$p['id']]??[])!==1)throw new RuntimeException('Staff non migré');
|
|
$m=DB::one("SELECT * FROM matches WHERE fff_match_id='UPGRADE'");$check=App\Eligibility::check($p,2,date('Y-m-d'));if($check['details'][0]['remaining']!==3)throw new RuntimeException('Purge modifiée');
|
|
echo "Migration réelle V3 → V4 : historiques, double profil et purge 1/4 conservés.\n";
|
|
}
|