spring-statemachine icon indicating copy to clipboard operation
spring-statemachine copied to clipboard

Make Spring Statemachine table names configurable using a prefix

Open pdalfarr opened this issue 1 year ago • 3 comments

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 https://github.com/spring-projects/spring-statemachine/issues/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

pdalfarr avatar Jan 24 '24 07:01 pdalfarr

@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.

pdalfarr avatar Feb 21 '24 13:02 pdalfarr

Sush feature would be very useful.

OksiBlack avatar Aug 10 '24 08:08 OksiBlack

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

libinbin880521 avatar Aug 10 '24 08:08 libinbin880521