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

Configurable table names (SQL) #941

Closed
strerene opened this issue Feb 24, 2020 · 8 comments
Closed

Configurable table names (SQL) #941

strerene opened this issue Feb 24, 2020 · 8 comments
Labels

Comments

@strerene
Copy link

Currently there is no way to change the default table names.

  • jv_global_id
  • jv_commit
  • jv_commit_property
  • jv_snapshot

Providing a way of customizing these would be very nice.

@bartoszwalacik bartoszwalacik added contribution wanted this feature is wanted but won't be implemented by core team due to limited resources good first issue new feature labels Feb 24, 2020
@shirishpandharikar
Copy link
Contributor

@bartoszwalacik I'm planning to work on this feature. Was thinking of providing a TableConfiguration class with a TableConfigurationBuilder where we can set the table names. We can then set this to the SqlRepositoryConfiguration via the SqlReposirotyBuilder. Another approach is to directly add these table names to the SqlRepositoryConfiguration but the constructor would be bloated.

TableConfiguration tableConf = TableConfigurationBuilder.tableConfiguration()
.withGlobalIdTableName("jav_global_id")
.withCommitTableName("jav_commit")
.withSnapshotTableName("jav_snapshot")
.withCommitPropertyTableName("jav_commit_property")
.build();

SqlRepositoryBuilder.sqlRepository().
withConnectionProvider(new ConnectionProvider() {
         public Connection getConnection() throws SQLException {
             return DriverManager.getConnection("jdbc:h2:mem:test;");
          }
}).
withDialect(DialectName.H2).
withTableConfiguration(tableConf).
build();

There will be a change in the TableNameProvider class to support this. Could you please let me know your thoughts on both the approaches? If this looks the right direction I will work on this and submit a PR. Will also look into the Mongodb module to support similar requirement.

@bartoszwalacik
Copy link
Member

bartoszwalacik commented Jul 5, 2020

I think that nesting builders would be too complex, so:

SqlRepositoryBuilder.sqlRepository().
withConnectionProvider(new ConnectionProvider() {
         public Connection getConnection() throws SQLException {
             return DriverManager.getConnection("jdbc:h2:mem:test;");
          }
}).
.withDialect(DialectName.H2)
.withGlobalIdTableName("jav_global_id")
.withCommitTableName("jav_commit")
.withSnapshotTableName("jav_snapshot")
.withCommitPropertyTableName("jav_commit_property")
build();

and then, these 4 new fields are stored in SqlRepositoryConfiguration :

public class SqlRepositoryConfiguration {
    private final boolean globalIdCacheDisabled;
    private final String schemaName;
    private final boolean schemaManagementEnabled;
    private final String globalIdTableName;
...

@shirishpandharikar
Copy link
Contributor

Sounds good. I will start making the changes. One thing I observed in the FixedSchemaFactory class is that the foreign key names and the constraint names are generated using the table names while the primary key names just append jv_. Also, the sequence names append jv_.

@bartoszwalacik
Copy link
Member

Well, i guess the key names and sequence names should also be changed to reflect given table names.

@shirishpandharikar
Copy link
Contributor

@bartoszwalacik I've made the required changes and submitted a PR. Please have a look at let me know your thoughts and comments.

@bartoszwalacik
Copy link
Member

bartoszwalacik commented Jul 14, 2020

yes, i know, i will merge till friday

bartoszwalacik added a commit that referenced this issue Jul 15, 2020
bartoszwalacik added a commit that referenced this issue Jul 15, 2020
bartoszwalacik added a commit that referenced this issue Jul 15, 2020
bartoszwalacik added a commit that referenced this issue Jul 16, 2020
bartoszwalacik added a commit that referenced this issue Jul 16, 2020
bartoszwalacik added a commit that referenced this issue Jul 16, 2020
bartoszwalacik added a commit that referenced this issue Jul 16, 2020
@bartoszwalacik
Copy link
Member

new props added in SqlRepository and in the starter:

  sqlGlobalIdTableName: 'cust_jv_global_id'
  sqlCommitTableName: 'cust_jv_commit'
  sqlSnapshotTableName: 'cust_jv_snapshot'
  sqlCommitPropertyTableName: 'cust_jv_commit_property'

@bartoszwalacik bartoszwalacik added fixed - waiting to be released and removed contribution wanted this feature is wanted but won't be implemented by core team due to limited resources good first issue new feature labels Jul 16, 2020
@bartoszwalacik
Copy link
Member

bartoszwalacik commented Jul 17, 2020

released in 5.10.5
(see https://javers.org/documentation/spring-boot-integration/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants