bullet-train-pro / bullet_train-action_models

Other
5 stars 1 forks source link

Are `PerformsImport` and `PerformsExport` deprecated? #102

Closed jagthedrummer closed 4 months ago

jagthedrummer commented 5 months ago

The PerformsImport and PerformsExport actions aren't documented: https://bullettrain.co/docs/action-models#action-types

And it's currently impossible to generate either one.

But we occasionally get questions about them.

The description for TargetsOneParent (https://bullettrain.co/docs/action-models#targets-one-parent) sounds like it's intended to be used for import actions. And it seems like it would also work for export actions.

Is it true that PerformsImport and PerformsExport should be deprecated and removed in favor of a more general TargetsOneParent?

jagthedrummer commented 5 months ago

I did a little futzing with the core repo (locally) to add a generator for PerformsImport and then ran some tests to compare PerformsImport with TargetsOneParent.

First I generated a Widget super scaffold:

rails g super_scaffold Widget Team name:text_field; rails db:migrate
rails db:migrate

Then I generated a PerformsImport:

rails g super_scaffold:action_models:performs_import Import Widget Team
rails db:migrate

And I also generated a TargetsOneParent:

rails g super_scaffold:action_models:targets_one_parent TargetedImport Widget Team
rails db:migrate

Now I have a couple of new options in the widget list:

CleanShot 2024-06-12 at 12 32 48

Clicking on "Import" gets me to this screen which has some options around actually performing an import:

CleanShot 2024-06-12 at 12 33 51

But clicking on "Targeted Import" gets me to this screen which doesn't offer any options:

CleanShot 2024-06-12 at 12 34 54

So PerformsImport seems to offer some built-in functionality that's missing with TargetsOneParent. I'm guessing you could implement an import action via TargetsOneParent but it seems like PerformsImport offers some useful functionality.

jagthedrummer commented 5 months ago

OK, I also cracked open the code for the PerformsImport and PerformsExport base classes and they definitely implement features that aren't present in the Targets* classes.

In fact PerformsImport directly includes the TargetsOne concern (not TargetsOneParent) and PerformsExport directly imports TargetsMany. So they use the Targets* building blocks and then implement functionality over the top of them.

I think we need to add generators and documentation for these two.

gazayas commented 4 months ago

@jagthedrummer I remember these two not being fully documented, and since I didn't help to build them I didn't move forward with any documentation/further implementation.

I do remember however talking with Andrew about these briefly, and the use-case for them was mainly for importing/exporting CSVs, which is reflected in the system tests.

If it helps, I also worked on a fun PR for import actions which uses OpenAI to guess which CSV column most closely matches the database model in question.

I'm not entirely sure what other use-cases we have for these actions though.

jagthedrummer commented 4 months ago

Added generators here: https://github.com/bullet-train-co/bullet_train-core/pull/853