PHPackages                             josegonzalez/cakephp-version - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. josegonzalez/cakephp-version

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

josegonzalez/cakephp-version
============================

CakePHP ORM behavior to allow versioning of records

5.0.0(2y ago)49145.2k↑41.5%18[6 issues](https://github.com/josegonzalez/cakephp-version/issues)[1 PRs](https://github.com/josegonzalez/cakephp-version/pulls)MITPHPPHP ^8.1

Since May 17Pushed 2y ago4 watchersCompare

[ Source](https://github.com/josegonzalez/cakephp-version)[ Packagist](https://packagist.org/packages/josegonzalez/cakephp-version)[ Docs](https://github.com/josegonzalez/cakephp-version)[ RSS](/packages/josegonzalez-cakephp-version/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (16)Used By (0)

[![Build Status](https://camo.githubusercontent.com/2f70c73309137129eb6dc83084068dccada05cb8ccc3a17197016d51c9449c44/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f7365676f6e7a616c657a2f63616b657068702d76657273696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/josegonzalez/cakephp-version)[![Coverage Status](https://camo.githubusercontent.com/c7873bcd5f3eca6165705b59a4da00351d7245ca706bb39ccbd194a5be02e075/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a6f7365676f6e7a616c657a2f63616b657068702d76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/josegonzalez/cakephp-version?branch=master)[![Total Downloads](https://camo.githubusercontent.com/5644919467e39da9bb03434e13086feb156684c2039093252733e8b15d53c11c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7365676f6e7a616c657a2f63616b657068702d76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/cakephp-version)[![Latest Stable Version](https://camo.githubusercontent.com/12b6019eb15365c0ac8acdc019f6a665b1485ed20b07803e8413aecd7980bff1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7365676f6e7a616c657a2f63616b657068702d76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/cakephp-version)[![Documentation Status](https://camo.githubusercontent.com/9785bb7ace0bbced65e5c8b016a3571df7a954ec8c7350173294087e10bce76a/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f63616b657068702d76657273696f6e2f62616467652f3f76657273696f6e3d6c6174657374267374796c653d666c61742d737175617265)](https://readthedocs.org/projects/cakephp-version/?badge=latest)[![Gratipay](https://camo.githubusercontent.com/40a48c7b3fc02e9d39dd715fe09e404c4cb2e89288c6ace0773d2aab6913b46f/68747470733a2f2f696d672e736869656c64732e696f2f67726174697061792f6a6f7365676f6e7a616c657a2e7376673f7374796c653d666c61742d737175617265)](https://gratipay.com/~josegonzalez/)

Version
=======

[](#version)

A CakePHP 4.x plugin that facilitates versioned database entities

Installation
------------

[](#installation)

Add the following lines to your application's `composer.json`:

```
"require": {
    "josegonzalez/cakephp-version": "dev-master"
}
```

followed by the command:

`composer update`

Or run the following command directly without changing your `composer.json`:

`composer require josegonzalez/cakephp-version:dev-master`

Usage
-----

[](#usage)

In your app's `config/bootstrap.php` add:

```
Plugin::load('Josegonzalez/Version', ['bootstrap' => true]);
```

Usage
-----

[](#usage-1)

Run the following schema migration:

```
CREATE TABLE `version` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `version_id` int(11) DEFAULT NULL,
    `model` varchar(255) NOT NULL,
    `foreign_key` int(10) NOT NULL,
    `field` varchar(255) NOT NULL,
    `content` text NULL,
    `created` datetime NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

> Note that the `content` field must be nullable if you want to be able to version any nullable fields in your application.

> You may optionally add a `version_id` field of type `integer` to the table which is being versioned. This will store the latest version number of a given page.

If you wish to create the table using `cakephp/migrations` then you will need to use a migration that looks something like this:

```
