Versioned Migrations

    In order to have Ent make the necessary changes to your code, you have to enable this feature with one of the two options:

    1. If you are using the default go generate configuration, simply add the to the file as follows:
    1. If you are using the code generation package (e.g. if you are using an Ent extension), add the feature flag as follows:

    After regenerating the project, there will be an extra method on the Ent client that you can use to inspect the connected database, compare it with the schema definitions and create sql statements needed to migrate the database to the graph.

    From Graph

    You can also generate new migration files without an instantiated Ent client. This can be useful if you want to make the migration file creation part of a go generate workflow.

    The Atlas migration engine does not support applying the migration files onto a database yet, therefore to manage and execute the generated migration files, you have to rely on an external tool (or execute them by hand). By default, Atlas generates one “up” and one “down” migration file for the computed diff. These files are compatible with the popular package, and you can use that tool to manage the migrations in you deployments.

    In case you already have an Ent application in production and want to switch over from auto migration to the new versioned migration, you need to take some extra steps.

    1. Configure the tool you use to manage migrations to consider this file as applied.

      In case of this can be done by forcing your database version as described here.