Execute Query
Just Execute Query With *
:¶
If you are not using the result of the query, you can mark it *
. This will tell
edgeql-queries
to use the .execute
driver method. This may be useful for migration, for example.
Information
This is only an example, because full migration support exists directly in the EdgeDB CLI.
For example, there are the following migrations for our scheme:
edgeql/migrations/migrtaion_0000_default.edgeql
:
# name: migration_0000_default*
CREATE MIGRATION migration_0000_default TO {
module default {
type Person {
required property first_name -> str;
required property last_name -> str;
}
}
};
COMMIT MIGRATION migration_0000_default;
edgeql/migrations/migration_0001_add_movies.edgeql
:
# name: migration_0001_add_movies*
CREATE MIGRATION migration_0001_add_movies TO {
module default {
type Person {
required property first_name -> str;
required property last_name -> str;
}
type Movie {
required property title -> str;
# the year of release
property year -> int64;
required link director -> Person;
multi link actors -> Person;
}
}
};
COMMIT MIGRATION migration_0001_add_movies;
edgeql/migrations/migration_0002_add_min_year_contraint.edgeql
:
# name: migration_0002_add_min_year_constraint*
CREATE MIGRATION migration_0002_add_min_year_constraint TO {
module default {
type Person {
required property first_name -> str;
required property last_name -> str;
}
type Movie {
required property title -> str;
# the year of release
property year -> int64 {
constraint min_value(1888);
};
required link director -> Person;
multi link actors -> Person;
}
}
};
COMMIT MIGRATION migration_0002_add_min_year_constraint;
We can migrate it using the following code:
migrate.py
:
import edgedb
from edgeql_queries import from_path
queries = from_path("./edgeql", async_driver=False)
conn = edgedb.connect()
for migration_query in queries.migrations.available_queries:
print(f"migrate: {migration_query.name}")
for tx in conn.transaction():
with tx:
queries.migrations.get_executor(migration_query.name)(tx)