Files
sbnews/qa/backend/test_match_live_schema_static.php

71 lines
2.0 KiB
PHP

<?php
$root = dirname(__DIR__, 2);
$sqlPath = $root . '/docs/sql/create_match_live_table.sql';
$modelPath = $root . '/server/app/common/model/match/MatchLive.php';
if (!is_file($sqlPath)) {
fwrite(STDERR, "missing sql file\n");
exit(1);
}
if (!is_file($modelPath)) {
fwrite(STDERR, "missing model file\n");
exit(1);
}
$sql = file_get_contents($sqlPath);
$model = file_get_contents($modelPath);
$requiredSql = [
'CREATE TABLE IF NOT EXISTS `la_match_live`',
'`match_id` int UNSIGNED NOT NULL',
'`title` varchar(255)',
'`source_url` varchar(500)',
'`play_url_m3u8` varchar(1000)',
'`play_url_hd_m3u8` varchar(1000)',
'`play_url_flv` varchar(1000)',
'`play_url_hd_flv` varchar(1000)',
'`fetch_status` tinyint',
'`fetch_error` varchar(500)',
'`last_fetch_at` int UNSIGNED NOT NULL',
'`next_fetch_at` int UNSIGNED NOT NULL',
'`create_time` int UNSIGNED NOT NULL',
'`update_time` int UNSIGNED NOT NULL',
'`delete_time` int UNSIGNED DEFAULT NULL',
'UNIQUE KEY `uk_match_source_url` (`match_id`, `source_url`)',
'KEY `idx_match_id` (`match_id`)',
'KEY `idx_next_fetch_at` (`next_fetch_at`)',
'KEY `idx_fetch_status` (`fetch_status`)',
'KEY `idx_match_create_time` (`match_id`, `create_time`)',
];
foreach ($requiredSql as $needle) {
if (strpos($sql, $needle) === false) {
fwrite(STDERR, "missing sql token: {$needle}\n");
exit(1);
}
}
if (strpos($model, "protected \$name = 'match_live';") === false) {
fwrite(STDERR, "model table name mismatch\n");
exit(1);
}
if (strpos($model, 'extends BaseModel') === false) {
fwrite(STDERR, "model base class mismatch\n");
exit(1);
}
if (strpos($model, 'use SoftDelete;') === false) {
fwrite(STDERR, "model soft delete missing\n");
exit(1);
}
if (strpos($model, "protected \$deleteTime = 'delete_time';") === false) {
fwrite(STDERR, "model delete time mismatch\n");
exit(1);
}
echo "schema static checks passed\n";