DB를 MySQL에서 PostgreSQL로 전면 전환
- Sequelize dialect를 postgres로 변경, mysql2 대신 pg/pg-hstore 사용 - docker-compose: postgres:16-alpine + pg_isready healthcheck, 호스트 포트 5442 - 환경변수 MYSQL_PORT -> DB_PORT로 통일, .env.example 갱신 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+7
-7
@@ -19,15 +19,15 @@ const swaggerJsdoc = require("swagger-jsdoc");
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// MySQL Connection using Sequelize
|
||||
// PostgreSQL Connection using Sequelize
|
||||
const sequelize = new Sequelize(
|
||||
process.env.DB_NAME || "report_db",
|
||||
process.env.DB_USER || "root",
|
||||
process.env.DB_USER || "postgres",
|
||||
process.env.DB_PASSWORD || "password",
|
||||
{
|
||||
host: process.env.DB_HOST || "localhost",
|
||||
port: process.env.MYSQL_PORT || 3306,
|
||||
dialect: "mysql",
|
||||
port: process.env.DB_PORT || 5432,
|
||||
dialect: "postgres",
|
||||
logging: false,
|
||||
},
|
||||
);
|
||||
@@ -211,7 +211,7 @@ const LoginLog = sequelize.define(
|
||||
sequelize
|
||||
.authenticate()
|
||||
.then(() => {
|
||||
console.log("MySQL Connected...");
|
||||
console.log("PostgreSQL Connected...");
|
||||
// 테이블 구조가 변경되었을 경우 자동으로 반영하도록 alter: true 추가
|
||||
return sequelize.sync({ alter: true });
|
||||
})
|
||||
@@ -243,7 +243,7 @@ sequelize
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((err) => console.log("MySQL Connection/Sync Error:", err));
|
||||
.catch((err) => console.log("PostgreSQL Connection/Sync Error:", err));
|
||||
|
||||
// Auth Middleware
|
||||
const authenticateToken = (req, res, next) => {
|
||||
@@ -900,7 +900,7 @@ app.post("/api/report", authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { companyId, ...data } = req.body;
|
||||
|
||||
// upsert (MySQL에서는 INSERT ... ON DUPLICATE KEY UPDATE)
|
||||
// upsert (PostgreSQL에서는 INSERT ... ON CONFLICT DO UPDATE)
|
||||
const [report, created] = await Report.upsert({
|
||||
companyId,
|
||||
owner: req.user.username,
|
||||
|
||||
Reference in New Issue
Block a user