Skip to content

Commit

Permalink
ui, sql: fix display of "database dropped" event.
Browse files Browse the repository at this point in the history
The DROP_DATABASE event in `system.eventlog`  was changed from having
the key `DroppedTables` to having the key `DroppedTablesAndViews`.
The corresponding UI code which displays the dropped tables was not
changed, creating bug #18523.

This commit fixes #18523 by renaming the key to `DroppedSchemaObjects`,
both in the event and in the UI code. The term "Schema Objects" accounts
for the existence of sequences in addition to views and tables.

Release note (admin ui change): display the names of dropped schema
objects on `DROP DATABASE ... CASCADE`
  • Loading branch information
Pete Vilter committed Apr 16, 2018
1 parent 99014a1 commit e242d28
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions pkg/sql/drop_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ func (n *dropDatabaseNode) startExec(params runParams) error {
int32(n.dbDesc.ID),
int32(params.extendedEvalCtx.NodeID),
struct {
DatabaseName string
Statement string
User string
DroppedTablesAndViews []string
DatabaseName string
Statement string
User string
DroppedSchemaObjects []string
}{n.n.Name.String(), n.n.String(), p.SessionData().User, tbNameStrings},
)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/event_log
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ DROP DATABASE IF EXISTS othereventlogtest CASCADE
# verify event is there, and cascading table drops are logged.

query IIT
SELECT "targetID", "reportingID", info::JSONB->>'DroppedTablesAndViews'
SELECT "targetID", "reportingID", info::JSONB->>'DroppedSchemaObjects'
FROM system.eventlog
WHERE "eventType" = 'drop_database'
AND info::JSONB->>'Statement' LIKE 'DROP DATABASE eventlogtest%'
----
53 1 ["eventlogtest.public.anothertesttable", "eventlogtest.public.testtable"]

query IIT
SELECT "targetID", "reportingID", info::JSONB->>'DroppedTablesAndViews'
SELECT "targetID", "reportingID", info::JSONB->>'DroppedSchemaObjects'
FROM system.eventlog
WHERE "eventType" = 'drop_database'
AND info::JSONB->>'Statement' LIKE 'DROP DATABASE IF EXISTS othereventlogtest%'
Expand Down
17 changes: 9 additions & 8 deletions pkg/ui/src/util/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Event$Properties = protos.cockroach.server.serverpb.EventsResponse.Event$Pr
export function getEventDescription(e: Event$Properties): string {
const info: {
DatabaseName: string,
DroppedTables: string[],
DroppedSchemaObjects: string[],
IndexName: string,
MutationID: string,
TableName: string,
Expand All @@ -27,14 +27,15 @@ export function getEventDescription(e: Event$Properties): string {
case eventTypes.CREATE_DATABASE:
return `Database Created: User ${info.User} created database ${info.DatabaseName}`;
case eventTypes.DROP_DATABASE:
info.DroppedTables = info.DroppedTables || [];
let tableDropText: string = `${info.DroppedTables.length} tables were dropped: ${info.DroppedTables.join(", ")}`;
if (info.DroppedTables.length === 0) {
tableDropText = "No tables were dropped.";
} else if (info.DroppedTables.length === 1) {
tableDropText = `1 table was dropped: ${info.DroppedTables[0]}`;
info.DroppedSchemaObjects = info.DroppedSchemaObjects || [];
let tableDropText = `${info.DroppedSchemaObjects.length} schema objects ` +
`were dropped: ${info.DroppedSchemaObjects.join(", ")}`;
if (info.DroppedSchemaObjects.length === 0) {
tableDropText = "No schema objects were dropped.";
} else if (info.DroppedSchemaObjects.length === 1) {
tableDropText = `1 schema objects was dropped: ${info.DroppedSchemaObjects[0]}`;
}
return `Database Dropped: User ${info.User} dropped database ${info.DatabaseName}.${tableDropText}`;
return `Database Dropped: User ${info.User} dropped database ${info.DatabaseName}. ${tableDropText}`;
case eventTypes.CREATE_TABLE:
return `Table Created: User ${info.User} created table ${info.TableName}`;
case eventTypes.DROP_TABLE:
Expand Down

0 comments on commit e242d28

Please sign in to comment.