public Migration getMigration() throws InvalidRequestException, ConfigurationException
{
try
{
CFMetaData oldCfm = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
boolean columnExists = false;
// mutating oldCfm directly would be bad, but mutating a Thrift copy is fine. This also
// sets us up to use validateCfDef to check for index name collisions.
CfDef cf_def = oldCfm.toThrift();
for (ColumnDef cd : cf_def.column_metadata)
{
if (cd.name.equals(columnName.key))
{
if (cd.index_type != null)
throw new InvalidRequestException("Index already exists");
if (logger.isDebugEnabled())
logger.debug("Updating column {} definition for index {}", columnName, indexName);
cd.setIndex_type(IndexType.KEYS);
cd.setIndex_name(indexName);
columnExists = true;
break;
}
}
if (!columnExists)
{
CFDefinition cfDef = oldCfm.getCfDef();
CFDefinition.Name name = cfDef.get(columnName);
if (name != null)
{
switch (name.kind)
{