Migrations

This section describes the DDL commands pertaining to migrations.

Create a new migration.

[ WITH [ module-alias := ] MODULE module-name ]
CREATE MIGRATION name TO "{"
    sdl-declaration ;
    [ ... ]
"}" ;

CREATE MIGRATION defines a migration of the schema to a new state. The target schema state is described using SDL and the migration generates the necessary DDL commands behind the scenes based on the current and the target state.

Important: CREATE MIGRATION and the follow-up COMMIT MIGRATION must be executed in a transaction block.

[ module-alias := ] MODULE module-name

An optional list of module alias declarations to be used in the migration definition. When module-alias is not specified, module-name becomes the effective current module and is used to resolve all unqualified names.

name

The name of the new migration. If qualifed with a module name, the migration is created for that module, otherwise the effective current module is used.

sdl-declaration

Module contents defined using the declarative EdgeDB schema definition language.

Create a new migration to a target schema specified by the EdgeDB Schema syntax:

CREATE MIGRATION init TO {
    module default {
        type User {
            property username -> str
        }
    }
};

Apply the given migration to the database.

COMMIT MIGRATION name ;

COMMIT MIGRATION runs the DDL commands defined by the given migration. Once the migration is committed, it cannot be dropped.

Important: COMMIT MIGRATION must be executed in a transaction block.

name

The name of the migration to commit.

Commit the “alter_tx” migration:

COMMIT MIGRATION init;

Discard a migration.

DROP MIGRATION name ;

DROP MIGRATION discards the given migration. Once a migration has been applied using a COMMIT MIGRATION command, it cannot be discarded.

name

The name of the migration to discard.

Remove the “init” migration:

DROP MIGRATION init;