mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
doc/md/versioned: fixes to tutorial (#3102)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user