我正在使用JPA查询flyway_schema_history来打印已执行迁移的报告。在我的Postgresql数据库中的所有模式中都重复flyway_schema_history的结构。另外,我在运行程序时将模式名称作为参数传递。我正在使用Java 10。
我在JPA中创建了这个实体。
@Entity
@Table(name = "flyway_schema_history", schema="this_should_be dynamic")
public class FlywaySchemaHistoryGeneric {
@Id
@Column(name="installed_rank")
private Integer installedRank;
@Column(name="version")
private String version;
@Column(name="description")
private String description;
@Column(name="type")
private String type;
@Column(name="script")
private String script;
@Column(name="checksum")
private Integer checksum;
@Column(name="installed_by")
private String installedBy;
@Column(name="installed_on")
private Date installedOn;
@Column(name="execution_time")
private Integer executionTime;
@Column(name="success")
private Boolean success;
public Integer getInstalledRank() {
return installedRank;
}
public void setInstalledRank(Integer installedRank) {
this.installedRank = installedRank;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getScript() {
return script;
}
public void setScript(String script) {
this.script = script;
}
public Integer getChecksum() {
return checksum;
}
public void setChecksum(Integer checksum) {
this.checksum = checksum;
}
public String getInstalledBy() {
return installedBy;
}
public void setInstalledBy(String installedBy) {
this.installedBy = installedBy;
}
public Date getInstalledOn() {
return installedOn;
}
public void setInstalledOn(Date installedOn) {
this.installedOn = installedOn;
}
public Integer getExecutionTime() {
return executionTime;
}
public void setExecutionTime(Integer executionTime) {
this.executionTime = executionTime;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
}
我试图使用FlywaySchemaHistoryGeneric.class.getAnnotation在运行时更改值,但没有成功,但是我认为这应该是一种简单的方法。 我该怎么做才能使@table中的架构成为动态的?
答案 0 :(得分:0)
我想您将无法在运行时修改它,因为注释是只读的。您可以为每个架构创建一个数据源,然后选择其中一个以根据您的规则保留实体。