Download the PHP package kdabrow/time-machine without Composer
On this page you can find all versions of the php package kdabrow/time-machine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package time-machine
Time machine
This package allows to move in time database data. It automatically selects all fields that store datetime and move them by given period or to particular date, relatively from it current value. See example to check more details.
Motivation
This package might be useful in a pre-prod environment to test log lasting processes. For example
generating customer invoice. Usually invoices are generated in a 30 days period. You might move
customer and all it's data into previous invoice cycle (30 days in to past) and effectively simulate
whole invoice cycle like that customer was created 30 days ago.
Installation
First install main package:
Then install database driver package:
Database | Driver |
---|---|
mysql | |
postgres |
Advice is to install those packages as --dev dependencies.
Usage
Time traveller setup
First create TimeTraveller. Only Eloquent model can be TimeTraveller. Basic configuration look like this:
Modify query
TimeMachine by default selects all rows related to given to TimeTraveller model. You're able to provide your conditions to restrict query
Additional columns
It's possible to add additional columns into query.
Exclude fields
Sometimes is need to omit some fields that would usually be selected to change.
Set up keys
Records selected to time travel are based on primary key from the model. You're able to overwrite it.
Time machine and direction of move
After TimeTravellers are created, create TimeMachine.
Move to the past
First create DateChooser. It is information about period or date.
Move to the future
First create DateChooser. It is information about period or date.
Move to particular date
First create DateChooser. It is information about period or date.
Examples
Move customer, it's payments and orders 10 days in the past
Database structure before and after change:
customers (before)
id | date_of_birth | activated_at | created_at | updated_at | |
---|---|---|---|---|---|
100 | [email protected] | 1856-07-10 | 2000-06-15 12:12:12 | 1999-06-15 12:12:12 | 1999-06-15 12:12:12 |
customers (after)
id | date_of_birth | activated_at | created_at | updated_at | |
---|---|---|---|---|---|
100 | [email protected] | 1856-07-10 | 2000-06-05 12:12:12 | 1999-06-05 12:12:12 | 1999-06-05 12:12:12 |
payments (before)
id | customer_id | amount | paid_at | created_at | updated_at |
---|---|---|---|---|---|
200 | 100 | 120 | 2020-03-24 13:10:45 | 2020-03-24 10:10:45 | 2020-03-24 13:10:45 |
payments (after)
id | customer_id | amount | paid_at | created_at | updated_at |
---|---|---|---|---|---|
200 | 100 | 120 | 2020-03-14 13:10:45 | 2020-03-14 10:10:45 | 2020-03-14 13:10:45 |
orders
id | payment_id | name | sent_at | created_at | updated_at |
---|---|---|---|---|---|
300 | 200 | Engine | 2020-03-25 | 2020-03-24 13:11:22 | 2020-03-25 15:32:17 |
orders
id | payment_id | name | sent_at | created_at | updated_at |
---|---|---|---|---|---|
300 | 200 | Engine | 2020-03-15 | 2020-03-14 13:11:22 | 2020-03-15 15:32:17 |
Script:
Testing
Run tests from docker container
or directly from your machine