Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/lib/server/postgresql/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logger } from "../../../utils/logger";
import { type PJSe } from '../loader/loader';
import { readdir, readFile } from 'fs/promises';
import { join } from 'path';
import { createHash } from 'crypto';

const encodedPassword = encodeURIComponent(env.POSTGRESQL_PASSWORD);
const dbUrl = `postgres://${env.POSTGRESQL_USER}:${encodedPassword}@${env.POSTGRESQL_HOST}:${env.POSTGRESQL_PORT}/${env.POSTGRESQL_NAME}`;
Expand Down Expand Up @@ -64,9 +65,12 @@ export async function runMigrations(): Promise<void> {
const filePath = join(migrationFolder, file);
const sql = await readFile(filePath, 'utf-8');

// 파일 내용의 해시 계산
const contentHash = createHash('sha256').update(sql).digest('hex');

// 이미 실행된 마이그레이션인지 확인
const [existing] = await postgresClient`
SELECT id FROM drizzle_migrations WHERE hash = ${file}
SELECT id FROM drizzle_migrations WHERE hash = ${contentHash}
`;

if (!existing) {
Expand All @@ -80,7 +84,7 @@ export async function runMigrations(): Promise<void> {
// 실행 기록 저장
await tx.unsafe(
'INSERT INTO drizzle_migrations (hash, created_at) VALUES ($1, $2)',
[file, Date.now()]
[contentHash, Date.now()]
);
});

Expand Down