Adjust user appraisal order flow
This commit is contained in:
48
server-api/tools/schema_upgrade_appraisal_brand_input.php
Normal file
48
server-api/tools/schema_upgrade_appraisal_brand_input.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
||||
$dotenv->safeLoad();
|
||||
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
|
||||
$_ENV['DB_HOST'] ?? '127.0.0.1',
|
||||
$_ENV['DB_PORT'] ?? '3306',
|
||||
$_ENV['DB_DATABASE'] ?? '',
|
||||
$_ENV['DB_CHARSET'] ?? 'utf8mb4'
|
||||
);
|
||||
|
||||
$pdo = new PDO(
|
||||
$dsn,
|
||||
$_ENV['DB_USERNAME'] ?? '',
|
||||
$_ENV['DB_PASSWORD'] ?? '',
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]
|
||||
);
|
||||
|
||||
function abiHasColumn(PDO $pdo, string $table, string $column): bool
|
||||
{
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?');
|
||||
$stmt->execute([$table, $column]);
|
||||
return (int)$stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
if (!abiHasColumn($pdo, 'appraisal_draft_products', 'brand_name')) {
|
||||
$pdo->exec("ALTER TABLE appraisal_draft_products ADD COLUMN brand_name VARCHAR(128) NOT NULL DEFAULT '' AFTER brand_id");
|
||||
echo "ADD_COLUMN appraisal_draft_products.brand_name\n";
|
||||
}
|
||||
|
||||
$pdo->exec(<<<'SQL'
|
||||
UPDATE appraisal_draft_products p
|
||||
JOIN catalog_brands b ON b.id = p.brand_id
|
||||
SET p.brand_name = b.name
|
||||
WHERE p.brand_name = ''
|
||||
AND p.brand_id IS NOT NULL
|
||||
SQL);
|
||||
|
||||
echo "SCHEMA_UPGRADE_APPRAISAL_BRAND_INPUT_OK\n";
|
||||
Reference in New Issue
Block a user