Database scrubbing #2994
-
How would one go about scrubbing an entire EdgeDB database programmatically (without actually dropping the database)? Would the following suffice? Alternatively, is it possible to connect to EdgeDB without opening a database in order to log.warning("Dropping all EdgeDB objects due to scrubbing configuration")
drop_object_types = await client.query("SELECT name := schema::ObjectType.name FILTER name LIKE 'default::%';")
drop_scalar_types = await client.query("SELECT name := schema::ScalarType.name FILTER name LIKE 'default::%';")
drop_functions = await client.query("SELECT name := schema::Function.name FILTER name LIKE 'default::%';")
drop_aliases = await client.query("SELECT name := schema::Alias.name FILTER name LIKE 'default::%';")
drop_properties = await client.query("SELECT name := schema::Property.name FILTER name LIKE 'default::%';")
drop_constraints = await client.query("SELECT name := schema::Constraint.name FILTER name LIKE 'default::%';")
drop_annotations = await client.query("SELECT name := schema::Annotation.name FILTER name LIKE 'default::%';")
drop_extensions = await client.query("SELECT name := schema::Extension.name FILTER name LIKE 'default::%';")
pending_drop = []
pending_drop += [(name, "TYPE") for name in drop_object_types]
pending_drop += [(name, "SCALAR TYPE") for name in drop_scalar_types]
pending_drop += [(name, "FUNCTION") for name in drop_functions]
pending_drop += [(name, "ALIAS") for name in drop_aliases]
pending_drop += [(name, "ABSTRACT PROPERTY") for name in drop_properties]
pending_drop += [(name, "ABSTRACT CONSTRAINT") for name in drop_constraints]
pending_drop += [(name, "ABSTRACT ANNOTATION") for name in drop_annotations]
pending_drop += [(name, "EXTENSION") for name in drop_extensions]
while pending_drop:
name, item_type = pending_drop.pop()
try:
await client.execute(f"DROP {item_type} {name};")
except Exception as e:
log.warning(f"Failed to drop EdgeDB {item_type.lower()} `{name}`; queuing to retry...")
pending_drop.insert(0, (name, item_type)) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
So far, I worked around this by connecting to a different database, dropping and re-creating the target database, and then connecting the the target database. The following should work similar to what you're doing:
But last time I tried that (about a year ago), this often failed due to EdgeDB bugs, which should be fixed nowadays. However manual migrations like that (or your code) might mess with edgedb cli's built in migration handling. |
Beta Was this translation helpful? Give feedback.
So far, I worked around this by connecting to a different database, dropping and re-creating the target database, and then connecting the the target database.
The following should work similar to what you're doing:
But last time I tried that (about a year ago), this often failed due to EdgeDB bugs, which should be fixed nowadays.
However manual migrations like that (or your code) might mess with edgedb cli's built in migration handling.