Packages · Private
Laravel Cold Storage
Move a model's old rows out of the live table into an archive, and Order::find($id) goes on returning them.
The problem
A table grows for years. Most of its rows are closed and nobody reads them. Every scan and every index on that table still carries all of them.
The usual fix is an "archived" flag and a rule that hides the old rows. That hides them from queries. They are still in the table, so the table is no smaller.
The idea
Cold storage moves the old rows out: to a second table, to another database, or to a store you write yourself. The model keeps working. Looking a record up by its id still returns it, whichever place it lives in.
The rest of the application does not have to know that anything moved.
How it works
- You say what "cold" means: untouched for 90 days, older than six months and closed, or a rule of your own. Rules combine, and a rule can hold rows back.
- You say where cold rows go. A second table, another database connection, or your own store.
- A mover does the work, on a schedule if you want one. It copies rows in chunks, checks each chunk by row count and checksum, and only then deletes the live rows.
- A dry run tells you what would move, and moves nothing.
- Saving an archived record puts it back in the live table first.
The rule it will not break
A query that includes archived rows gets the complete answer, or it gets an error. It never quietly answers from the live rows alone.
Ordinary queries read the live table only, so nothing pulls the whole archive back by accident. To include the archive, you ask for it.
Where it fits
A table where most rows are old and rarely read, and the application still has to open one by its id now and then: closed orders, sent messages, settled payments.
Interested?
I keep Laravel Cold Storage private. If you would like it running in your company, or you want to talk through how it would fit, email me.