Replace SQLite with PostgreSQL for production, add Testcontainers for tests#348
Replace SQLite with PostgreSQL for production, add Testcontainers for tests#348devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
Conversation
… tests - Add PostgreSQL driver and Testcontainers dependencies to build.gradle - Create Spring profiles: dev (SQLite), prod (PostgreSQL), test (Testcontainers+PostgreSQL) - Add vendor-specific Flyway migrations for SQLite and PostgreSQL - Fix MyBatis LIMIT syntax for cross-database compatibility - Rename reserved keyword alias AT to ATAG in mapper XMLs - Add SQL cleanup to test base classes for data isolation - Add docker-compose.yml with PostgreSQL service Co-Authored-By: Doris Tian <doristian23@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…ories Co-Authored-By: Doris Tian <doristian23@gmail.com>
There was a problem hiding this comment.
🔴 countArticle query still uses reserved keyword AT as table alias, breaking PostgreSQL
The countArticle query in ArticleReadService.xml at lines 68-69 still uses AT as the alias for article_tags. While the PR renamed AT → ATAG in the selectArticleData and selectArticleIds SQL fragments, the countArticle query has its own inline join that was missed.
Root Cause and Impact
AT is a reserved keyword in PostgreSQL. The other queries in this file were correctly updated to use ATAG (lines 23, 24, 32, 33), but the countArticle query at lines 68-69 was overlooked:
left join article_tags AT on A.id = AT.article_id
left join tags T on T.id = AT.tag_idThis query is used to count the total number of articles matching filter criteria (by tag, author, or favorited-by). When running against PostgreSQL (both prod and test profiles), this query will fail with a syntax error because AT is a reserved keyword.
Impact: The article listing/filtering endpoints that call countArticle (to return total counts for pagination) will throw SQL exceptions on PostgreSQL, making pagination broken in production and tests.
(Refers to lines 68-69)
Was this helpful? React with 👍 or 👎 to provide feedback.
Replace SQLite with PostgreSQL for production, add Testcontainers for tests
Summary
Introduces Spring profiles to support multiple database backends:
devprofile (default): SQLite via file-baseddev.db— preserves existing local development experienceprodprofile: PostgreSQL with externalized config via environment variablestestprofile: Testcontainers spins up a disposable PostgreSQL 14 container per test runKey changes:
application.propertiesinto profile-specific files (application-dev.properties,application-prod.properties,application-test.properties)db/migration/sqlite/,db/migration/postgresql/)LIMIT x,y→LIMIT y OFFSET x, and table aliasATrenamed toATAG(reserved keyword in PostgreSQL)@Sqlcleanup added toDbTestBaseandArticleRepositoryTransactionTestfor test data isolation across shared Testcontainers instancedocker-compose.ymladded for running the app with PostgreSQL locallyReview & Testing Checklist for Human
db/migration/V1__create_tables.sqlwas NOT deleted. If no profile is active orspring.flyway.locationsis unset, Flyway could pick up both the old and new migrations. Verify whether this file should be removed or if the profile-basedspring.flyway.locationsalways takes precedence."123","456"). Decide if this is acceptable for production or if a follow-upV2__add_foreign_keys.sqlmigration is needed.gradle.yml) was not modified.ubuntu-latestincludes Docker, but confirm tests pass in CI and don't time out waiting for container startup.docker-compose.ymlreferencesbuild: .— ensure the existingDockerfileworks with the newSPRING_PROFILES_ACTIVE=prodenvironment variable.devprofile (./gradlew bootRun) to confirm SQLite still works as expected for local development.Notes