서버 데이터베이스 자동 마이그레이션 코드 추가 (누락 컬럼 자동 생성)

This commit is contained in:
2026-01-04 19:19:49 +09:00
parent f8546431e9
commit 6341d70f36
2 changed files with 19 additions and 1 deletions

View File

@@ -50,7 +50,7 @@ try {
FROM sales_record
WHERE member_id = ? AND status = 'completed' AND contract_date BETWEEN ? AND ?
UNION ALL
SELECT p.id, t.name as customer, p.contract_date as contractDate, p.contract_amount as amount
SELECT p.id, t.tenant_name as customer, p.contract_date as contractDate, p.contract_amount as amount
FROM sales_tenant_products p
JOIN sales_tenants t ON p.tenant_id = t.id
WHERE (t.sales_manager_id = ? OR (t.sales_manager_id IS NULL AND t.manager_id = ?))

View File

@@ -139,6 +139,24 @@ try {
if (!in_array('consultation_type', $cols)) {
$pdo->exec("ALTER TABLE `sales_tenant_consultations` ADD COLUMN `consultation_type` varchar(20) DEFAULT 'text' AFTER `attachment_paths` ");
}
// 5. sales_tenants 테이블에 sales_manager_id 컬럼 추가
$check5 = $pdo->query("SHOW COLUMNS FROM `sales_tenants` LIKE 'sales_manager_id'")->fetch();
if (!$check5) {
$pdo->exec("ALTER TABLE `sales_tenants` ADD COLUMN `sales_manager_id` int(11) DEFAULT NULL AFTER `manager_id` ");
}
// 6. sales_tenant_products 테이블 컬럼 확인 및 추가
$prodCols = $pdo->query("SHOW COLUMNS FROM `sales_tenant_products`")->fetchAll(PDO::FETCH_COLUMN);
if (!in_array('operator_confirmed', $prodCols)) {
$pdo->exec("ALTER TABLE `sales_tenant_products` ADD COLUMN `operator_confirmed` tinyint(1) DEFAULT 0 AFTER `contract_date` ");
}
if (!in_array('sub_models', $prodCols)) {
$pdo->exec("ALTER TABLE `sales_tenant_products` ADD COLUMN `sub_models` text DEFAULT NULL AFTER `operator_confirmed` ");
}
if (!in_array('commission_amount', $prodCols)) {
$pdo->exec("ALTER TABLE `sales_tenant_products` ADD COLUMN `commission_amount` decimal(15,2) DEFAULT 0.00 AFTER `commission_rate` ");
}
} catch (Exception $e) {
error_log("Migration error: " . $e->getMessage());
}