Multi-tenant Laravel for 40 koperasi: one database with tenant_id, or one database per tenant?
Hello all. I maintain a savings and loan system (koperasi simpan pinjam) used by 40 cooperatives. Same features for all, each has 2,000 to 20,000 members. Laravel 10, PHP 8.2, MySQL 8, one VPS.
Now it is single database, every table has koperasi_id, and I use a global scope:
class KoperasiScope implements Scope
{
public function apply(Builder $builder, Model $model): void
{
$builder->where(
$model->getTable().'.koperasi_id',
auth()->user()->koperasi_id
);
}
}
My worry: one day a developer forgets the scope (or uses DB::table()) and koperasi A see the members of koperasi B. For savings data this is very bad. So I am thinking to move to database per tenant (maybe with stancl/tenancy).
But I am not sure about:
- migrations on 40 databases every deploy
- backups, some koperasi ask "give us a copy of only our data"
- the government office (dinas) wants one report across all koperasi every month
- cost, all on one MySQL server
For the case of 40 tenants with same schema, which one you will choose? Thank you 🙏
Accepted answer
Get the best of #php_still_pays weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to commentAccepted answer