diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java index afc2a4feb875..e1b420efa1ad 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java @@ -2753,6 +2753,9 @@ private void deleteAPIFromDB(API api) throws APIManagementException { } } deleteScopes(localScopeKeysToDelete, tenantId); + if (APIConstants.API_SUBTYPE_AI_API.equals(api.getSubtype())) { + apiMgtDAO.deleteAIConfiguration(api.getUuid(), null); + } apiMgtDAO.deleteAPI(api.getUuid()); if (log.isDebugEnabled()) { log.debug("API : " + apiIdentifier + " is successfully deleted from the database and Key Manager."); @@ -6722,6 +6725,7 @@ public void deleteAPIRevision(String apiId, String apiRevisionId, String organiz ERROR_DELETING_API_REVISION,apiRevision.getApiUUID())); } apiMgtDAO.deleteAPIRevision(apiRevision); + apiMgtDAO.deleteAIConfiguration(apiRevision.getApiUUID(), apiRevision.getRevisionUUID()); gatewayArtifactsMgtDAO.deleteGatewayArtifact(apiRevision.getApiUUID(), apiRevision.getRevisionUUID()); if (artifactSaver != null) { try { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java index daf7622bed74..265d5d7aa23a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java @@ -2803,7 +2803,7 @@ public class SQLConstants { "DELETE FROM AM_API_AI_CONFIGURATION WHERE API_UUID = ? AND API_REVISION_UUID = ?"; public static final String DELETE_AI_CONFIGURATIONS = - "DELETE FROM AM_API_AI_CONFIGURATION WHERE API_UUID = ? AND API_REVISION_UUID IS NULL"; + "DELETE FROM AM_API_AI_CONFIGURATION WHERE API_UUID = ?"; public static final String DELETE_API_PRODUCT_SQL = "DELETE FROM AM_API WHERE API_PROVIDER = ? AND API_NAME = ? AND API_VERSION = ? AND API_TYPE = '" diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql index bb85205dfffc..cdc6a5e292fa 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql @@ -3284,7 +3284,7 @@ CREATE TABLE AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql index 36a9dafc9fd0..dfdec4d1f798 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql @@ -2488,7 +2488,7 @@ CREATE TABLE IF NOT EXISTS AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ); diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql index f654368ae9c0..e774595b34b9 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql @@ -2762,7 +2762,7 @@ CREATE TABLE AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ); diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql index ede30778e941..9246dd723b9e 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql @@ -2522,7 +2522,7 @@ CREATE TABLE IF NOT EXISTS AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ) ENGINE INNODB; diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql index fe75ae9dea6d..3f8555416ba3 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql @@ -2674,7 +2674,7 @@ CREATE TABLE IF NOT EXISTS AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ) ENGINE=NDB; diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql index 675a12f1afde..8a8000dac571 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql @@ -3876,7 +3876,7 @@ CREATE TABLE AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql index dc449397ade5..6d9ee5f2cd47 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql @@ -3876,7 +3876,7 @@ CREATE TABLE AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql index a7a1cd43e2f5..b8ae243eac84 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql @@ -3847,7 +3847,7 @@ CREATE TABLE AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) ) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql index 3728b854dae9..19a3c8559568 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql @@ -2863,7 +2863,7 @@ CREATE TABLE IF NOT EXISTS AM_API_AI_CONFIGURATION ( ENDPOINT_CONFIGURATION VARCHAR(2048) NOT NULL, THROTTLING_CONFIGURATIONS VARCHAR(1024) NOT NULL, PRIMARY KEY (AI_CONFIGURATION_UUID), - FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE, + FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID), FOREIGN KEY (LLM_PROVIDER_UUID) REFERENCES AM_LLM_PROVIDER(UUID) );