-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add Flyway for database schema management (#543) #626
Conversation
WalkthroughThe changes introduced in this pull request primarily enhance the Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant LocalDB as Local Database
participant Flyway as Flyway Migration Tool
Developer->>LocalDB: Configure local profile
Developer->>Flyway: Run migrations
Flyway->>LocalDB: Create table `the_entity`
Flyway->>LocalDB: Insert test data into `the_entity`
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 3
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (3)
refarch-backend/pom.xml
(2 hunks)refarch-backend/src/main/resources/application-local.yml
(0 hunks)refarch-backend/src/main/resources/db/migration/V001__TheEntity_schema.sql
(1 hunks)
💤 Files with no reviewable changes (1)
- refarch-backend/src/main/resources/application-local.yml
🔇 Additional comments (4)
refarch-backend/src/main/resources/db/migration/V001__TheEntity_schema.sql (2)
1-5
: 🧹 Nitpick (assertive)
Add an index for the primary key
While PostgreSQL automatically creates an index for the primary key constraint, it's a good practice to explicitly create it for better maintainability and documentation.
create table the_entity (
text_attribute varchar(8) not null,
id uuid not null,
primary key (id)
-);
+);
+create index idx_the_entity_id on the_entity(id);
Likely invalid or redundant comment.
2-2
: Verify the varchar length restriction
The varchar(8)
limit seems quite restrictive. Please verify if 8 characters will be sufficient for all use cases.
✅ Verification successful
Let me try a different approach to search for any usage or constraints of this field.
Let me search for the entity class and DTO to understand the complete usage pattern.
The varchar length of 8 is appropriate and validated
The length restriction of 8 characters for text_attribute
is intentionally set and properly validated:
- The entity class has
@Size(min = 2, max = 8)
validation constraint - The field is used in tests with Unicode characters ("Ä-é"), showing it can handle special characters within this length
- The column definition matches the validation constraints in the entity class
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any Entity classes or DTOs that might use this field
# to verify the expected length requirements
ast-grep --pattern 'class $_ {
$$$
@$$$
private String text$_;
$$$
}'
Length of output: 79
Script:
#!/bin/bash
# Search for files containing "text_attribute" to understand its usage
rg -i "text_attribute" -A 5 -B 5
# Also search for any SQL files that might reference this column
fd -e sql -x cat {} \; | rg -i "text_attribute" -A 5 -B 5
Length of output: 6127
Script:
#!/bin/bash
# Search for TheEntity class and DTO
fd -e java -x cat {} \; | rg -i "class TheEntity" -A 10 -B 2
# Also search for any validation annotations on the text attribute
ast-grep --pattern '@$_($$$)
private String textAttribute;'
Length of output: 2632
refarch-backend/pom.xml (2)
153-160
: LGTM! Dependencies are correctly configured
The Flyway dependencies are properly added and will inherit versions from the Spring Boot parent, which is the recommended approach.
468-468
: 🧹 Nitpick (assertive)
Review the clean operation configuration
The cleanDisabled
property is set to false, which allows the database to be cleaned. While this might be acceptable for local development, it could be dangerous if accidentally used in other environments.
Consider adding a warning in the configuration comment about the risks of the clean operation, or implementing additional safeguards such as environment checks.
refarch-backend/src/main/resources/db/migration/V001__TheEntity_schema.sql
Outdated
Show resolved
Hide resolved
refarch-backend/src/main/resources/db/migration/V001__TheEntity_schema.sql
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 6
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (4)
refarch-backend/src/main/resources/application-local.yml
(2 hunks)refarch-backend/src/main/resources/application.yml
(1 hunks)refarch-backend/src/main/resources/db/migration/schema/V001__TheEntity_schema.sql
(1 hunks)refarch-backend/src/main/resources/db/migration/testdata/R__Testdata.sql
(1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
refarch-backend/src/main/resources/application-local.yml
[error] 20-20: wrong indentation: expected 6 but found 4
(indentation)
🔇 Additional comments (2)
refarch-backend/src/main/resources/application.yml (1)
4-6
: Verify migration scripts organization.
The configuration shows only schema migrations. Let's verify if the migration scripts are properly organized.
✅ Verification successful
Let me check the content of the migration files to ensure proper organization and separation of concerns.
Migration scripts are properly organized and follow best practices
The migration scripts are well-organized with clear separation of concerns:
- Schema migrations (
V001__TheEntity_schema.sql
) contain only DDL statements and follow versioned naming convention - Test data is properly isolated in a separate repeatable migration (
R__Testdata.sql
) under the testdata directory - No data manipulation statements are mixed within schema migrations
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check the organization of Flyway migration scripts
# Check if migration files follow the naming convention and are properly separated
echo "Checking migration files structure..."
find . -path "*/db/migration/*" -type f -name "*.sql" | while read -r file; do
echo "Found migration: $file"
# Check if it's a schema or data migration based on naming convention
if [[ $file =~ V[0-9]+__.*\.sql ]]; then
echo " ✓ Valid version-based migration"
else
echo " ✗ Invalid migration filename format"
fi
done
# Look for potential data migrations mixed with schema migrations
echo -e "\nChecking for data/schema separation..."
find . -path "*/db/migration/schema/*.sql" -type f -exec grep -l "INSERT INTO\|UPDATE\|DELETE FROM" {} \;
Length of output: 1170
Script:
#!/bin/bash
# Check content of migration files
echo "=== Schema Migration Content ==="
cat ./refarch-backend/src/main/resources/db/migration/schema/V001__TheEntity_schema.sql
echo -e "\n=== Test Data Migration Content ==="
cat ./refarch-backend/src/main/resources/db/migration/testdata/R__Testdata.sql
Length of output: 773
refarch-backend/src/main/resources/application-local.yml (1)
7-8
: LGTM! Appropriate Hibernate configuration for Flyway integration
Setting ddl-auto: validate
is the correct approach when using Flyway for schema management. This ensures Hibernate only validates the schema against the entity mappings without attempting to modify it.
refarch-backend/src/main/resources/db/migration/schema/V001__TheEntity_schema.sql
Show resolved
Hide resolved
refarch-backend/src/main/resources/db/migration/testdata/R__Testdata.sql
Show resolved
Hide resolved
refarch-backend/src/main/resources/db/migration/testdata/R__Testdata.sql
Show resolved
Hide resolved
…(e.g. IDE integration, profiles in users settings.xml
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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (1)
refarch-backend/pom.xml
(2 hunks)
🔇 Additional comments (2)
refarch-backend/pom.xml (2)
152-160
: LGTM! Dependencies are correctly configured.
The Flyway dependencies are properly configured and inherit versions from the Spring Boot parent POM, which is a good practice for version management.
451-455
: 🧹 Nitpick (assertive)
Consider removing profile binding for better IDE integration.
As discussed in the previous review comments, binding the Flyway plugin to a profile might make it harder to use via IDE's Maven integration. Since the plugin is used manually, consider making it available without profile activation.
refarch-backend/src/main/resources/db/migration/testdata/R__Testdata.sql
Show resolved
Hide resolved
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.
Actionable comments posted: 3
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (1)
refarch-backend/pom.xml
(2 hunks)
🔇 Additional comments (2)
refarch-backend/pom.xml (2)
152-160
: LGTM: Flyway dependencies are properly configured.
The required Flyway dependencies for PostgreSQL integration are correctly added and their versions are managed by the Spring Boot parent.
456-456
: 🧹 Nitpick (assertive)
Consider using a dedicated database name.
Using the default 'postgres' database is not recommended. Consider using a dedicated database name for the application.
- <url>jdbc:postgresql://localhost:5432/postgres</url>
+ <url>jdbc:postgresql://localhost:5432/refarch_local</url>
Likely invalid or redundant comment.
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.
LGTM
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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (1)
refarch-backend/src/main/resources/application-local.yml
(1 hunks)
🔇 Additional comments (2)
refarch-backend/src/main/resources/application-local.yml (2)
Line range hint 11-13
: Consider using environment variables for database credentials
For better security practices, consider externalizing the database credentials using environment variables, even in the local profile.
datasource:
url: jdbc:postgresql://localhost:5432/postgres
- password: admin
- username: admin
+ password: ${DB_PASSWORD:admin}
+ username: ${DB_USERNAME:admin}
Line range hint 4-8
: Verify Hibernate validation mode in main configuration
Based on previous discussions, the ddl-auto: validate
setting should be moved to the main application.yml
. Let's verify this configuration:
✅ Verification successful
Hibernate validation mode is correctly configured
The ddl-auto: validate
setting is properly configured in the main application.yml
file, which is the recommended location for this production-critical configuration.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if Hibernate validation mode exists in the main application.yml
rg "ddl-auto.*validate" "refarch-backend/src/main/resources/application.yml"
# Also check for any remaining ddl-auto configurations
rg "ddl-auto" "refarch-backend/src/main/**/*.yml"
Length of output: 225
Script:
#!/bin/bash
# Let's try searching with correct path patterns
rg "ddl-auto" "refarch-backend/src/main/resources/"
Length of output: 125
Description
Adds flyway for db schema management. Hibernate's ddl-auto feature removed (as this is flyways job now).
Added a Maven
local
profile to manage the local PostgresDB from stack via Flyway Maven plugin (e.g. to do a clean ->mvn flyway:clean -Plocal
)Reference
Issues #543
Summary by CodeRabbit
New Features
the_entity
with defined attributes.the_entity
table.Bug Fixes
Documentation
application.yml
andapplication-local.yml
.