NAME

DBIO::ChangeLog::Schema - Schema-level change tracking component

VERSION

version 0.900000

SYNOPSIS

package MyApp::Schema;
use base 'DBIO::Schema';

__PACKAGE__->load_components('ChangeLog::Schema');

# Optional: restrict which sources are tracked (default: all)
__PACKAGE__->changelog_sources([qw/ Artist Album /]);

DESCRIPTION

A schema-level component that enables automatic change tracking. When loaded, it:

  • Overrides "txn_do" in DBIO::Schema to automatically create changesets that group changelog entries within a transaction.

  • At connection time, dynamically registers ResultSource objects for the changelog_set table and each <source>_changelog table.

  • Provides "changelog_user" and "changelog_session" accessors for recording who made changes.

METHODS

changelog_user

$schema->changelog_user($user_id);
my $uid = $schema->changelog_user;

Sets or gets the user identifier for future changesets.

changelog_session

$schema->changelog_session($session_id);
my $sid = $schema->changelog_session;

Sets or gets the session identifier for future changesets.

changelog_disabled

local $schema->{_changelog_disabled_flag} = 1;
$schema->changelog_disabled(1);

Flag to skip change tracking entirely.

connection

Override of "connection" in DBIO::Schema. After establishing the connection, registers the changelog ResultSources if not yet done.

txn_do

$schema->txn_do(sub {
  # all changes here are grouped in one changeset
});

Wraps the inherited txn_do in changeset creation. A new changelog_set row is inserted before the coderef runs. If the transaction rolls back, the changeset row is naturally rolled back too (thanks to local scoping of the changeset ID).

Nested calls to txn_do reuse the parent changeset.

deploy_changelog

$schema->deploy_changelog;

Deploys all changelog tables (changelog_set and every <source>_changelog table) via the storage layer. Call this after deploying your main schema.

SEE ALSO

DBIO::ChangeLog, DBIO::ChangeLog::Entry, DBIO::ChangeLog::Set, DBIO::ChangeLog::Table

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.