WendellAdriel / laravel-exa

Opinionated Modularized API Skeleton for Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel ExA use default database Postgresql

msoares94 opened this issue · comments

Firstly, thank you for the amazing work with Laravel ExA.

Following the recent changes, I noticed that the SoftDeletes concept was added and this is great for auditing and data recovery. From what I noticed, UserActions was also added, this made the template more robust.

However, I would like to raise the following logical question, thinking about making the temple more robust.

Given that when using SoftDelete the records are now marked as logically deleted, that is, the "deleted_at" field is different from null, I suggest defining the Postgresql Database as the default for the template, considering that Postgresql supports uniqueness restrictions composed disregarding records marked as deleted by softDeletes, and this meets some business need to have, for example, a table with compound uniqueness.

Example:

TableA with $table->unique(['colunaA', 'colunaB']

Event flow

  • Register a record with the values: ColumnValueA1, ColumnValue2
  • Delete the record (This will make the record marked as deleted)
  • I try to create a new record with the same values ​​ColumnValueA1, ColumnValue2
  • MySQL will throw an exception as it does not support uniqueness, disregarding softDeletes records

I love PgSQL and I think it's great for a lot of applications, however, the most used DB with PHP/Laravel is still MySQL AFAIK, so I'd prefer to keep MySQL as the default DB and if someone needs to change, they can easily change it by doing some changes in the Docker configuration.

For this issue with MySQL, you can try this workaround:
https://gusiol.medium.com/soft-delete-and-unique-constraint-da94b41cff62