Skip to content

PostgreSQL을 사용하여 DB 초기 구축#81

Merged
reddevilmidzy merged 4 commits intomainfrom
db
May 27, 2025
Merged

PostgreSQL을 사용하여 DB 초기 구축#81
reddevilmidzy merged 4 commits intomainfrom
db

Conversation

@reddevilmidzy
Copy link
Owner

♟️ What’s this PR about?

PostgreSQL을 사용한 DB를 구축하였습니다.

알아두면 좋을 명령어.

컴파일 타임에 확인할 수 있도록 해주는 명령어.

cargo sqlx prepare

migrates 디렉터리 안에 있는 sql 문의 변경및실행을 추적하고 새로 변경되었다면 sql 파일 실행

sqlx migrate run

🔗 Related Issues / PRs

close: #80

Copilot AI review requested due to automatic review settings May 27, 2025 13:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR sets up a PostgreSQL database for the Queensac service. The key changes include:

  • Adding database initialization and pool creation in main.rs.
  • Introducing a new db module with functions for creating the pool and initializing the database.
  • Adding a new migration file and updating Cargo.toml and .env for PostgreSQL support.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rook/src/main.rs Integrates database pool creation, dotenv usage, and updates app() to accept state.
rook/src/lib.rs Exports the new db module.
rook/src/db.rs Implements create_pool, init_db, and adds a test for database connection.
rook/migrations/202450527173623_initial.sql Provides initial SQL migration for subscribers table.
rook/Cargo.toml Adds required dependencies for sqlx and dotenv.
rook/.env Defines the DATABASE_URL for local PostgreSQL connection.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link

?? Blunder 😵‍💫
Your CI made a critical mistake on the board.

❌ Failure Details
test db::tests::test_database_connection ... FAILED
test schedule::tests::test_interval_timing ... ok
test schedule::tests::test_scheduled_execution ... ok
test link::tests::validate_link ... ok

failures:

---- db::tests::test_database_connection stdout ----

thread 'db::tests::test_database_connection' panicked at src/db.rs:30:14:
Failed to create database pool: PoolTimedOut
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    db::tests::test_database_c

See the full battle logs here: View Logs

Time to rethink your next move!

@github-actions
Copy link

?? Blunder 😵‍💫
Your CI made a critical mistake on the board.

❌ Failure Details
test db::tests::test_database_connection ... FAILED
test schedule::tests::test_interval_timing ... ok
test schedule::tests::test_scheduled_execution ... ok
test link::tests::validate_link ... ok

failures:

---- db::tests::test_database_connection stdout ----

thread 'db::tests::test_database_connection' panicked at src/db.rs:30:14:
Failed to create database pool: PoolTimedOut
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    db::tests::test_database_c

See the full battle logs here: View Logs

Time to rethink your next move!

@reddevilmidzy reddevilmidzy requested a review from Copilot May 27, 2025 14:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR sets up a PostgreSQL-backed database using SQLx migrations and integrates connection pooling into the Axum application.

  • Introduce a db module with create_pool and init_db functions and a basic connectivity test
  • Update main.rs to load environment variables, create the pool, run migrations, and pass the pool into the router state
  • Add initial SQL migration, required dependencies (sqlx, dotenv), a .env file, and configure GitHub Actions to spin up Postgres for tests

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rook/src/main.rs Load DATABASE_URL, create SQLx pool, run migrations, and pass pool via with_state
rook/src/lib.rs Expose new db module in crate root
rook/src/db.rs Implement create_pool, init_db, and a connectivity test
rook/migrations/202450527173623_initial.sql Define subscribers table schema
rook/Cargo.toml Add sqlx and dotenv dependencies
rook/.env Provide local DATABASE_URL (committed)
.github/workflows/rust.yml Add Postgres service and set DATABASE_URL for CI tests
Comments suppressed due to low confidence (2)

rook/src/db.rs:13

  • The init_db function isn’t covered by existing tests. Add a test that calls init_db and verifies that the subscribers table exists after migrations run.
pub async fn init_db(pool: &PgPool) -> Result<(), sqlx::Error> {

rook/.env:1

  • Committing a .env file with real database credentials can expose sensitive information. Consider removing it from version control, adding .env to .gitignore, and including a .env.example instead.
DATABASE_URL=postgres://postgres:password@localhost:5432/queensac

@reddevilmidzy
Copy link
Owner Author

코파일럿 아깐 별말 없더니 이제는 좀 치네

@reddevilmidzy
Copy link
Owner Author

아 add suggenstion to batch 누르면 코파일럿 리뷰 한번에 커밋 날릴 수 있구나,,, 몰랐네

@github-actions
Copy link

?? Blunder 😵‍💫
Your CI made a critical mistake on the board.

❌ Failure Details
---- src/db.rs - db::create_pool (line 28) stdout ----
�[0m�[1m�[38;5;9merror[E0433]�[0m�[0m�[1m: failed to resolve: use of unresolved module or unlinked crate `your_crate_name`�[0m
�[0m �[0m�[0m�[1m�[38;5;12m--> �[0m�[0msrc/db.rs:29:5�[0m
�[0m  �[0m�[0m�[1m�[38;5;12m|�[0m
�[0m�[1m�[38;5;12m3�[0m�[0m �[0m�[0m�[1m�[38;5;12m|�[0m�[0m �[0m�[0muse your_crate_name::db::create_pool;�[0m
�[0m  �[0m�[0m�[1m�[38;5;12m|�[0m�[0m     �[0m�[0m�[1m�[38;5;9m^^^^^^^^^^^^^^^�[0m�[0m �[0m�[0m�[1m�[38;5;9muse of u

See the full battle logs here: View Logs

Time to rethink your next move!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@reddevilmidzy
Copy link
Owner Author

꺄오 성공이다

@reddevilmidzy reddevilmidzy merged commit 333fbee into main May 27, 2025
2 checks passed
@reddevilmidzy reddevilmidzy deleted the db branch May 27, 2025 14:22
@reddevilmidzy
Copy link
Owner Author

참고로 현재 배포를 위해 사용하고 있는 shuttle 에서도 db 설정에 관한 구현을 제공한다 참고

하지만 이걸 사용하지 않은 이유는 몇주 사용해보았는데, 계속해서 shuttle을 사용하기엔 너무 작은 것 같다. 좀만 돌리면 곰방 뻗어버리는데 물론 이건 요금제 때문이기는 하다. 하지만 돈내고 사용할거면 AWS를 사용하여 더 커스터마이징 할 수 있는 서버리스 서비스를 사용하는게 좋아보인다. shuttle은 서버 한대를 빌린다기보단 그냥 프로젝트 실행시킬 프로세스 하나를 빌리는 느낌이다. 그래서 서버에 접속하여 설정하는 것이 불가능하다.

언젠간 shuttle을 걷어낼 거라 shuttle을 사용하여 db를 구축하진 않았다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DB 구축

2 participants