diff --git a/database_setup.sql b/database_setup.sql index d31441f..597c621 100644 --- a/database_setup.sql +++ b/database_setup.sql @@ -4,10 +4,29 @@ -- 이 스크립트는 postgres superuser로 실행해야 합니다. -- 실행 방법: psql -U postgres -f database_setup.sql --- 1. 데이터베이스 생성 (필요한 경우) --- CREATE DATABASE dewey_memory; +-- 1. dewey 사용자 생성 (이미 존재하면 스킵) +DO $$ +BEGIN + IF NOT EXISTS (SELECT FROM pg_user WHERE usename = 'dewey') THEN + CREATE USER dewey WITH PASSWORD '0bk1rWu98mGl5ea3'; + RAISE NOTICE 'dewey 사용자가 생성되었습니다.'; + ELSE + RAISE NOTICE 'dewey 사용자가 이미 존재합니다.'; + END IF; +END $$; --- 2. dewey_memory 데이터베이스에 연결 +-- 2. dewey_memory 데이터베이스 생성 (이미 존재하면 스킵) +DO $$ +BEGIN + IF NOT EXISTS (SELECT FROM pg_database WHERE datname = 'dewey_memory') THEN + CREATE DATABASE dewey_memory OWNER dewey; + RAISE NOTICE 'dewey_memory 데이터베이스가 생성되었습니다.'; + ELSE + RAISE NOTICE 'dewey_memory 데이터베이스가 이미 존재합니다.'; + END IF; +END $$; + +-- 3. dewey_memory 데이터베이스에 연결 \c dewey_memory -- 3. pgvector 확장 설치 (superuser 권한 필요)