초기 PM 소스 전체 업로드
This commit is contained in:
62
db_patch.js
Normal file
62
db_patch.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const pool = require("./db/pool.js");
|
||||
|
||||
async function checkAndAddColumn(tableName, columnName, columnDefinition) {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
// 컬럼 존재 여부 확인
|
||||
const checkQuery = `
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'ver4'
|
||||
AND table_name = $1
|
||||
AND column_name = $2;
|
||||
`;
|
||||
const res = await client.query(checkQuery, [tableName, columnName]);
|
||||
const exists = parseInt(res.rows[0].count) > 0;
|
||||
|
||||
if (!exists) {
|
||||
console.log(`Adding column [${columnName}] to [ver4.${tableName}]...`);
|
||||
const alterQuery = `ALTER TABLE ver4.${tableName} ADD COLUMN ${columnName} ${columnDefinition};`;
|
||||
await client.query(alterQuery);
|
||||
console.log(`Successfully added [${columnName}] to [ver4.${tableName}].`);
|
||||
} else {
|
||||
console.log(`Column [${columnName}] already exists in [ver4.${tableName}].`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Error processing table ${tableName}, column ${columnName}:`, err);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
console.log("Starting DB patch processing...");
|
||||
|
||||
// 1. tb_data
|
||||
await checkAndAddColumn("tb_data", "popup_size", "BIGINT DEFAULT 0");
|
||||
await checkAndAddColumn("tb_data", "preview_size", "BIGINT DEFAULT 0");
|
||||
|
||||
// 2. _test_tb_data
|
||||
await checkAndAddColumn("_test_tb_data", "popup_size", "BIGINT DEFAULT 0");
|
||||
await checkAndAddColumn("_test_tb_data", "preview_size", "BIGINT DEFAULT 0");
|
||||
|
||||
// 3. tb_official_doc_file
|
||||
await checkAndAddColumn("tb_official_doc_file", "popup_size", "BIGINT DEFAULT 0");
|
||||
await checkAndAddColumn("tb_official_doc_file", "preview_size", "BIGINT DEFAULT 0");
|
||||
|
||||
// 4. tb_download_folder
|
||||
await checkAndAddColumn("tb_download_folder", "expire_date", "TIMESTAMP");
|
||||
await checkAndAddColumn("tb_download_folder", "made", "BOOLEAN DEFAULT FALSE");
|
||||
await checkAndAddColumn("tb_download_folder", "path", "TEXT");
|
||||
await checkAndAddColumn("tb_download_folder", "name", "TEXT");
|
||||
|
||||
console.log("DB patch processing finished.");
|
||||
} catch (err) {
|
||||
console.error("Migration script failed:", err);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user