Skip to content

Commit

Permalink
sctest: Run backup/restore tests if exactly one database has schema c…
Browse files Browse the repository at this point in the history
…hanged

We skip backup/restore tests in declarative schema changer if more than
one databases have had schema changes, because we are doing database
level backup. This should not change any existing test case but rather
skip new ones (to be added in the next commit) like
```
create index idx on t (i);
create database db;
```

Release note: None
  • Loading branch information
Xiang-Gu committed Dec 19, 2023
1 parent 716a9f3 commit 7ff698d
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions pkg/sql/schemachanger/sctest/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,40 +753,42 @@ func maybeGetDatabaseForIDs(
t *testing.T, tdb *sqlutils.SQLRunner, ids catalog.DescriptorIDSet,
) (dbName string, exists bool) {
const q = `
SELECT
name
FROM
system.namespace
WHERE
id
IN (
SELECT
DISTINCT
COALESCE(
d->'database'->>'id',
d->'schema'->>'parentId',
d->'type'->>'parentId',
d->'function'->>'parentId',
d->'table'->>'parentId'
)::INT8
FROM
(
SELECT
crdb_internal.pb_to_json('desc', descriptor) AS d
FROM
system.descriptor
WHERE
id IN (SELECT * FROM ROWS FROM (unnest($1::INT8[])))
)
)
`
err := tdb.DB.QueryRowContext(context.Background(), q, pq.Array(ids.Ordered())).Scan(&dbName)
if errors.Is(err, gosql.ErrNoRows) {
SELECT
name
FROM
system.namespace
WHERE
id
IN (
SELECT
DISTINCT
COALESCE(
d->'database'->>'id',
d->'schema'->>'parentId',
d->'type'->>'parentId',
d->'function'->>'parentId',
d->'table'->>'parentId'
)::INT8
FROM
(
SELECT
crdb_internal.pb_to_json('desc', descriptor) AS d
FROM
system.descriptor
WHERE
id IN (SELECT * FROM ROWS FROM (unnest($1::INT8[])))
)
)
`
results := tdb.QueryStr(t, q, pq.Array(ids.Ordered()))
if len(results) > 1 {
skip.IgnoreLintf(t, "requires all schema changes to happen within one database;"+
" get %v: %v", len(results), results)
}
if len(results) == 0 {
return "", false
}

require.NoError(t, err)
return dbName, true
return results[0][0], true
}

// withPostCommitPlanAfterSchemaChange
Expand Down

0 comments on commit 7ff698d

Please sign in to comment.