Tane means seeds.
# priv/repo/seeds.exs
use Tane
repo(MyApp.Repo)
|> model(MyApp.User)
|> seed(name: "Bob", email: "bob@black.com")
|> seed(name: "Mary", email: "mary@blue.com")
Then do this.
$ mix tane
You can specify the path.
$ mix tane --path priv/another_repo/seeds.exs
If you want to delete all data before seeding, delete_all!/1
is useful.
repo(MyApp.Repo)
|> model(MyApp.User) # have to register these two before delete_all!.
|> delete_all!
|> seed(name: "Bob", email: "bob@black.com")
Use registered/1
to get saved models.
use Tane
alias MyApp.User
alias MyApp.Post
alias MyApp.Repo
repo(Repo)
|> model(User)
|> seed(:bob, name: "bob")
|> seed(name: "mary")
|> model(Post)
|> seed(title: "Hello", body: "I'm bob", user_id: registered(:bob).id)