edgedb / edgedb-cli

The EdgeDB CLI
https://www.edgedb.com/docs/cli/index
Apache License 2.0
164 stars 23 forks source link

Edgedb dump -> restore onto non-empty database with only extensions isn't rejected #1310

Open quinchs opened 2 years ago

quinchs commented 2 years ago

When dumping a database whos schema uses an extension, the returned binary file cannot be used to restore.

Steps to Reproduce:

  1. create a new empty instance

  2. run edgedb dump ./dump.bin

  3. run edgedb restore dump.bin above steps should work as expected

  4. add a using extension .. to the schema and migrate the database

  5. run step 2 and 3

with testing this im using the edgeql_http extension

Retuned error ``` edgedb error: SchemaError: error initiating restore protocol: Extension ('cb78b832-d624-11ec-b010-f3789a0548ba') is already present in the schema Server traceback: Traceback (most recent call last): File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/server/compiler_pool/worker.py", line 309, in worker res = meth(*args) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 2450, in describe_database_restore units = self._compile(ctx=ctx, source=ddl_source) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 1667, in _compile return self._try_compile(ctx=ctx, source=source) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 1720, in _try_compile comp, capabilities = self._compile_dispatch_ql( File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 1614, in _compile_dispatch_ql self._compile_and_apply_ddl_stmt(ctx, ql, source=source), File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 793, in _compile_and_apply_ddl_stmt delta = s_ddl.delta_from_ddl( File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/ddl.py", line 581, in delta_from_ddl _, cmd = _delta_from_ddl( File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/ddl.py", line 628, in _delta_from_ddl schema = cmd.apply(schema, context) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/delta.py", line 2977, in apply schema = self._create_begin(schema, context) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/delta.py", line 2878, in _create_begin schema, self.scls = metaclass.create_in_schema(schema, **props) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/objects.py", line 1131, in create_in_schema schema = schema.add(id, cls, tuple(obj_data)) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/schema.py", line 1558, in add self._top_schema.add(id, sclass, data), File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/schema.py", line 963, in add return self.add_raw(id, sclass, data) File "/home/edgedb/.local/share/edgedb/portable/1.4/lib/python3.10/site-packages/edb/schema/schema.py", line 910, in add_raw raise errors.SchemaError( edb.errors.SchemaError: Extension ('cb78b832-d624-11ec-b010-f3789a0548ba') is already present in the schema ```

Schema:

using extension edgeql_http;

module default {

}
elprans commented 2 years ago

Hmm. Is there a chance you're restoring into a non-empty database? The bug seems to be that the CLI fails to recognize that the schema is non-empty.

quinchs commented 2 years ago

running the above steps on a clean empty database causes the error so I don't think so

elprans commented 2 years ago

I couldn't reproduce. Steps (as written) attempt restore twice into the same db, no?

quinchs commented 2 years ago

yes

msullivan commented 2 months ago

I think that Elvis is correct here: the second restore is trying to restore onto a non-empty database, which I think we typically try to reject in the CLI.