mirror of
https://github.com/google/nomulus
synced 2026-09-19 22:44:26 +00:00
Modify DeleteReservedListCommand to delete from both databases (#1025)
* Modify DeleteReservedListCommand to use both databases * switch to confirming command * fix typo
This commit is contained in:
@@ -31,6 +31,11 @@ public class ReservedListDatastoreDao {
|
||||
ofyTm().transact(() -> ofyTm().put(reservedList));
|
||||
}
|
||||
|
||||
/** Delete a reserved list from Datastore. */
|
||||
public static void delete(ReservedList reservedList) {
|
||||
ofyTm().transact(() -> ofyTm().delete(reservedList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most recent revision of the {@link ReservedList} with the specified name, if it
|
||||
* exists.
|
||||
|
||||
+15
@@ -51,6 +51,21 @@ public class ReservedListDualDatabaseDao {
|
||||
}
|
||||
}
|
||||
|
||||
/** Delete a reserved list from both databases. */
|
||||
public static void delete(ReservedList reservedList) {
|
||||
if (isDatastore(TransitionId.DOMAIN_LABEL_LISTS)) {
|
||||
ReservedListDatastoreDao.delete(reservedList);
|
||||
DatabaseMigrationUtils.suppressExceptionUnlessInTest(
|
||||
() -> ReservedListSqlDao.delete(reservedList),
|
||||
"Error deleting the reserved list from Cloud SQL.");
|
||||
} else {
|
||||
ReservedListSqlDao.delete(reservedList);
|
||||
DatabaseMigrationUtils.suppressExceptionUnlessInTest(
|
||||
() -> ReservedListDatastoreDao.delete(reservedList),
|
||||
"Error deleting the reserved list from Datastore.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most recent revision of the {@link ReservedList} with the specified name, if it
|
||||
* exists.
|
||||
|
||||
@@ -41,6 +41,11 @@ public class ReservedListSqlDao {
|
||||
reservedList.getName(), reservedList.getReservedListEntries().size());
|
||||
}
|
||||
|
||||
/** Deletes a reserved list from Cloud SQL. */
|
||||
public static void delete(ReservedList reservedList) {
|
||||
jpaTm().transact(() -> jpaTm().delete(reservedList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most recent revision of the {@link ReservedList} with the specified name, if it
|
||||
* exists.
|
||||
|
||||
@@ -21,13 +21,14 @@ import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.model.registry.label.ReservedListDualDatabaseDao;
|
||||
|
||||
/**
|
||||
* Command to delete a {@link ReservedList} in Datastore. This command will fail if the reserved
|
||||
* list is currently in use on a tld.
|
||||
* Command to delete a {@link ReservedList} from the database. This command will fail if the
|
||||
* reserved list is currently in use on a tld.
|
||||
*/
|
||||
@Parameters(separators = " =", commandDescription = "Deletes a ReservedList in Datastore.")
|
||||
final class DeleteReservedListCommand extends MutatingCommand {
|
||||
@Parameters(separators = " =", commandDescription = "Deletes a ReservedList from the database.")
|
||||
final class DeleteReservedListCommand extends ConfirmingCommand {
|
||||
|
||||
@Parameter(
|
||||
names = {"-n", "--name"},
|
||||
@@ -47,6 +48,12 @@ final class DeleteReservedListCommand extends MutatingCommand {
|
||||
tldsUsedOn.isEmpty(),
|
||||
"Cannot delete reserved list because it is used on these tld(s): %s",
|
||||
Joiner.on(", ").join(tldsUsedOn));
|
||||
stageEntityChange(existing, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String execute() {
|
||||
ReservedList existing = ReservedList.get(name).get();
|
||||
ReservedListDualDatabaseDao.delete(existing);
|
||||
return String.format("Deleted reserved list: %s", name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user