where to place seed files?
sam0x17 opened this issue · 4 comments
sam0x17 commented
I have a seed file with Clear.seed
defined. Where do I place it so when I run clear-cli migrate seed
it will seed the database?
anykeyh commented
Hello,
There's currently no clear-cli
binary.
How works the CLI is like this:
# In your entry point
# Example : src/entrypoints/server.cr
Clear.with_cli do
App.run # or Server.start or other, for example when I use it, it is Kemal.run
end
Then just call the cli using -- clear
:
# Seed
$ crystal run src/entrypoint/server.cr -- clear seed
# Migrate
$ crystal run src/entrypoint/server.cr -- clear migrate
# All command and subcommand have help for advanced usage:
$ crystal run src/entrypoint/server.cr -- clear migrate --help
Finally, if your application is using arguments and clear could be a legitimate word to use, you can manually call the CLI like in this example
# Example : src/entrypoints/cli.cr
require "clear/cli"
require "yourappfiles" #< Must require your models, seed and migrations
Clear::CLI.run # Run the CLI
In this case, you will build two binary, one for the CLI and one for your app.
$ crystal run src/entrypoint/cli.cr -- seed
sam0x17 commented
thanks!
sam0x17 commented
also by the way is there any way with the cli passthrough to drop and create the database? If not, I can make a Cakefile
for that.
anykeyh commented
Not yet, better to get a Cakefile indeed :-)