IDEMPIERE-1132 Improve AD_Index; AD_View; foreign keys management

- Use drop constraint and add constraint when there is a change on foreign key constraint
- Fix constraint SQL statement when there is a change on foreign key constraint
This commit is contained in:
Elaine Tan 2013-08-30 13:26:20 +08:00
parent 9435536919
commit f7385b0de2
1 changed files with 7 additions and 3 deletions

View File

@ -242,9 +242,13 @@ public class ColumnSync extends SvrProcess
DatabaseKey dbForeignKey = htForeignKeys.get(key);
if (dbForeignKey.getKeyColumns()[0].equalsIgnoreCase(column.getColumnName()))
{
DatabaseKey primaryKey = CreateForeignKey.getPrimaryKey(md, dbForeignKey.getKeyTable());
DatabaseKey primaryKey = CreateForeignKey.getPrimaryKey(md, referenceTableName);
if (primaryKey != null)
{
fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR);
fkConstraintSql.append("ALTER TABLE ").append(table.getTableName());
fkConstraintSql.append(" DROP CONSTRAINT ").append(dbForeignKey.getKeyName());
StringBuilder fkConstraint = new StringBuilder();
fkConstraint.append("CONSTRAINT ").append(dbForeignKey.getKeyName());
fkConstraint.append(" FOREIGN KEY (").append(column.getColumnName()).append(") REFERENCES ");
@ -256,10 +260,10 @@ public class ColumnSync extends SvrProcess
fkConstraint.append(", ").append(primaryKey.getKeyColumns()[i]);
}
fkConstraint.append(")");
fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR);
fkConstraintSql.append("ALTER TABLE ").append(table.getTableName());
fkConstraintSql.append(" MODIFY ");
fkConstraintSql.append(" ADD ");
fkConstraintSql.append(fkConstraint);
}
modified = true;