Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Aug 11, 2016
1 parent 2e1f8bd commit 20e1f96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
Expand Up @@ -29,17 +29,6 @@ public AbstractCTLMigration(Connection connection) {
public void beforeTransform() throws SQLException {
// delete relation between <feature>_schems to schems
dd.dropUnnamedFK(getName() + "_schems", "schems");

// change FK constraint between table that contains data and appropriate <feature>_schems table
dd.dropUnnamedFK(getName(), getName() + "_schems");
dd.alterTable(getName())
.add(constraint("FK_" + getName() + "_schems_id")
.foreignKey(getName() + "_schems_id")
.references(getName() + "_schems", "id")
.onDelete(CASCADE)
.onUpdate(CASCADE)
)
.execute();
}


Expand All @@ -52,20 +41,24 @@ protected List<Schema> transform() throws SQLException {
String toDelete = schemas.stream().map(s -> s.getId().toString()).collect(joining(", "));
runner.update(connection, "delete from schems where id in (" + toDelete + ")");

// set Type of schema
schemas.forEach( s -> s.setType(getType()));
// set Type of schema -- equals to name of the table
schemas.forEach( s -> s.setType(getName()));

return schemas;
}


public void afterTransform() throws SQLException {

dd.alterTable(getName() + "_schems")
.add(constraint("FK_" + getName() + "_base_schems_id")
.foreignKey("id")
.references("base_schems", "id")
.onDelete(CASCADE)
.onUpdate(CASCADE)
)
.execute();
}



protected abstract String getName();

protected abstract Schema.SchemaType getType();
}
Expand Up @@ -32,12 +32,25 @@ public CTLConfigurationMigration(Connection connection) {
}

@Override
protected String getName() {
return "configuration";
public void beforeTransform() throws SQLException {
super.beforeTransform();

// change FK constraint between table that contains data and appropriate <feature>_schems table
dd.dropUnnamedFK("configuration", "configuration_schems");
dd.alterTable(getName())
.add(constraint("FK_configuration_schems_id")
.foreignKey("configuration_schems_id")
.references("configuration_schems", "id")
.onDelete(CASCADE)
.onUpdate(CASCADE)
)
.execute();
}

@Override
protected Schema.SchemaType getType() {
return Schema.SchemaType.CONFIGURATION;
protected String getName() {
return "configuration";
}


}
Expand Up @@ -18,7 +18,7 @@ public class Schema {

private String schems;

private SchemaType type;
private String type;


public Long getId() {
Expand Down Expand Up @@ -85,15 +85,12 @@ public void setSchems(String schems) {
this.schems = schems;
}

public SchemaType getType() {
public String getType() {
return type;
}

public void setType(SchemaType type) {
public void setType(String type) {
this.type = type;
}

public enum SchemaType {
CONFIGURATION,NOTIFICATION, EVENTS, LOG;
}
}

0 comments on commit 20e1f96

Please sign in to comment.