luckyframework / avram

A Crystal database wrapper for reading, writing, and migrating Postgres databases.
https://luckyframework.github.io/avram/
MIT License
165 stars 64 forks source link

Should we require "avram/src/lucky/tasks/gen/model" as default? #892

Open zw963 opened 1 year ago

zw963 commented 1 year ago

I consider following gen.model task is a key component of avram, right?

▸ gen.model Generate a model, query, and operations (save and delete)

I add lucky binary to my $PATH for my current laptop login user, yes, it serve as a common command for all my avram project.

When i running lucky --help on my project which use 1.0.0-rc1 avram, there is no gen.model task.

For now, i have to require "avram/src/lucky/tasks/gen/model" manually in tasks.cr to make this task available

# See `LuckyEnv#task?`
ENV["LUCKY_TASK"] = "true"

require "./src/config/database"
require "avram/src/lucky/tasks/gen/model"
require "lucky_task"
require "./tasks/**"

LuckyTask::Runner.run
 ╰─ $ lucky --help
Usage: lucky name.of.task [options]

Available tasks:

  ▸ db.console             Access PostgreSQL console
  ▸ db.create              Create the database
  ▸ db.drop                Drop the database
  ▸ db.migrate             Run any pending migrations
  ▸ db.migrate.one         Run just the next pending migration
  ▸ db.migrations.status   Print the current status of migrations
  ▸ db.redo                Rollback and run just the last migration
  ▸ db.reset               Drop, recreate, and run migrations.
  ▸ db.rollback            Rollback the last migration
  ▸ db.rollback_all        Rollback all migrations
  ▸ db.rollback_to         Rollback to a specific migration
  ▸ db.schema.dump         Export database schema to a sql file
  ▸ db.schema.restore      Restore database from a sql dump file
  ▸ db.seed.required_data  Add database records required for the app to work
  ▸ db.seed.sample_data    Add sample database records helpful for development
  ▸ db.setup               Runs a few tasks for setting up your database
  ▸ db.verify_connection   Verify connection to postgres
  ▸ gen.migration          Generate a new migration
  ▸ gen.model              Generate a model, query, and operations (save and delete)

I consider this is not necessory, right?

I test on avram 1.0.0-rc1 with lucky-cli 1.0.0-rc1 binary but without add lucky as project dependency.

jwoertink commented 1 year ago

I don't think so because if you're not using Lucky, then you don't want that to become a default dependency.

For Lucky apps, we just include all of the tasks:

https://github.com/luckyframework/lucky_cli/blob/9dba5f7f2fd961f382706fa37fc3fb3da6006328/src/web_app_skeleton/tasks.cr#L23

Or you can include the individual ones you want like that.

zw963 commented 1 year ago

I don't think so because if you're not using Lucky, then you don't want that to become a default dependency.

Don't understand what you means, there is no external dependency, those files are included with avram, right? i consider we should move above require "avram/lucky/tasks" into avram, what do you think?

BTW: i am current still not use lucky, but i always use lucky gen.model SomeModel to generate my model files when use avram.

zw963 commented 1 year ago

@jwoertink , any idea?

jwoertink commented 1 year ago

I'll have to think about this when I get back from vacation next week.

Maybe @matthewmcgarvey has some thoughts?

matthewmcgarvey commented 1 year ago

I'm fine with moving gen.model and any other of the tasks that don't require lucky into the normal avram tasks directory https://github.com/luckyframework/avram/tree/main/src/avram/tasks

I don't know if you're familiar with the history but we recently moved all of the src/lucky/ext/ code from the lucky codebase. It was more of a copy/paste than anything so there could be more code in there that could be moved out since it doesn't directly depend on Lucky.

zw963 commented 1 year ago

I don't know if you're familiar with the history but we recently moved all of the src/lucky/ext/ code from the lucky codebase.

Probably not so familiar with the history, but i do know those move operation.

since it doesn't directly depend on Lucky.

yes, i consider gen.model is one part of avram, anyone use avram don't want create those template files himself.