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

configure dedicated db user for database migrations: DML-only user fo… #29649

Closed
wants to merge 1 commit into from
Closed

configure dedicated db user for database migrations: DML-only user fo… #29649

wants to merge 1 commit into from

Conversation

mfpc
Copy link
Contributor

@mfpc mfpc commented Dec 2, 2022

…r datasource, but DDL user for migration #24639

@quarkus-bot
Copy link

quarkus-bot bot commented Dec 2, 2022

Thanks for your pull request!

The title of your pull request does not follow our editorial rules. Could you have a look?

  • title should not end up with ellipsis (make sure the title is complete)
  • title should preferably start with an uppercase character (if it makes sense!)

This message is automatically generated by a bot.

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

Added some comments. The implementation looks good.


public Connection getConnection(String username, String password)
throws SQLException {
// TODO Auto-generated method stub
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these comments


if (flywayRuntimeConfig.username.isPresent() && flywayRuntimeConfig.password.isPresent()) {
configure.dataSource(
new DataSourceDecorator(dataSource, flywayRuntimeConfig.username, flywayRuntimeConfig.password));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can invoke get() here and avoid using Optional in the class constructor

Copy link
Member

Choose a reason for hiding this comment

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

I don't undertstand the usage of this pattern. I gave you good hints on how you can deal with this in your previous PR with some pseudo code that should allow you to do what you want and some advice on how to deal with the JDBC URL.
Not sure why you went another way? There might be a very good reason so don't hesitate to speak up.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gsmet Before I read your comments on the previous PR, I suggested @mfpc to use this pattern. The idea was to reuse the DataSource configuration and call DataSource#getConnection(String user, String password) when DataSource#getConnection() is called in the Flyway codebase.

But now I see that your suggestion seems nicer, so 👍🏻 to that


import javax.sql.DataSource;

public class DataSourceDecorator implements DataSource {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name doesn't really explain what this class does, but I am not very good at naming, so I'll let others decide about it

var = rs.getInt(1);
}
}
assertEquals(100, var, "Different username and password was not executed");
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't really verify the feature you provided

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test if the connection is working with new configs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change the message for "Database connected with new config", its ok?

Copy link
Member

Choose a reason for hiding this comment

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

I think you should rather get the datasource and check the user there. In your previous PR, I outlined how you could get the datasource URL. I'm pretty sure you can get the user from there too.

return dataSource.isWrapperFor(arg0);
}

public <T> T unwrap(Class<T> arg0) throws SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace arg0 parameters with the name used in the sources

@@ -43,6 +43,26 @@ public static FlywayDataSourceRuntimeConfig defaultConfig() {
@ConfigItem
public Optional<String> defaultSchema = Optional.empty();

/**
* This is a safety measurement against theoretical situations where the application goes haywire for any reason.
* This includes e.g. accidentally setting quarkus.hibernate-orm.database.generation to drop-and-create.
Copy link
Contributor

Choose a reason for hiding this comment

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

This description looks misleading and confusing


/**
* Set the password for connection;
* quarkus.flyway.password=my_secret_password
Copy link
Contributor

Choose a reason for hiding this comment

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

This line can be removed

* This includes e.g. accidentally setting quarkus.hibernate-orm.database.generation to drop-and-create.
* If the application runs with a restricted database user, damage in such situations can be mitigated.
* # Name of a custom database user for flyway to use. Must have DDL rights
* quarkus.flyway.username=my_schema_owner
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed

@gastaldi
Copy link
Contributor

gastaldi commented Dec 2, 2022

For the record, there are some worthy comments in the previous PR: #29628

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Not completely sold by this new approach and I would like more details about why you changed your approach.
Have you seen my comments in your previous PR?

var = rs.getInt(1);
}
}
assertEquals(100, var, "Different username and password was not executed");
Copy link
Member

Choose a reason for hiding this comment

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

I think you should rather get the datasource and check the user there. In your previous PR, I outlined how you could get the datasource URL. I'm pretty sure you can get the user from there too.


if (flywayRuntimeConfig.username.isPresent() && flywayRuntimeConfig.password.isPresent()) {
configure.dataSource(
new DataSourceDecorator(dataSource, flywayRuntimeConfig.username, flywayRuntimeConfig.password));
Copy link
Member

Choose a reason for hiding this comment

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

I don't undertstand the usage of this pattern. I gave you good hints on how you can deal with this in your previous PR with some pseudo code that should allow you to do what you want and some advice on how to deal with the JDBC URL.
Not sure why you went another way? There might be a very good reason so don't hesitate to speak up.

@mfpc mfpc closed this by deleting the head repository Dec 6, 2022
@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Dec 6, 2022
@geoand
Copy link
Contributor

geoand commented Dec 7, 2022

#29704 seems to be a follow up to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flyway triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants