Skip to content
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

[Bug] Fix TriggerRelationMapper cannot work due to miss DatabaseIdProvider #15153

Merged
merged 7 commits into from
Nov 17, 2023

Conversation

mind-echo
Copy link
Contributor

@mind-echo mind-echo commented Nov 10, 2023

fix #15152 : When using PostgreSQL, MyBatis did not set databaseId correctly, causing the workflow to fail to start

Purpose of the pull request

fix bug #15152

Brief change log

  1. add bean of VendorDatabaseIdProvider
  2. change org.apache.dolphinscheduler.dao.mapper.TriggerRelationMapper#upsert.databaseId from pg to PostgreSQL

Verify this pull request

Copy link
Member

@fuchanghai fuchanghai left a comment

Choose a reason for hiding this comment

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

LGTM
BTW, do we need to do some mapping ? as following :

@Bean
public DatabaseIdProvider databaseIdProvider() {
    VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
    Properties properties = new Properties();
    properties.put("Oracle","oracle");
    properties.put("MySQL","mysql");
    properties.put("PostgreSQL","pg");
    databaseIdProvider.setProperties(properties);
    return databaseIdProvider;
}

cc @EricGao888

@mind-echo
Copy link
Contributor Author

LGTM BTW, do we need to do some mapping ? as following :

@Bean
public DatabaseIdProvider databaseIdProvider() {
    VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
    Properties properties = new Properties();
    properties.put("Oracle","oracle");
    properties.put("MySQL","mysql");
    properties.put("PostgreSQL","pg");
    databaseIdProvider.setProperties(properties);
    return databaseIdProvider;
}

cc @EricGao888

Thank you for your review. I have made changes to the current code

@fuchanghai
Copy link
Member

hi @destroydestiny Is it possible to write an enumeration class to reduce the magic value?

@mind-echo
Copy link
Contributor Author

hi @destroydestiny Is it possible to write an enumeration class to reduce the magic value?

I added an enum, but I'm not sure if I added it in the right package

public enum DatabaseId {

H2("H2", "h2"),
ORACLE("Oracle", "oracle"),
Copy link
Member

Choose a reason for hiding this comment

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

We do not support oracle database as meta database.

@SbloodyS SbloodyS added bug Something isn't working 3.2.1 labels Nov 14, 2023
@SbloodyS SbloodyS added this to the 3.2.1 milestone Nov 14, 2023
@SbloodyS SbloodyS added the first time contributor First-time contributor label Nov 14, 2023
Comment on lines 28 to 36
public enum DatabaseId {

H2("H2", "h2"),
MYSQL("MySQL", "mysql"),
POSTGRESQL("PostgreSQL", "pg");

private final String productName;
private final String databaseId;
}
Copy link
Member

Choose a reason for hiding this comment

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

ruanwenjun
ruanwenjun previously approved these changes Nov 16, 2023
Copy link
Member

@ruanwenjun ruanwenjun left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -61,6 +63,11 @@ public MybatisPlusInterceptor paginationInterceptor(DbType dbType) {
return interceptor;
}

@Bean
public DatabaseIdProvider databaseIdProvider() {
return new FixedDatabaseIdProvider(daoPluginConfiguration.databaseId());
Copy link
Member

Choose a reason for hiding this comment

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

Can we directly use daoPluginConfiguration.dbType().name() as databaseId?
I find the databaseId only exist in TriggerRelationMapper.xml if we modify the name to POSTGRE_SQL this should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's what I thought at first, use DatabaseProductName as databaseId. view commit 19d8510

Copy link
Member

@ruanwenjun ruanwenjun Nov 17, 2023

Choose a reason for hiding this comment

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

If so, we can remove databaseId, and use the default VendorDatabaseIdProvider without add properties after change the datasourceId to PostgreSQL in mapper? .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup

Copy link
Member

Choose a reason for hiding this comment

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

Please remove databaseId in DaoPlugin, and use this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I close this PR and recreate it? Too many commits are not clean enough

Copy link
Member

@ruanwenjun ruanwenjun Nov 17, 2023

Choose a reason for hiding this comment

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

You can rebase the commit, and I will use squash merge to edit the commit message when merged. So this is not a problem, don't worry.

Copy link
Member

@ruanwenjun ruanwenjun left a comment

Choose a reason for hiding this comment

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

LGTM

@ruanwenjun ruanwenjun changed the title fix bug 15152: When using PostgreSQL, MyBatis did not set databaseId … [Bug] Fix TriggerRelationMapper cannot work due to miss DatabaseIdProvider Nov 17, 2023
Copy link
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

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

+1

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d6175f3) 38.23% compared to head (571cebf) 38.23%.

❗ Current head 571cebf differs from pull request most recent head 4ee2941. Consider uploading reports for the commit 4ee2941 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##                dev   #15153      +/-   ##
============================================
- Coverage     38.23%   38.23%   -0.01%     
  Complexity     4695     4695              
============================================
  Files          1285     1285              
  Lines         45453    45454       +1     
  Branches       4951     4951              
============================================
  Hits          17381    17381              
  Misses        26181    26181              
- Partials       1891     1892       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented Nov 17, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

@ruanwenjun ruanwenjun merged commit 36f7205 into apache:dev Nov 17, 2023
52 of 53 checks passed
@ruanwenjun
Copy link
Member

Merged, thanks for you pr. BTW, we don't only exist UT under h2, are you interesting add test for PG @destroydestiny

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.2.1 backend bug Something isn't working first time contributor First-time contributor ready-to-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] [API] using docker-compose to start server. unable to run workflow
5 participants