@@ -121,7 +121,7 @@ docker run --name migration --rm -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTG
1211212\. Create a ` main.go ` file under the ` migrate/ent ` package and customize the migration generation for your project.
122122
123123<Tabs
124- defaultValue = " golang_migrate "
124+ defaultValue = " atlas "
125125values = { [
126126{label: ' Atlas' , value: ' atlas' },
127127{label: ' golang-migrate/migrate' , value: ' golang_migrate' },
@@ -410,29 +410,21 @@ For example:
410410go run -mod=mod ent/migrate/main.go create_users
411411```
412412
413- Run ` ls ent/migrate/migrations ` after the command above was passed successfully, and you will notice Atlas created 3
413+ Run ` ls ent/migrate/migrations ` after the command above was passed successfully, and you will notice Atlas created 2
414414files:
415415
416416<Tabs
417- defaultValue = " migration_file_up "
417+ defaultValue = " migration_file "
418418values = { [
419- {label: ' 20220811114629_create_users.up.sql' , value: ' migration_file_up' },
420- {label: ' 20220811114629_create_users.down.sql' , value: ' migration_file_down' },
419+ {label: ' 20220811114629_create_users.sql' , value: ' migration_file' },
421420{label: ' atlas.sum' , value: ' sum_file' },
422421]} >
423- <TabItem value = " migration_file_up " >
422+ <TabItem value = " migration_file " >
424423
425424``` sql
426425-- create "users" table
427426CREATE TABLE `users ` (` id` bigint NOT NULL AUTO_INCREMENT, PRIMARY KEY (` id` )) CHARSET utf8mb4 COLLATE utf8mb4_bin;
428- ```
429-
430- </TabItem >
431- <TabItem value = " migration_file_down" >
432427
433- ``` sql
434- -- reverse: create "users" table
435- DROP TABLE ` users` ;
436428```
437429
438430</TabItem >
@@ -443,8 +435,9 @@ to ensure the integrity of the migration directory and force developers to deal
443435where migration order or contents were modified after the fact.
444436
445437``` text
446- h1:NRHsNIjvSSzprr/EzMdtszQg3t3pVLk4G4N1tX4rMfk=
447- 20220811114629_create_users.up.sql h1:Ng3GHrdk2davokjOctgVdxC+6QsK4JzaLX6RT3QstJc=
438+ h1:vj6fBSDiLEwe+jGdHQvM2NU8G70lAfXwmI+zkyrxMnk=
439+ 20220811114629_create_users.sql h1:wrm4K8GSucW6uMJX7XfmfoVPhyzz3vN5CnU1mam2Y4c=
440+
448441```
449442
450443</TabItem >
@@ -548,26 +541,17 @@ longer needed after the first one.
548541
549542## Apply Migrations
550543
551- The Atlas migration engine has only experimental support applying the migration files onto a database yet. Therefore,
552- to manage and execute the generated migration files for production systems it is recommended you use on an external tool
553- (or execute them by hand). By default, Ent generates one "up" and one "down" migration file for the computed diff. These
554- files are compatible with the popular [ golang-migrate/migrate] ( https://github.com/golang-migrate/migrate ) package, and
555- you can use that tool to manage the migrations in your deployments.
544+ Ent recommends to use the Atlas CLI to apply the generated migration files onto the database. If you want to use any
545+ other migration management tool, Ent has support for generating migrations for several of them
546+ out of the box.
556547
557548``` shell
558- migrate -source file://migrations -database mysql://root:pass@tcp(localhost:3306)/test up
549+ atlas migrate apply \
550+ --dir " file://migrations"
551+ --url mysql://root:pass@localhost:3306/ent
559552```
560553
561- :::note
562-
563- If you use golang-migrate with MySQL, you need to add the ` multiStatements ` parameter to ` true ` as in the example below
564- and then take the DSN we used in the documents with the param applied.
565-
566- ```
567- "user:password@tcp(host:port)/dbname?multiStatements=true"
568- ```
569-
570- :::
554+ For more information head over the the [ Atlas documentation] ( https://atlasgo.io/versioned/apply ) .
571555
572556## Moving from Auto-Migration to Versioned Migrations
573557
@@ -603,11 +587,17 @@ above (`users,groups`) but your deployed table looks like the one below (`groups
603587You can see, that the order differs. In that case, you have to manually change both the entries in the generated
604588migration file.
605589
606- ### Configure the tool you use to manage migrations to consider this file as applied
590+ ### Use an Atlas Baseline Migration
607591
608- In case of ` golang-migrate ` this can be done by forcing your database version as
609- described
610- [ here] ( https://github.com/golang-migrate/migrate/blob/master/GETTING_STARTED.md#forcing-your-database-version ) .
592+ If you are using Atlas as migration execution engine, you can then simply use the ` --baseline ` flag. For other tools,
593+ please take a look at their respective documentation.
594+
595+ ``` shell
596+ atlas migrate apply \
597+ --dir " file://migrations"
598+ --url mysql://root:pass@localhost:3306/ent
599+ --baseline " <version>"
600+ ```
611601
612602## Atlas migration directory integrity file
613603
0 commit comments