Amvionlie CMS
Where the Future Begins

Schema Contract Sample

A schema contract is the addon-owned description of database tables and schema apply behavior. The sample folder does not currently include a standalone schema contract file, but manifest risk fields must still match any schema contract the addon ships.

Where It Belongs

Use an addon-owned path such as `addons/{addon_folder}/src/schema_contract.php` or another manifest-declared contract path. The file should be safe for Installer/system governance inspection and should not perform unrelated runtime work when loaded.

What Owns It

The addon owns its table namespace and apply helper. Installer owns when schema contracts are applied during install/update. system governance owns installed lifecycle state and should be able to compare declared ownership against collisions.

Common Breakage

  • Creating tables without declaring `risk_declarations.database.creates_tables` makes install risk warnings incomplete.
  • Touching shared/core tables without declaring it can produce unsafe updates.
  • Redeclaring functions on repeated contract inspection can break update installs.
  • Dropping tables during uninstall without declaring `removes_owned_tables` and `destroys_live_data` misleads admins.

Minimal Pattern

function youraddon_schema_tables(): array
{
    return [
        'amv_youraddon_records' => 'CREATE TABLE IF NOT EXISTS amv_youraddon_records (...)',
    ];
}

function youraddon_schema_apply(PDO $pdo): array
{
    foreach (youraddon_schema_tables() as $schemaSql) {
        $pdo->exec($schemaSql);
    }

    return array_keys(youraddon_schema_tables());
}

return [
    'addon_key' => 'your-addon-slug',
    'schema_contract_ready' => true,
    'table_namespace' => 'amv_youraddon_*',
    'owned_tables' => array_keys(youraddon_schema_tables()),
    'apply_function' => 'youraddon_schema_apply',
];

See Install And Risk Contract Sample for the manifest fields that must agree with schema behavior.

Updated: 2026-05-07 02:18:09