From 79046d3e76ba1b11f003bb54ae5b58a755074db3 Mon Sep 17 00:00:00 2001 From: Jayant Shrivastava Date: Sun, 1 Nov 2020 17:26:47 -0500 Subject: [PATCH] workload/schemachange: screen for errors in createSchema op Release note: None --- pkg/workload/schemachange/operation_generator.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/workload/schemachange/operation_generator.go b/pkg/workload/schemachange/operation_generator.go index b395b1b6e1bd..7fdf0eef1319 100644 --- a/pkg/workload/schemachange/operation_generator.go +++ b/pkg/workload/schemachange/operation_generator.go @@ -87,6 +87,7 @@ var opsWithExecErrorScreening = map[opType]bool{ createTableAs: true, createView: true, createEnum: true, + createSchema: true, dropColumn: true, dropColumnDefault: true, @@ -1432,9 +1433,18 @@ func (og *operationGenerator) createSchema(tx *pgx.Tx) (string, error) { if err != nil { return "", err } + ifNotExists := og.randIntn(2) == 0 + + schemaExists, err := schemaExists(tx, schemaName) + if err != nil { + return "", err + } + if schemaExists && !ifNotExists { + og.expectedExecErrors.add(pgcode.DuplicateSchema) + } // TODO(jayshrivastava): Support authorization - stmt := rowenc.MakeSchemaName(og.randIntn(2) == 0, schemaName, security.RootUserName()) + stmt := rowenc.MakeSchemaName(ifNotExists, schemaName, security.RootUserName()) return tree.Serialize(stmt), nil }