-
Notifications
You must be signed in to change notification settings - Fork 288
Remove ON DELETE CASCADE #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.netflix.metacat.common.server.connectors.exception; | ||
|
||
/* | ||
* | ||
* Copyright 2024 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import com.netflix.metacat.common.QualifiedName; | ||
import lombok.Getter; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Exception when database can't be deleted because ON DELETE CASCADE is | ||
* disabled and a table still exists in the database. | ||
* | ||
* @author gtret | ||
*/ | ||
@Getter | ||
public class DatabasePreconditionFailedException extends ConnectorException { | ||
/** | ||
* Constructor. | ||
* | ||
* @param name qualified name of the database | ||
* @param message error description | ||
* @param error stacktrace | ||
*/ | ||
public DatabasePreconditionFailedException(final QualifiedName name, | ||
@Nullable final String message, | ||
@Nullable final Throwable error) { | ||
super(String.format("Precondition failed to update table %s. %s", name, message), error); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,5 @@ create table TBLS ( | |
created_date TIMESTAMP not null, | ||
last_updated_by STRING(255), | ||
last_updated_date TIMESTAMP not null, | ||
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE | ||
foreign key (db_name) references DBS(name) ON DELETE RESTRICT ON UPDATE CASCADE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want cascading updates? |
||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.dao.DataAccessException; | ||
import org.springframework.dao.DataIntegrityViolationException; | ||
import org.springframework.dao.OptimisticLockingFailureException; | ||
import org.springframework.data.auditing.AuditingHandler; | ||
import org.springframework.data.auditing.DateTimeProvider; | ||
|
@@ -182,6 +183,24 @@ public void testTableCreationAndDeletionWithParams() { | |
Assert.assertFalse(polarisConnector.tableExistsById(tblEntity.getTblId())); | ||
} | ||
|
||
/** | ||
* Test database deletion if table exists and ON DELETE CASCADE is disabled. | ||
*/ | ||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to have a test at the PolarisConnectorDatabaseService level as well. |
||
public void testDbDeletionNoCascade() { | ||
final String dbName = generateDatabaseName(); | ||
final String tblName = generateTableName(); | ||
final PolarisDatabaseEntity dbEntity = createDB(dbName); | ||
final PolarisTableEntity tblEntity = createTable(dbName, tblName); | ||
|
||
Assert.assertTrue(polarisConnector.databaseExists(dbName)); | ||
Assert.assertTrue(polarisConnector.tableExists(dbName, tblName)); | ||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> | ||
polarisConnector.deleteDatabase(dbName)); | ||
Assert.assertTrue(polarisConnector.databaseExists(dbName)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could you also add a check to make sure the table exist as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
Assert.assertTrue(polarisConnector.tableExists(dbName, tblName)); | ||
} | ||
|
||
/** | ||
* Test to verify that table name can be updated. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this should be
update database
?