Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import org.alfasoftware.morf.jdbc.ConnectionResources;
import org.alfasoftware.morf.metadata.Column;
import org.alfasoftware.morf.metadata.Schema;
import org.alfasoftware.morf.metadata.SchemaHomology;
import org.alfasoftware.morf.metadata.Table;
import org.alfasoftware.morf.upgrade.adapt.AlteredTable;
import org.alfasoftware.morf.upgrade.adapt.TableOverrideSchema;
import org.apache.commons.lang3.StringUtils;

/**
* {@link SchemaChange} which consists of adding a new column to an existing
Expand Down Expand Up @@ -162,4 +161,10 @@ public void accept(SchemaChangeVisitor visitor) {
visitor.visit(this);
}


@Override
public String toString() {
return "AddColumn [tableName=" + tableName + ", newColumnDefinition=" + newColumnDefinition + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,10 @@ public Index getNewIndex() {
return newIndex;
}


@Override
public String toString() {
return "AddIndex [tableName=" + tableName + ", newIndex=" + newIndex + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

package org.alfasoftware.morf.upgrade;

import com.google.common.collect.ImmutableList;
import org.alfasoftware.morf.jdbc.ConnectionResources;
import org.alfasoftware.morf.metadata.Schema;
import org.alfasoftware.morf.metadata.SchemaValidator;
import org.alfasoftware.morf.metadata.Sequence;
import org.alfasoftware.morf.upgrade.adapt.AugmentedSchema;
import org.alfasoftware.morf.upgrade.adapt.FilteredSchema;

import com.google.common.collect.ImmutableList;

/**
* A {@link SchemaChange} which consists of the addition of a new sequence to
* a database schema.
Expand Down Expand Up @@ -111,4 +112,10 @@ public void accept(SchemaChangeVisitor visitor) {
public Sequence getSequence() {
return newSequence;
}


@Override
public String toString() {
return "AddSequence [newSequence=" + newSequence + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public Table getTable() {
public void accept(SchemaChangeVisitor visitor) {
visitor.visit(this);
}

@Override
public String toString() {
return "AddTable [newTable=" + newTable + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ public SelectStatement getSelectStatement() {
public void accept(SchemaChangeVisitor visitor) {
visitor.visit(this);
}


@Override
public String toString() {
return "AddTableFrom [table=" + getTable() + ", selectStatement=" + selectStatement + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,11 @@ public String getTableName() {
return tableName;
}


@Override
public String toString() {
return "AnalyseTable [tableName=" + tableName + "]";
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@

package org.alfasoftware.morf.upgrade;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.alfasoftware.morf.jdbc.ConnectionResources;
import org.alfasoftware.morf.metadata.Column;
import org.alfasoftware.morf.metadata.DataType;
Expand All @@ -29,13 +35,8 @@
import org.alfasoftware.morf.upgrade.adapt.AlteredTable;
import org.alfasoftware.morf.upgrade.adapt.TableOverrideSchema;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;

/**
* {@link SchemaChange} which consists of changing an existing column
Expand All @@ -45,26 +46,26 @@
*/
public class ChangeColumn implements SchemaChange {

/** The table to change **/
private final String tableName;

/** The start definition for the column **/
private final Column fromColumn;

/** The end definition for the column **/
private final Column toColumn;

/**
* A map of the supported data type transitions.
*
* <p>Each of the transitions here MUST be supported by a test in TestDatabaseUpgradeIntegration.</p>
*
* Transitions do not have to be reversible.
*/
private final Multimap<DataType,DataType> allowedDataTypeChanges = ImmutableMultimap.<DataType,DataType>builder()
private static final Multimap<DataType,DataType> ALLOWED_DATA_TYPE_CHANGES = ImmutableMultimap.<DataType,DataType>builder()
.put(DataType.DECIMAL, DataType.BIG_INTEGER) // Tested by testChangeColumnDataTypeAndChangeToPrimaryKey
.build();

/** The table to change **/
private final String tableName;

/** The start definition for the column **/
private final Column fromColumn;

/** The end definition for the column **/
private final Column toColumn;

/**
* @param tableName the name of the table to change
* @param fromColumn the column definition to change from
Expand Down Expand Up @@ -168,7 +169,7 @@ private void verifyDataTypeChanges() {
}

// look up what target types we are allowed to change to
Collection<DataType> allowableTargetTypes = allowedDataTypeChanges.get(fromColumn.getType());
Collection<DataType> allowableTargetTypes = ALLOWED_DATA_TYPE_CHANGES.get(fromColumn.getType());

if (!allowableTargetTypes.contains(toColumn.getType())) {
throw new IllegalArgumentException(String.format("Attempting to change the data type of [%s]. Changes from %s to %s are not supported.", fromColumn.getName(), fromColumn.getType(), toColumn.getType()));
Expand Down Expand Up @@ -297,4 +298,10 @@ public Column getFromColumn() {
public Column getToColumn() {
return toColumn;
}


@Override
public String toString() {
return "ChangeColumn [tableName=" + tableName + ", fromColumn=" + fromColumn + ", toColumn=" + toColumn + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,10 @@ public Index getFromIndex() {
public Index getToIndex() {
return toIndex;
}


@Override
public String toString() {
return "ChangeIndex [tableName=" + tableName + ", fromIndex=" + fromIndex + ", toIndex=" + toIndex + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,11 @@ public List<String> getOldPrimaryKeyColumns() {
public List<String> getNewPrimaryKeyColumns() {
return newPrimaryKeyColumns;
}


@Override
public String toString() {
return "ChangePrimaryKeyColumns [tableName=" + tableName + ", oldPrimaryKeyColumns=" + oldPrimaryKeyColumns
+ ", newPrimaryKeyColumns=" + newPrimaryKeyColumns + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,11 @@ public Schema reverse(Schema schema) {
public List<String> getOldPrimaryKeyColumns() {
return oldPrimaryKeyColumns == null ? super.getOldPrimaryKeyColumns() : oldPrimaryKeyColumns;
}


@Override
public String toString() {
return "CorrectPrimaryKeyColumns [tableName=" + tableName + ", newPrimaryKeyColumns=" + newPrimaryKeyColumns
+ ", oldPrimaryKeyColumns=" + oldPrimaryKeyColumns + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ExecuteStatement(Statement statement) {

/**
* {@inheritDoc}
*
*
* @see org.alfasoftware.morf.upgrade.SchemaChange#accept(org.alfasoftware.morf.upgrade.SchemaChangeVisitor)
*/
@Override
Expand Down Expand Up @@ -101,4 +101,10 @@ public Schema reverse(Schema schema) {
public Statement getStatement() {
return statement;
}


@Override
public String toString() {
return "ExecuteStatement [statement=" + statement + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,10 @@ public String getTableName() {
return tableName;
}


@Override
public String toString() {
return "RemoveColumn [tableName=" + tableName + ", columnDefinition=" + columnDefinition + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,10 @@ public String getTableName() {
public Index getIndexToBeRemoved() {
return indexToBeRemoved;
}


@Override
public String toString() {
return "RemoveIndex [tableName=" + tableName + ", indexToBeRemoved=" + indexToBeRemoved + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

package org.alfasoftware.morf.upgrade;

import com.google.common.collect.ImmutableList;
import org.alfasoftware.morf.jdbc.ConnectionResources;
import org.alfasoftware.morf.metadata.Schema;
import org.alfasoftware.morf.metadata.Sequence;
import org.alfasoftware.morf.upgrade.adapt.AugmentedSchema;
import org.alfasoftware.morf.upgrade.adapt.FilteredSchema;

import com.google.common.collect.ImmutableList;


/**
* A {@link SchemaChange} which consists of the removal of a new sequence to
Expand Down Expand Up @@ -104,4 +105,10 @@ public void accept(SchemaChangeVisitor visitor) {
public Sequence getSequence() {
return sequenceToBeRemoved;
}


@Override
public String toString() {
return "RemoveSequence [sequenceToBeRemoved=" + sequenceToBeRemoved + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ public Table getTable() {
return tableToBeRemoved;
}


@Override
public String toString() {
return "RemoveTable [tableToBeRemoved=" + tableToBeRemoved + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import org.alfasoftware.morf.jdbc.ConnectionResources;
import org.alfasoftware.morf.metadata.Index;
import org.alfasoftware.morf.metadata.Schema;
import org.alfasoftware.morf.metadata.Table;
import org.alfasoftware.morf.upgrade.adapt.AlteredTable;
import org.alfasoftware.morf.upgrade.adapt.TableOverrideSchema;
import org.apache.commons.lang3.StringUtils;

/**
* {@link SchemaChange} which consists of renaming an existing index within a
Expand Down Expand Up @@ -203,4 +202,10 @@ public String getFromIndexName() {
public String getToIndexName() {
return toIndexName;
}


@Override
public String toString() {
return "RenameIndex [tableName=" + tableName + ", fromIndexName=" + fromIndexName + ", toIndexName=" + toIndexName + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.alfasoftware.morf.metadata.Schema;
import org.alfasoftware.morf.metadata.SchemaUtils;
import org.alfasoftware.morf.metadata.Table;

import com.google.common.collect.Maps;

/**
Expand Down Expand Up @@ -186,4 +187,10 @@ public boolean isTemporary() {
return baseTable.isTemporary();
}
}


@Override
public String toString() {
return "RenameTable [oldTableName=" + oldTableName + ", newTableName=" + newTableName + "]";
}
}