Catmandu::Plugin::Versioning(3pm) | User Contributed Perl Documentation | Catmandu::Plugin::Versioning(3pm) |
Catmandu::Plugin::Versioning - Automatically adds versioning to Catmandu::Store records
# Using configuration files $ cat catmandu.yml --- store: test: package: MongoDB options: database_name: test bags: data: plugins: - Versioning # Add two version of record 001 to the store $ echo '{"_id":"001",hello":"world"}' | catmandu import JSON to test $ echo '{"_id":"001",hello":"world2"}' | catmandu import JSON to test # In the store we see only the latest version $ catmandu export test to YAML --- _id: '001' _version: 2 hello: world2 # In the '_version' store we'll find all the previous versions $ catmandu export test --bag data_version to YAML --- _id: '001.1' data: _id: '001' _version: 1 hello: world # Or in your Perl program my $store = Catmandu->store('MongoDB', database_name => 'test' , bags => { data => { plugins => [qw(Versioning)] } }); $store->bag->add({ _id => '001' , hello => 'world'}); $store->bag->add({ _id => '001' , hello => 'world2'}); print "Versions:\n"; for (@{$store->bag->get_history('001')}) { print Dumper($_); }
The Catmandu::Plugin::Versioning plugin automatically adds a new 'version' bag to your Catmandu::Store containing previous versions of newly created records. The name of the version is created by appending '_version' to your original bag name. E.g. when add the Versioning plugin to a 'test' bag then 'test_version' will contain the previous version of all your records.
When using Catmandu::Store-s that don't have dynamic schema's (e.g. Solr , DBI) these new bags need to be predefined (e.g. create new Solr cores or database tables).
# catmandu.yml --- store: test: package: MongoDB options: database_name: test bags: data: plugins: - Versioning version_compare_ignore: - date_updated # In your perl # First version $store->bag->add({ _id => '001' , name => 'test' , date_updated => '10:00' }); # Second version (name has changed) $store->bag->add({ _id => '001' , name => 'test123' , date_updated => '10:00' }); # Second version (date_updated has changed but we ignored that in our configuration) $store->bag->add({ _id => '001' , name => 'test123' , date_updated => '10:15' });
# catmandu.yml --- store: test: package: MongoDB options: database_name: test bags: data: plugins: - Versioning version_transfer: - rights: # In your perl # First version $store->bag->add({ _id => '001' , name => 'test' , rights => 'Acme Corp.' }); # Second version we will try you delete rights but this is copied to the new version $store->bag->add({ _id => '001' , name => 'test'}); print "Rights: %s\n" , $store->bag->get('001')->{rights}; # Rights: Acme Corp.
my $store = Catmandu::Store::MyDB->new(bags => {book => {plugins => ['Versioning'], version_bag => 'book_history'}}); $store->bag('book')->version_bag->name # returns 'book_history'
Every bag that is configured with the Catmandu::Plugin::Versioning plugin can use the following methods:
Retrieve a record with identifier ID and version identifier VERSION. E.g.
my $obj = $store->bag('test')->get_version('001',1);
Retrieve the previous version of a record with identifier ID. E.g.
Returns an ARRAY reference with all the versions of the record with identifier ID.
Overwrites the current version of the stored record with identifier ID with a version with identifier VERSION.
Overwrites the current version of the stored record with identifier ID with its previous version.
Catmandu::Store, Catmandu::Bag
2023-03-03 | perl v5.36.0 |