weizhouapache commented on code in PR #7381:
URL: https://github.com/apache/cloudstack/pull/7381#discussion_r1210088804


##########
engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java:
##########
@@ -26,6 +26,17 @@ public class DatabaseAccessObject {
 
     private static Logger s_logger = 
Logger.getLogger(DatabaseAccessObject.class);
 
+    public void addForeignKey(Connection conn, String tableName, String 
tableColumn, String foreignTableName, String foreignColumnName) {
+        String addForeignKeyStmt = String.format("CALL 
`cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY`('%s', '%s', '%s', '%s')", tableName, 
tableColumn, foreignTableName, foreignColumnName);

Review Comment:
   > I am not sure it is wise to allow changes to the DB to be not IdemPotent 
if they can be. updating in dot releases that rquire updates will lead to 
conflicts if we do not keep this policy. I have not understood yet why it would 
be harmful in this instance. @weizhouapache please explain.
   
   @DaanHoogland 
   the try-catch block will handle the exceptions if the column or constrain 
key has been already added.
   
   I think it is better than MySQL procedure, because the error codes of MySQL 
procedure are different with MySQL versions, which is the root cause of #7358 
   
   ```
       try
           {
               pstmt.executeUpdate();
               s_logger.debug(String.format("Foreign key is added successfully 
from the table %s", tableName));
           } catch (SQLException e) {
               s_logger.error("Ignored SQL Exception when trying to add foreign 
key on table "  + tableName + " exception: " + e.getMessage());
           }
       }
   }



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to