Skip to content

Commit

Permalink
Use regular CREATE TABLE instead of CREATE TEMPORARY
Browse files Browse the repository at this point in the history
Some hosted/managed environments like google CloudSQL, might not support this type of statement (i.e. when using replication and GTID)

Since we are dropping the table anyway it seems a regular CREATE statement should work fine here.

Signed-off-by: mike-pt <[email protected]>
  • Loading branch information
mike-pt authored and pedroigor committed Nov 28, 2024
1 parent 7acb302 commit 94bcad6
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void generateStatementsImpl() throws CustomChangeException {
" AND uc.USER_ID = max_dates.USER_ID AND uc.LAST_UPDATED_DATE = max_dates.MAX_UPDATED_DATE)"
));
statements.add(new RawSqlStatement(
" CREATE TEMPORARY TABLE TEMP_USER_CONSENT_IDS" +
" CREATE TABLE TEMP_USER_CONSENT_IDS" +
" AS SELECT uc.ID FROM "+userConsentTable+" uc INNER JOIN (" +
" SELECT CLIENT_ID, USER_ID, MAX(LAST_UPDATED_DATE) AS MAX_UPDATED_DATE" +
" FROM "+userConsentTable+" GROUP BY CLIENT_ID, USER_ID HAVING COUNT(*) > 1 )" +
Expand All @@ -44,7 +44,7 @@ protected void generateStatementsImpl() throws CustomChangeException {
));
statements.add(new DeleteStatement(null, null, database.correctObjectName("USER_CONSENT", Table.class))
.setWhere("ID IN (SELECT ID FROM TEMP_USER_CONSENT_IDS)"));
statements.add(new RawSqlStatement("DROP TEMPORARY TABLE IF EXISTS TEMP_USER_CONSENT_IDS"));
statements.add(new RawSqlStatement("DROP TABLE IF EXISTS TEMP_USER_CONSENT_IDS"));

statements.add(new RawSqlStatement(
" DELETE FROM "+ userConsentClientScopeTable + " WHERE USER_CONSENT_ID IN (" +
Expand All @@ -55,7 +55,7 @@ protected void generateStatementsImpl() throws CustomChangeException {
" AND uc.EXTERNAL_CLIENT_ID = max_dates.EXTERNAL_CLIENT_ID AND uc.USER_ID = max_dates.USER_ID AND uc.LAST_UPDATED_DATE = max_dates.MAX_UPDATED_DATE )"
));
statements.add(new RawSqlStatement(
"CREATE TEMPORARY TABLE TEMP_USER_CONSENT_IDS2" +
"CREATE TABLE TEMP_USER_CONSENT_IDS2" +
" AS SELECT uc.ID FROM "+userConsentTable+" uc INNER JOIN (" +
" SELECT CLIENT_STORAGE_PROVIDER, EXTERNAL_CLIENT_ID, USER_ID, MAX(LAST_UPDATED_DATE) AS MAX_UPDATED_DATE" +
" FROM "+userConsentTable+" GROUP BY CLIENT_STORAGE_PROVIDER, EXTERNAL_CLIENT_ID, USER_ID HAVING COUNT(*) > 1 )" +
Expand All @@ -64,7 +64,7 @@ protected void generateStatementsImpl() throws CustomChangeException {
));
statements.add(new DeleteStatement(null, null, database.correctObjectName("USER_CONSENT", Table.class))
.setWhere("ID IN (SELECT ID FROM TEMP_USER_CONSENT_IDS2)"));
statements.add(new RawSqlStatement("DROP TEMPORARY TABLE IF EXISTS TEMP_USER_CONSENT_IDS2"));
statements.add(new RawSqlStatement("DROP TABLE IF EXISTS TEMP_USER_CONSENT_IDS2"));
}

@Override
Expand Down

0 comments on commit 94bcad6

Please sign in to comment.