Skip to content

Commit

Permalink
Grant permission to roles to create table on public schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Sfurti-yb committed Feb 6, 2025
1 parent 29db96c commit b1647c8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/yugabyte/sample/apps/AppBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ protected Connection getPostgresConnection(String database, String username, Str
String connectStr = String.format("%s//%s:%d/%s", url, contactPoint.getHost(),
contactPoint.getPort(),
database);
if (!username.equalsIgnoreCase("yugabyte") || !username.equalsIgnoreCase("postgres")){
Properties newProps = new Properties();
newProps.setProperty("user", "yugabyte");
Connection controlConnection = DriverManager.getConnection(connectStr, newProps);
Statement st = controlConnection.createStatement();
String grantPermission = String.format("grant create on schema public to %s with grant option;", username);
st.execute(grantPermission);
controlConnection.close();
}
Connection connection = DriverManager.getConnection(connectStr, props);
return connection;
} catch (Exception e) {
Expand Down

0 comments on commit b1647c8

Please sign in to comment.