Skip to content

Commit

Permalink
create audit triggers with "if not exists" in order to fix issue loca…
Browse files Browse the repository at this point in the history
…tiontech#410

Signed-off-by: sebastian-r-schmidt <[email protected]>
  • Loading branch information
sebastian-r-schmidt committed Nov 3, 2018
1 parent 655b143 commit 72f54a7
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private void createInsertTrigger(final String tableName, final String auditTable
final LinkedHashMap<String, String> columnNames) throws SQLException {

StringBuilder trigger = new StringBuilder(
format("CREATE TRIGGER '%s_insert' AFTER INSERT ON '%s'\n", auditTable, tableName));
format("CREATE TRIGGER IF NOT EXISTS '%s_insert' AFTER INSERT ON '%s'\n", auditTable, tableName));
trigger.append("BEGIN\n");
trigger.append(format(" INSERT INTO '%s' (", auditTable));
for (String colName : columnNames.keySet()) {
Expand All @@ -347,7 +347,7 @@ private void createUpdateTrigger(final String tableName, final String auditTable
final LinkedHashMap<String, String> columnNames) throws SQLException {

StringBuilder trigger = new StringBuilder(
format("CREATE TRIGGER '%s_update' AFTER UPDATE ON '%s'\n", auditTable, tableName));
format("CREATE TRIGGER IF NOT EXISTS '%s_update' AFTER UPDATE ON '%s'\n", auditTable, tableName));
trigger.append("BEGIN\n");
trigger.append(format(" INSERT INTO '%s' (", auditTable));
for (String colName : columnNames.keySet()) {
Expand All @@ -370,7 +370,7 @@ private void createDeleteTrigger(final String tableName, final String auditTable
final LinkedHashMap<String, String> columnNames) throws SQLException {

StringBuilder trigger = new StringBuilder(
format("CREATE TRIGGER '%s_delete' AFTER DELETE ON '%s'\n", auditTable, tableName));
format("CREATE TRIGGER IF NOT EXISTS '%s_delete' AFTER DELETE ON '%s'\n", auditTable, tableName));
trigger.append("BEGIN\n");

final String insert = format(" INSERT INTO '%s' ('fid', audit_op) VALUES (OLD.fid, %s);\n",
Expand Down

0 comments on commit 72f54a7

Please sign in to comment.