Skip to content

Instantly share code, notes, and snippets.

@havvg
Created June 6, 2012 12:53
Show Gist options
  • Save havvg/2881652 to your computer and use it in GitHub Desktop.
Save havvg/2881652 to your computer and use it in GitHub Desktop.
Propel 1.6: Archivable with Versionable
<?xml version="1.0" encoding="UTF-8"?>
<database name="default" defaultIdMethod="native" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd">
<table name="entry" phpName="Entry">
<column name="id" type="integer" autoIncrement="true" primaryKey="true" />
<column name="value" type="varchar" size="255" required="true" />
<behavior name="archivable">
<parameter name="archive_on_insert" value="true" />
<parameter name="archive_on_update" value="true" />
<parameter name="archive_on_delete" value="true" />
<parameter name="log_archived_at" value="false" />
</behavior>
</table>
<table name="entry_archive" phpName="EntryArchive">
<column name="id" type="integer" autoIncrement="false" primaryKey="true" />
<column name="value" type="varchar" size="255" required="true" />
<column name="archived_at" type="timestamp" />
<behavior name="versionable">
<parameter name="log_created_at" value="true" />
<parameter name="log_created_by" value="true" />
<parameter name="log_comment" value="true" />
</behavior>
</table>
</database>
@willdurand
Copy link

So, how do you use that? You create versions just for archives?

@havvg
Copy link
Author

havvg commented Jun 11, 2012

Technically, yes.
The use-case is, I want to keep all versions after deleting the versioned object.

The archive (from ArchivableBehavior) is created on any change, thus creating a new version.
As there is no ForeignKey between the archive and the live object, it can be kept after deleting the object.
The version of an object (from VersionableBehavior) is bound to the object with a ForeignKey, so deleting the object will also delete all versions.

A combination of those behaviors allows to keep the data after deletion, including all versions.

@havvg
Copy link
Author

havvg commented Jun 11, 2012

In addition it also allows the deletion of every version with ease: you just delete the archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment