Add a way to persist a calculation for a resource

Aperta
#383 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
elixir, postgresql
Ambito
databases

Direzione di ricerca

Non sono indicati file sorgente né test. Inizia tracciando come gli attributi generati delle risorse Ash diventano migrazioni PostgreSQL/Ecto, quindi confronta le proposte generate_with e persist? con gli esempi di Ecto sulle colonne generate con add/3. Il lavoro è completato quando un’interfaccia di risorsa concordata produce la migrazione corretta per la colonna generata e copre con test i casi di calcolo e raw-SQL.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Is your feature request related to a problem? Please describe.
When defining generated attributes for a resource, I often see people needing to manually edit the migration to use ALTER TABLE to explicitly add the column with the SQL statement used to populate the column.

Describe the solution you'd like
A way to in an Ash resource to define an attribute that is generated, specify the raw SQL statement to populate the field, and have the generated migration use the Ecto syntax for configuring such a column shown here

Describe alternatives you've considered
Continue manually changing migrations or replace generated attribute with calculations that are not persisted in a column

Express the feature either with a change to resource syntax, or with a change to the resource interface

Idea 1 - generate_with attribute option

Using calculation
  attributes do
    attribute :generated_foo, :string, generate_with: :full_name
  end

  calculations do
    calculate :full_name, :string, expr(first_name <> " " <> last_name)
  end
Using raw SQL
  attributes do
    attribute :generated_foo, :string, generate_with: expr(fragment("? || ' ' || ?", first_name, last_name))
  end

Idea 2 - persist calculation option

  calculations do
    calculate :full_name, :string, expr(first_name <> " " <> last_name)

    persist? true
  end

Additional context
Link to the start of the conversation in the Elixir Discord server that lead to this proposal: message

Lingua principale
Elixir
Stelle
191
Fork
186
Merge medio
16h 4m
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ash-project/ash_postgres

Tutte le issue di ash-project/ash_postgres

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.