Skip to content

Add ability to generate resources from existing postgres as fragments #437

Open
@alykhanjetha

Description

@alykhanjetha

Is your feature request related to a problem? Please describe.
The current implementation of ash_postgres.gen.resources assumes that one porting an existing application to Ash. This is likely not the most common case, as it is rare that someone would abandon an existing app and a new one in a different language.

Instead, it is likely that migration from another environment is gradual and the management of the low level schema would remain in the original app for a while initially.

This means that the PG schema is really externally managed and likely to change -- which means I would have to manually edit my previously generated resources. This is error prone!

Describe the solution you'd like
Add an --use_fragments option to the generator.
This would generate the attributes and relationships in a separate fragment file.
If the resource does not exist (the first you run the generator), then the resource is created with a link to the fragment.

defmodule MyApp.Person do
  use Ash.Resource,
    domain: MyApp.Persons,
    fragments: [MyApp.Persons.Person.Model]

end

With this, person_model.ex can be regenerated at will. It would not alter or edit person.ex and all actions, calculations, changes etc... would be maintained.

Additional context

This argument is really about easing Elixir/Ash adoption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions