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

Make Spring Statemachine table names configurable using a prefix #1137

Open
pdalfarr opened this issue Jan 24, 2024 · 3 comments
Open

Make Spring Statemachine table names configurable using a prefix #1137

pdalfarr opened this issue Jan 24, 2024 · 3 comments
Labels
status/need-triage Team needs to triage and take a first look

Comments

@pdalfarr
Copy link

pdalfarr commented Jan 24, 2024

Context

Spring Statemachine creates tables to store statemachine's definitions and states.

As a consequence, when using Spring Statemachine in a project, the following tables are created:

action
deferred_events
guard
state
state_entry_actions
state_exit_actions
state_machine
state_state_actions
transition
transition_actions

Observations

As per the list above, one can note that table names of org.springframework.statemachine.JpaRepository* classes are hardcoded.

example taken from JpaRepositoryStateMachine.java :

@Entity
@Table(name = "state_machine")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public class JpaRepositoryStateMachine extends RepositoryStateMachine {

Potential Issues

Table name clashes can occurs with already existing tables in project's DB.
Possible workarounds consist in renaming exiting table(s), or using another Datasource for Spring StateMachine.

Proposed improvement

Adding a prefix to Spring Statemachine table names, for instance "ssm_" would be great, both to prevent name clashes and to ease the finding and understanding of tables in DB.
Prefix would have a default value ( "ssm_" or "" ?) which could be changed using application property

spring:
   statemachine:
      data:
         jpa:
            table-name-prefix: "customerorder_statemachine_"

Note about table-name-prefix:
A heads up should be given to users regarding the length of table names ( see #469 ) ( "ssm_" prefix will cause max length to be 26, which is below 30 mentioned in issue 469 )

About the implementation of this improvement

Application property spring.jpa.hibernate.naming.physical-strategy: could help with that.

References:
https://www.baeldung.com/hibernate-naming-strategy
https://www.baeldung.com/hibernate-field-naming-spring-boot

About Other "statemachine" implementations

Thanks

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Jan 24, 2024
@pdalfarr
Copy link
Author

@jvalkeal Sorry to bother you, but it seems you are the main contributor on this projet.
Just one question:
When / how often are 'need-triage' issues processed?

Thanks.

@OksiBlack
Copy link

Sush feature would be very useful.

@libinbin880521
Copy link

libinbin880521 commented Aug 10, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-triage Team needs to triage and take a first look
Projects
None yet
Development

No branches or pull requests

3 participants