amnesia icon indicating copy to clipboard operation
amnesia copied to clipboard

[FEATURE] - Default Mix tasks

Open cs-victor-nascimento opened this issue 8 years ago • 9 comments

I think it would help a lot to have some default mix tasks like create|drop|migrate (same as those found in ecto for easier understanding). Your example of install/uninstall in the README is pretty much what everybody does when starting a project with amnesia INMHO.

We would only need to support something like:

mix amnesia.create --database MyDatabase (more options)

Options I can think of are:

  • --no-schema: would not create the mnesia schema
  • --disc: would create passing the option disc:[node()]
  • --disc-only: same as above but with disc only on node ... and other mnesia options.

To support migrate we could have some behaviour that would export a migrate function and we would receive the user module implementing that function. Again, close to Ecto's idiom.

I was starting out a PR but thought that it would be better to ask for opinions first. What do you think @meh?

cs-victor-nascimento avatar Sep 26 '15 20:09 cs-victor-nascimento

Sounds good to me, go for it :+1:

meh avatar Sep 26 '15 21:09 meh

Just so I get this right, I will use the following default values:

  • schema: true (will create schema before starting mnesia)
  • disc: true (this might be controversial, but it will follow README's task)
  • disc-only: false (only one of disc or disc-only will be allowed)

Drop task will accept an option --no-schema to destroy only the database. Defaults to false destroying also the schema.

Also, to make it easier to detect that the module is an amnesia database, I think we should add an __amnesia__/0 function. What do you think?

Migrate will probably go in a different PR...

cs-victor-nascimento avatar Sep 26 '15 23:09 cs-victor-nascimento

How would that function be used?

meh avatar Sep 27 '15 00:09 meh

Much like this line in Mix.Ecto.

I can also detect if the module has a defdatabase!/2 function... I guess it is not necessary to introduce a new function...

cs-victor-nascimento avatar Sep 27 '15 00:09 cs-victor-nascimento

Actually I will call metadata and check it returns a %Amnesia.Metadata{database: module}.

cs-victor-nascimento avatar Sep 27 '15 14:09 cs-victor-nascimento

[x] - Create mix task [x] - Drop mix task [ ] - Migrate mix task

cs-victor-nascimento avatar Sep 30 '15 19:09 cs-victor-nascimento

Hello guys,

First of, #42

Second, if these new and shiny mix tasks are part of the official readme on the front page, they should also be part of the latest release people get when they install amnesia using hex. So maybe we should create a new release with the current master?

matehat avatar Jan 08 '16 20:01 matehat

@matehat released a new version.

meh avatar Jan 08 '16 21:01 meh

:+1:

matehat avatar Jan 08 '16 21:01 matehat