Scheme

Class BlackFox\Scheme accepts as input for the constructor a list of SCRUD heirs and provides methods to synchronize the structure of the database.

Basic methods

Method Params Description Return
__construct SCRUD[...]|string[...] $Tables You can pass to the constructor a mixed list of objects and strings (the names of the derived classes from SCRUD).
Compare Compares the structure of the database (tables, columns, keys, indexes, constraints) with the structure, described in the classes inherited from SCRUD. Multidimensional array describing possible changes to the database structure for converting it to the structure described in the derived classes from SCRUD:
  • MESSAGE - description of the change
  • TABLE - code of the modified table or associated index or constraint
  • SQL - SQL to change structure
  • ... - other data depending on the change
Synchronize Synchronizes the database structure if it differs from the structure described in the SCRUD inherited classes.

Using

Usually, you don't need to manually run the above methods yourself, instead you should:

  • create and return an instance of the Scheme class in GetScheme method of your core
  • start schema sync using the Upgrade method of your core
  • any:
    • start a full engine upgrade: run file /BlackFox/upgrade.php
    • use the SchemeSynchronizer unit in the admin area: address /admin/BlackFox/SchemeSynchronizer.php
<?php namespace Testing; class Core extends \BlackFox\ACore { // ... public function GetScheme() { return new \BlackFox\Scheme([ Grades::I(), Rooms::I(), Timetable::I(), Students::I(), ]); } public function Upgrade() { $this->GetScheme()->Synchronize(); } // ... }
Ask question