doc/md/versioned: fixes to tutorial (#3102)

This commit is contained in:
Rotem Tamir
2022-11-17 11:04:53 +02:00
committed by GitHub
parent 5954fa8b15
commit a5aadd7737
3 changed files with 11 additions and 6 deletions

View File

@@ -76,8 +76,6 @@ After running the code-generation, you should see the following
to `ent/migrate/migrate.go`:
* `Diff`
* `NamedDiff`
* `Schema.Diff`
* `Schema.NamedDiff`
These methods are used to compare the state read from a database connection or migration directory with the state defined
by the Ent schema.

View File

@@ -59,10 +59,17 @@ import (
_ "github.com/go-sql-driver/mysql"
)
const (
dir = "ent/migrate/migrations"
)
func main() {
ctx := context.Background()
// Create a local migration directory able to understand Atlas migration file format for replay.
dir, err := atlas.NewLocalDir("ent/migrate/migrations")
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatalf("creating migration directory: %v", err)
}
dir, err := atlas.NewLocalDir(dir)
if err != nil {
log.Fatalf("failed creating atlas migration directory: %v", err)
}
@@ -78,7 +85,7 @@ func main() {
}
// Generate migrations using Atlas support for MySQL (note the Ent dialect option passed above).
//highlight-next-line
err = migrate.NamedDiff(ctx, "mysql://root:pass@localhost:3306/test", os.Args[1], opts...)
err = migrate.NamedDiff(ctx, "mysql://root:pass@localhost:3306/dev", os.Args[1], opts...)
if err != nil {
log.Fatalf("failed generating migration file: %v", err)
}

View File

@@ -19,12 +19,12 @@ to our `User` entity, adding a new optional field named `title`:
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
// highlight-start
field.String("email"). // <-- Our new field
Unique(),
// highlight-end
// highlight-start
field.String("title").
Optional(),
// highlight-end
}
}
```