# This test ensures that online restore on a backup with prefixes only succeeds
# if the restoring cluster is empty.

reset test-nodelocal
----

new-cluster name=s1 disable-tenant
----


exec-sql
SET CLUSTER SETTING bulkio.backup.elide_common_prefix.enabled = false;
----

exec-sql
CREATE TABLE data.baz (i INT PRIMARY KEY, s STRING);
INSERT INTO data.baz VALUES (1, 'x'),(2,'y'),(3,'z');
----

query-sql
SELECT count(*) FROM data.baz;
----
3

exec-sql
BACKUP INTO 'nodelocal://1/cluster/';
----


new-cluster name=s2 share-io-dir=s1 allow-implicit-access disable-tenant
----


exec-sql
RESTORE DATABASE data FROM LATEST IN 'nodelocal://1/cluster/' with EXPERIMENTAL DEFERRED COPY;
----

query-sql
SELECT count(*) FROM data.baz;
----
3

exec-sql expect-error-regex=(experimental online restore: descriptor rewrites not supported but required)
RESTORE DATABASE data FROM LATEST IN 'nodelocal://1/cluster/' with EXPERIMENTAL DEFERRED COPY, new_db_name =d2;
----
regex matches error