테이블관리
This commit is contained in:
82
backend-node/create-test-user.js
Normal file
82
backend-node/create-test-user.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const { Client } = require("pg");
|
||||
require("dotenv/config");
|
||||
|
||||
async function createTestUser() {
|
||||
const client = new Client({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
console.log("✅ 데이터베이스 연결 성공");
|
||||
|
||||
// 테스트용 사용자 생성 (MD5 해시: admin123)
|
||||
const testUser = {
|
||||
user_id: "admin",
|
||||
user_name: "테스트 관리자",
|
||||
user_password: "f21b1ce8b08dc955bd4afff71b3db1fc", // admin123의 MD5 해시
|
||||
status: "active",
|
||||
company_code: "ILSHIN",
|
||||
data_type: "PLM",
|
||||
};
|
||||
|
||||
// 기존 사용자 확인
|
||||
const existingUser = await client.query(
|
||||
"SELECT user_id FROM user_info WHERE user_id = $1",
|
||||
[testUser.user_id]
|
||||
);
|
||||
|
||||
if (existingUser.rows.length > 0) {
|
||||
console.log("⚠️ 테스트 사용자가 이미 존재합니다:", testUser.user_id);
|
||||
|
||||
// 기존 사용자 정보 업데이트
|
||||
await client.query(
|
||||
`
|
||||
UPDATE user_info
|
||||
SET user_name = $1, user_password = $2, status = $3
|
||||
WHERE user_id = $4
|
||||
`,
|
||||
[
|
||||
testUser.user_name,
|
||||
testUser.user_password,
|
||||
testUser.status,
|
||||
testUser.user_id,
|
||||
]
|
||||
);
|
||||
|
||||
console.log("✅ 테스트 사용자 정보 업데이트 완료");
|
||||
} else {
|
||||
// 새 사용자 생성
|
||||
await client.query(
|
||||
`
|
||||
INSERT INTO user_info (user_id, user_name, user_password, status, company_code, data_type)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`,
|
||||
[
|
||||
testUser.user_id,
|
||||
testUser.user_name,
|
||||
testUser.user_password,
|
||||
testUser.status,
|
||||
testUser.company_code,
|
||||
testUser.data_type,
|
||||
]
|
||||
);
|
||||
|
||||
console.log("✅ 테스트 사용자 생성 완료");
|
||||
}
|
||||
|
||||
// 생성된 사용자 확인
|
||||
const createdUser = await client.query(
|
||||
"SELECT user_id, user_name, status FROM user_info WHERE user_id = $1",
|
||||
[testUser.user_id]
|
||||
);
|
||||
|
||||
console.log("👤 생성된 사용자:", createdUser.rows[0]);
|
||||
} catch (error) {
|
||||
console.error("❌ 오류 발생:", error);
|
||||
} finally {
|
||||
await client.end();
|
||||
}
|
||||
}
|
||||
|
||||
createTestUser();
|
||||
Reference in New Issue
Block a user