Schema Model
Derafu ETL describes a database structure with its own model, independent
from Doctrine DBAL and from any spreadsheet format: a Schema has tables, a
table has columns, indexes and foreign keys. Every schema source reads
into this model and every schema target writes from it.
Engine-Specific Text Settings
ColumnInterface and TableInterface expose getPlatformOptions() and
setPlatformOptions(). These optional settings describe text encoding and
comparison for a particular engine; they do not convert row values.
$column->setPlatformOptions([
'mysql' => [
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
],
'postgresql' => ['collation' => 'C'],
'sqlite' => ['collation' => 'NOCASE'],
]);
The setter replaces the option map, rejects malformed settings and omits null
values. An empty map means unspecified. MySQL table defaults and individual
column overrides are stored separately. Changing these options on schema()
affects subsequent synchronization without modifying the source database.
DoctrineDatabase supplies the current platform to its schema adapters. When
using the adapters directly, pass the platform explicitly:
$platform = $connection->getDatabasePlatform();
$source = new DoctrineSchemaSource($platform);
$target = new DoctrineSchemaTarget($platform);
Without a platform, those adapters preserve their platform-neutral behavior. With a platform, only its option group is applied. MySQL collation names are not sent to PostgreSQL or SQLite. During synchronization, unspecified settings on existing assets preserve the destination’s configuration; new assets use the destination’s defaults. Explicit incompatible settings are reported by the database rather than mapped to an assumed equivalent.
Spreadsheet table and column rows store these maps in
properties.platform_options. XLSX and JSON round trips retain them, and files
without the property continue to load. The standalone SQLite SQL target honors
sqlite.collation and ignores other engines’ groups. MySQL synchronization uses
DBAL’s platform comparator and also handles explicit changes to table defaults.
Its documented implicit-commit limitation still applies to actual DDL changes.
Indexes
An index (Derafu\ETL\Schema\Index, IndexInterface) has:
| Property | Type | Meaning |
|---|---|---|
name |
string |
The index name. |
columns |
string[] |
The indexed columns, in order. |
type |
IndexType |
The kind of index. |
clustered |
bool |
Whether the index is clustered. |
Derafu\ETL\Schema\Enum\IndexType is a string-backed enum:
| Case | Value |
|---|---|
IndexType::REGULAR |
regular |
IndexType::UNIQUE |
unique |
IndexType::FULLTEXT |
fulltext |
IndexType::SPATIAL |
spatial |
use Derafu\ETL\Schema\Enum\IndexType;
use Derafu\ETL\Schema\Index;
$regular = new Index('idx_name', ['name']);
$unique = new Index('idx_email', ['email'], IndexType::UNIQUE);
$fulltext = new Index('idx_body', ['body'], IndexType::FULLTEXT);
$clustered = new Index('idx_order', ['order_id', 'line'], IndexType::REGULAR, true);
$unique->isUnique(); // true (it is `type === IndexType::UNIQUE`).
$clustered->isClustered(); // true.
isUnique() is derived from the type, so the two can never contradict each
other. To change an index use setType() and setClustered().
The enum values are the ones stored in a spreadsheet (see below), so they are part of the file format and do not change.
What each target does with them
| Target | Type | Clustered |
|---|---|---|
| Doctrine | Mapped to Doctrine’s own IndexType. |
Passed to the index. |
| Spreadsheet | Stored as type. |
Stored as clustered. |
| Text | INDEX, UNIQUE INDEX, FULLTEXT INDEX, SPATIAL INDEX. |
A CLUSTERED line under the index. |
| Markdown | INDEX, UNIQUE, FULLTEXT, SPATIAL. |
CLUSTERED in the Clustered column. |
| D2 | INDEX, UNIQUE, FULLTEXT, SPATIAL. |
Not shown. |
| SQL (SQLite) | UNIQUE is honored. |
Ignored. |
The SQLite target has no FULLTEXT or SPATIAL index through
CREATE INDEX, and no clustered indexes, so those are created as regular
indexes there. Whether clustered has any effect depends on the platform of the
database that receives the Doctrine schema (for example SQL Server).
Schema in a Spreadsheet
SpreadsheetSchemaTarget writes the schema into a sheet (__schema by
default) with one row per element, and SpreadsheetSchemaSource reads it back.
Each row has a type, a name and its properties. An index row looks like
this:
{
"type": "index",
"name": "invoice.idx_number",
"properties": {
"columns": ["invoice_number"],
"type": "unique",
"clustered": false
}
}
Files from previous versions
Older versions wrote unique and flags instead of type and clustered:
{ "columns": ["invoice_number"], "unique": true, "flags": ["clustered"] }
Those spreadsheets are still read:
unique: truebecomesIndexType::UNIQUE.- The flag
clusteredbecomesclustered: true. - The flags
fulltextandspatialbecome the matchingIndexType. - Any other flag throws an exception, instead of being dropped silently.
An index row with a type that is not one of the four values also throws.
When the file is written again it uses the current format.