dwyl / alog

🌲 alog (Append-only Log) is an easy way to start using the Lambda/Kappa architecture in your Elixir/Phoenix Apps while still using PostgreSQL (with Ecto).
GNU General Public License v2.0
15 stars 2 forks source link

add :deleted column to any schema that uses alog #5

Open nelsonic opened 6 years ago

nelsonic commented 6 years ago

As a developer creating Phoenix Web Apps/APIs using alog, I would like to have the :deleted column added to each schema/table where alog is used. So that I don't have to manually add the :deleted column or think about how to "delete" records.

Todo

as initially discussed in https://github.com/dwyl/phoenix-ecto-append-only-log-example/issues/7#issuecomment-431863209

Danwhy commented 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?

nelsonic commented 6 years ago

@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.

Danwhy commented 6 years ago

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.