pierrefourgeaud

pierrefourgeaud

I have been working on a platform where we have to manage some kind of documents and particularly the versioning. I have the rest of the platform up and running with most of the stuff done but here come the central piece: The document management.

For the POC I did something simple for testing in the lights of:

  schema "documents" do
    field :title, :string
    field :body, :string
    belongs_to :organisation, MyApp.Organisations.Organisation

    timestamps(type: :utc_datetime)
  end

It works well - we validated our idea and are now going to the next step.

But now comes the part where I will need to manage versions and state of the documents.

I came up with something like this:

  schema "documents" do
    # more fields
    field :draft_version, :integer
    field :published_version, :integer
    belongs_to :organisation, MyApp.Organisations.Organisation

    timestamps(type: :utc_datetime)
  end

  schema "document_versions" do
    field :title, :string
    field :body, :string
    field :version, :integer

    # this has_one doesn't work and I think I will change it to belongs_to
    has_one :author, MyApp.Accounts.User
    belongs_to :document, MyApp.Documents.Document

    timestamps(type: :utc_datetime)
  end

It looks OK I guess. We will not have millions of documents and with index on the version with version/document I guess that will work.

But now comes the time to have the forms. A “new” document will basically create a document and the first version. “Edit” a document will create a new version (loading the content from the previous version) for a document.

I have been struggling with that side. I am using live_view from the frontend and I started to look for embedded forms to get that going.
That’s where I stumbled upon the embedded_schemas… I was wondering if this would be actually a fit for my use-case. I am still relatively new in Elixir/Phoenix/Ecto and learning around that. What would be the recommendation for a case like this?

Showing Posts 1 to 5

LostKobrakai

LostKobrakai

I’d suggest ignoring forms for a bit. Make the underlying business logic work (e.g. using tests) and only then figure out how to can make LV provide the necessary data to your core APIs and to which part and how those values need to be provided by the user with a form vs directly from e.g. the LV state.

mayel

mayel

Not really an answer to your question, but have you considered using a library for the versioning, such as GitHub - izelnakri/paper_trail: Track and record all the changes in your database with Ecto. Revert back to anytime in history. · GitHub ?

pierrefourgeaud

pierrefourgeaud OP

That’s how I started and actually the second version I mention is actually what I have with some tests and it works just fine. Where I am more struggling it is how to make the LV and that’s also when I got to find the embedded_schemas and wondered if that would be useful there…

pierrefourgeaud

pierrefourgeaud OP

Thanks for the tip. I actually looked for it but didn’t find anything. It seems that this could simply do the job but it also seems that it hasn’t been updated in 2 years. I am wondering if this could become an issue on the long run…

mayel

mayel

I’m using it quite happily (well a forked repo, since the maintainer seems slow on merges but has been occasionally responsive: a few things by mayel · Pull Request #224 · izelnakri/paper_trail · GitHub )

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews