anykeyh/clear

where to place seed files?

sam0x17 opened this issue · 4 comments

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?

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

thanks!

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.

Not yet, better to get a Cakefile indeed :-)