Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0045728Openbravo ERPY. DBSourceManagerpublic2021-01-13 17:342022-02-01 07:24
shuehner 
Triage Platform Base 
normalminorhave not tried
newopen 
5
 
 
Core
No
0045728: update.database fails when renaming the primaryKey of a table definition in the xml file
Database element names should follow module naming convention and in case of fixing old modules sometime names will be 'fixed' to comply with them.

Renaming the primaryKey name of a table in any src-db/datbase/tables/<TABLENAME>.xml file makes update.database fails with SQL error trying to apply those.

Scenarios below tested with master >21Q1 and pg10 and oracle19

2 specific sub-problems
a.)
On postgresql:
     [java] ALTER TABLE AD_TABLE
     [java] ADD CONSTRAINT AD_TABLE_KEY_NEW PRIMARY KEY (AD_TABLE_ID)

Happens on any rename of the primary key.
Apparently logic does not support this as apparently it is missing to drop the old pk constraint first ?

b.) oracle and pk has incoming fk
     [java] 94900 [main] WARN org.apache.ddlutils.platform.OracleStandardBatchEvaluator - SQL Command failed with: ORA-02273: this unique/primary key is referenced by some foreign keys
     [java]
     [java] 94900 [main] WARN org.apache.ddlutils.platform.OracleStandardBatchEvaluator - ALTER TABLE AD_TABLE
     [java] DROP PRIMARY KEY DROP INDEX
     [java] 94908 [main] WARN org.apache.ddlutils.platform.OracleStandardBatchEvaluator - SQL Command failed with: ORA-02260: table can have only one primary key
     [java]
     [java] 94909 [main] WARN org.apache.ddlutils.platform.OracleStandardBatchEvaluator - -- END
     [java] ALTER TABLE AD_TABLE
     [java] ADD CONSTRAINT AD_TABLE_KEY_NEW PRIMARY KEY (AD_TABLE_ID)

drop index fails as there is a foreign key from other table still pointing to the pk
Then 2nd error is same as in case a.) above

c.) Oracle when there is no incoming foreign key

In this case the renaming works without a problem as can be tested editing primaryKey for example for the AD_SESSION_USAGE_AUDIT table
install.source of unmodified sources
edit table xml file for the tables seen in the cases above and rename the value of primaryKey (2nd line in xml file) to a different name
run update.database to apply the changed xml file
No tags attached.
Issue History
2021-01-13 17:34shuehnerNew Issue
2021-01-13 17:34shuehnerAssigned To => platform
2021-01-13 17:34shuehnerModules => Core
2021-01-13 17:34shuehnerTriggers an Emergency Pack => No
2022-02-01 07:24alostaleAssigned Toplatform => Triage Platform Base

There are no notes attached to this issue.