protected function AppendCreateTableStructureQuery(QueryBuilder $QueryBuilder, Syncing\Traits\ITableTraitManager $TableTraitManager, IColumnTraitManager $ColumnTraitManager, Table $Table) { $QueryBuilder->AppendIdentifier('CREATE TABLE # ', [$Table->GetName()]); $QueryBuilder->Append('('); $First = true; foreach ($Table->GetColumns() as $Column) { if ($First) { $First = false; } else { $QueryBuilder->Append(','); } $this->AppendFullColumn($QueryBuilder, $ColumnTraitManager, $Column, null, false); } $TableOptions = []; foreach ($Table->GetStructuralTraits() as $StructuralTableTrait) { if ($StructuralTableTrait instanceof Tables\CharacterSet || $StructuralTableTrait instanceof Tables\Collation || $StructuralTableTrait instanceof Tables\Engine || $StructuralTableTrait instanceof Relational\Traits\Comment) { $TableOptions[] = $StructuralTableTrait; } else { $QueryBuilder->Append(','); $TableTraitManager->AppendDefinition($QueryBuilder, $Table, $StructuralTableTrait); } } $QueryBuilder->Append(')'); foreach ($TableOptions as $TableOption) { $QueryBuilder->Append(','); $TableTraitManager->AppendDefinition($QueryBuilder, $Table, $TableOption); } }
private function GetTableStructuralTraits(Relational\Table $Table, Relational\Table $CurrentTable) { $Traits = $Table->GetStructuralTraits(); $CurrentTraits = $CurrentTable->GetStructuralTraits(); $TraitsToAdd = []; foreach ($Traits as $Trait) { if (count(array_filter($CurrentTraits, [$Trait, 'Is'])) === 0) { $TraitsToAdd[] = $Trait; } } $TraitsToRemove = []; foreach ($CurrentTraits as $CurrentTrait) { if (count(array_filter($Traits, [$CurrentTrait, 'Is'])) === 0) { $TraitsToRemove[] = $CurrentTrait; } } return [$TraitsToAdd, $TraitsToRemove]; }