-
-
Notifications
You must be signed in to change notification settings - Fork 217
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 MySQL #320
Add MySQL #320
Conversation
Add support for MySQL database Fix jhipster#231
Codecov Report
@@ Coverage Diff @@
## main #320 +/- ##
============================================
Coverage 100.00% 100.00%
- Complexity 463 493 +30
============================================
Files 80 85 +5
Lines 1479 1593 +114
Branches 32 32
============================================
+ Hits 1479 1593 +114
Continue to review full report at Codecov.
|
Wow, thanks @swarajsaaj ! |
result.put("spring.datasource.url", "jdbc:mysql://localhost:3306/" + baseName); | ||
result.put("spring.datasource.username", "root"); | ||
result.put("spring.datasource.password", ""); | ||
result.put("spring.datasource.driver-class-name", "com.mysql.jdbc.Driver"); |
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.
I don't think we need this
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.
agreed, these properties are not needed. Removed
result.put("spring.datasource.hikari.auto-commit", false); | ||
|
||
result.put("spring.data.jpa.repositories.bootstrap-mode", "deferred"); | ||
result.put("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect"); |
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.
same, I don't think we need this. What I can suggest, is to generate a JHipster project with MySQL and check all properties in application-prod.yml
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.
agreed, these properties are not needed. Removed
public class MySQL { | ||
|
||
public static final String TESTCONTAINERS_VERSION = "1.16.0"; | ||
|
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.
just an idea, maybe we can add: DOCKER_MYSQL_VERSION = "mysql:8.0.27"
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.
yes sure, I think constant name could be DOCKER_IMAGE_NAME instead?
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.
yes it's ok :)
private Map<String, Object> springPropertiesForTest(String baseName) { | ||
TreeMap<String, Object> result = new TreeMap<>(); | ||
result.put("spring.datasource.driver-class-name", "org.testcontainers.jdbc.ContainerDatabaseDriver"); | ||
result.put("spring.datasource.url", "jdbc:tc:mysql:8.0.27:///" + baseName); |
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.
we could use MySQL.getDockerMysqlVersion(), following my comment above
version: '3.8' | ||
services: | ||
mysql: | ||
image: mysql:8.0.27 |
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.
we could use {{dockerMysqlVersion}}, injected by DOCKER_MYSQL_VERSION value
|
||
@Override | ||
public void addDockerCompose(Project project) { | ||
project.addDefaultConfig(BASE_NAME); |
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.
we could add something like:
project.addConfig("dockerMysqlVersion", MySQL.getDockerMysqlVersion());
|
||
public static String getTestcontainersVersion() { | ||
return TESTCONTAINERS_VERSION; | ||
} |
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.
with new method getDockerMysqlVersion()
assertFileContent( | ||
project, | ||
getPath(TEST_RESOURCES, "config/application.properties"), | ||
List.of("spring.datasource.url=jdbc:tc:mysql:8.0.27:///chips", "spring.datasource.username=chips") |
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.
use MySQL.getDockerMysqlVersion()
By reviewing this PR, I need to improve the code in PostgreSQL too :) |
Don't forget to claim your bounty @swarajsaaj |
I claim the bounty :) https://opencollective.com/generator-jhipster/expenses/58753 |
@swarajsaaj : approved! |
Add support for MySQL database
Fix #231
I have replicated the postgresql style here without extracting common functionalities to avoid making a complicated if-else ladder in future.