Open nelsonic opened 6 years ago
After looking into this, it doesn't appear to be possible to modify a schema without completely redefining the Ecto.Schema function. The most we can do is throw an error, or display a warning if the required field is not present in the schema.
The same is true of the :deleted
column in the database, although there is a conventional way that we could add it here, which is by turning this module into an Ecto Adapter, which would define its own migration module. This would likely involve a lot of work though, would significantly change the API, and probably wouldn't be different enough from the standard Postgres Adapter to be worth it.
@nelsonic What do you think? Is adding a warning that a deleted field is needed enough?
@Danwhy good question, if we are unable to "inject" the additional fields into the schema
perhaps we can group all the alog
related fields at the end of the schema definition?
A warning would be a good checkpoint to help remind people using alog
.
For now avoid the Ecto Adapter work unless it will make the use of alog
significantly easier for other devs implementing this.
Thinking a little further, it might be good to actually throw an error rather than just a warning, as most of the functions won't actually work without a :deleted
field.
While there may be some use cases that don't actually need to use a :deleted
column, and maybe we should eventually look at making it possible to not require it, for now we'll leave it in and throw an error if it doesn't exist.
As a developer creating Phoenix Web Apps/APIs using
alog
, I would like to have the:deleted
column added to each schema/table wherealog
is used. So that I don't have to manually add the:deleted
column or think about how to "delete" records.Todo
:deleted
field to a schema when theuse AppendOnlyLog
is employed.README.md
so it's clear to people why this column is needed/added.as initially discussed in https://github.com/dwyl/phoenix-ecto-append-only-log-example/issues/7#issuecomment-431863209