forked from gothinkster/spring-boot-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 12
Replace SQLite with PostgreSQL for production, add Testcontainers for tests #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
2
commits into
master
Choose a base branch
from
devin/1770752952-replace-sqlite-with-postgresql
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| postgresql: | ||
| image: postgres:14-alpine | ||
| environment: | ||
| POSTGRES_DB: realworld | ||
| POSTGRES_USER: realworld | ||
| POSTGRES_PASSWORD: realworld | ||
| ports: | ||
| - "5432:5432" | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data | ||
|
|
||
| app: | ||
| build: . | ||
| ports: | ||
| - "8080:8080" | ||
| environment: | ||
| SPRING_PROFILES_ACTIVE: prod | ||
| DATABASE_URL: jdbc:postgresql://postgresql:5432/realworld | ||
| DATABASE_USERNAME: realworld | ||
| DATABASE_PASSWORD: realworld | ||
| depends_on: | ||
| - postgresql | ||
|
|
||
| volumes: | ||
| postgres_data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| spring.datasource.url=jdbc:sqlite:dev.db | ||
| spring.datasource.driver-class-name=org.sqlite.JDBC | ||
| spring.datasource.username= | ||
| spring.datasource.password= | ||
|
|
||
| spring.flyway.locations=classpath:db/migration/sqlite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| spring.datasource.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/realworld} | ||
| spring.datasource.driver-class-name=org.postgresql.Driver | ||
| spring.datasource.username=${DATABASE_USERNAME:realworld} | ||
| spring.datasource.password=${DATABASE_PASSWORD:realworld} | ||
|
|
||
| spring.flyway.locations=classpath:db/migration/postgresql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,6 @@ | ||
| spring.datasource.url=jdbc:sqlite::memory: | ||
| spring.datasource.url=jdbc:tc:postgresql:14-alpine:///realworld_test | ||
| spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver | ||
| spring.datasource.username=test | ||
| spring.datasource.password=test | ||
|
|
||
| spring.flyway.locations=classpath:db/migration/postgresql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/resources/db/migration/postgresql/V1__create_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| CREATE TABLE users ( | ||
| id VARCHAR(255) PRIMARY KEY, | ||
| username VARCHAR(255) UNIQUE, | ||
| password VARCHAR(255), | ||
| email VARCHAR(255) UNIQUE, | ||
| bio TEXT, | ||
| image VARCHAR(511) | ||
| ); | ||
|
|
||
| CREATE TABLE articles ( | ||
| id VARCHAR(255) PRIMARY KEY, | ||
| user_id VARCHAR(255), | ||
| slug VARCHAR(255) UNIQUE, | ||
| title VARCHAR(255), | ||
| description TEXT, | ||
| body TEXT, | ||
| created_at TIMESTAMP NOT NULL, | ||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
|
|
||
| CREATE TABLE article_favorites ( | ||
| article_id VARCHAR(255) NOT NULL, | ||
| user_id VARCHAR(255) NOT NULL, | ||
| PRIMARY KEY(article_id, user_id) | ||
| ); | ||
|
|
||
| CREATE TABLE follows ( | ||
| user_id VARCHAR(255) NOT NULL, | ||
| follow_id VARCHAR(255) NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE tags ( | ||
| id VARCHAR(255) PRIMARY KEY, | ||
| name VARCHAR(255) NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE article_tags ( | ||
| article_id VARCHAR(255) NOT NULL, | ||
| tag_id VARCHAR(255) NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE comments ( | ||
| id VARCHAR(255) PRIMARY KEY, | ||
| body TEXT, | ||
| article_id VARCHAR(255), | ||
| user_id VARCHAR(255), | ||
| created_at TIMESTAMP NOT NULL, | ||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| ); |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴
countArticlequery still uses reserved keywordATas table alias, breaking PostgreSQLThe
countArticlequery inArticleReadService.xmlat lines 68-69 still usesATas the alias forarticle_tags. While the PR renamedAT→ATAGin theselectArticleDataandselectArticleIdsSQL fragments, thecountArticlequery has its own inline join that was missed.Root Cause and Impact
ATis a reserved keyword in PostgreSQL. The other queries in this file were correctly updated to useATAG(lines 23, 24, 32, 33), but thecountArticlequery at lines 68-69 was overlooked:This query is used to count the total number of articles matching filter criteria (by tag, author, or favorited-by). When running against PostgreSQL (both
prodandtestprofiles), this query will fail with a syntax error becauseATis 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.