Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Do not prefix fields/tables on "*.change" DB schema update #314

Merged
merged 2 commits into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Classes/Database/Schema/SchemaUpdateResultRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class SchemaUpdateResultRenderer
protected $schemaUpdateTypeLabels = array(
SchemaUpdateType::FIELD_ADD => 'Add fields',
SchemaUpdateType::FIELD_CHANGE => 'Change fields',
SchemaUpdateType::FIELD_PREFIX => 'Prefix fields',
SchemaUpdateType::FIELD_DROP => 'Drop fields',
SchemaUpdateType::TABLE_ADD => 'Add tables',
SchemaUpdateType::TABLE_CHANGE => 'Change tables',
SchemaUpdateType::TABLE_CLEAR => 'Clear tables',
SchemaUpdateType::TABLE_PREFIX => 'Prefix tables',
SchemaUpdateType::TABLE_DROP => 'Drop tables',
);

Expand Down
10 changes: 10 additions & 0 deletions Classes/Database/Schema/SchemaUpdateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class SchemaUpdateType extends Enumeration
*/
const FIELD_CHANGE = 'field.change';

/**
* Prefix a field
*/
const FIELD_PREFIX = 'field.prefix';

/**
* Drop a field
*/
Expand All @@ -51,6 +56,11 @@ class SchemaUpdateType extends Enumeration
*/
const TABLE_CHANGE = 'table.change';

/**
* Prefix a table
*/
const TABLE_PREFIX = 'table.prefix';

/**
* Drop a table
*/
Expand Down
39 changes: 26 additions & 13 deletions Classes/Service/Database/SchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
*/
class SchemaService implements SingletonInterface
{
/**
* Group of safe statements
*/
const STATEMENT_GROUP_SAFE = 1;

/**
* Group of destructive statements
*/
const STATEMENT_GROUP_DESTRUCTIVE = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make these strings add_create_change and drop_rename


/**
* @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
* @inject
Expand All @@ -41,13 +51,15 @@ class SchemaService implements SingletonInterface
* @var array
*/
protected $schemaUpdateTypesStatementTypesMapping = array(
SchemaUpdateType::FIELD_ADD => array('add'),
SchemaUpdateType::FIELD_CHANGE => array('change'),
SchemaUpdateType::FIELD_DROP => array('drop'),
SchemaUpdateType::TABLE_ADD => array('create_table'),
SchemaUpdateType::TABLE_CHANGE => array('change_table'),
SchemaUpdateType::TABLE_CLEAR => array('clear_table'),
SchemaUpdateType::TABLE_DROP => array('drop_table'),
SchemaUpdateType::FIELD_ADD => array('add' => self::STATEMENT_GROUP_SAFE),
SchemaUpdateType::FIELD_CHANGE => array('change' => self::STATEMENT_GROUP_SAFE),
SchemaUpdateType::FIELD_PREFIX => array('change' => self::STATEMENT_GROUP_DESTRUCTIVE),
SchemaUpdateType::FIELD_DROP => array('drop' => self::STATEMENT_GROUP_DESTRUCTIVE),
SchemaUpdateType::TABLE_ADD => array('create_table' => self::STATEMENT_GROUP_SAFE),
SchemaUpdateType::TABLE_CHANGE => array('change_table' => self::STATEMENT_GROUP_SAFE),
SchemaUpdateType::TABLE_CLEAR => array('clear_table' => self::STATEMENT_GROUP_DESTRUCTIVE),
SchemaUpdateType::TABLE_PREFIX => array('change' => self::STATEMENT_GROUP_DESTRUCTIVE),
SchemaUpdateType::TABLE_DROP => array('drop_table' => self::STATEMENT_GROUP_DESTRUCTIVE),
);

/**
Expand All @@ -64,18 +76,19 @@ public function updateSchema(array $schemaUpdateTypes)
$addCreateChange = $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
$dropRename = $this->schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema);

$updateStatements = array();
ArrayUtility::mergeRecursiveWithOverrule($updateStatements, $this->schemaMigrationService->getUpdateSuggestions($addCreateChange));
ArrayUtility::mergeRecursiveWithOverrule($updateStatements, $this->schemaMigrationService->getUpdateSuggestions($dropRename, 'remove'));
$updateStatements = array(
self::STATEMENT_GROUP_SAFE => $this->schemaMigrationService->getUpdateSuggestions($addCreateChange),
self::STATEMENT_GROUP_DESTRUCTIVE => $this->schemaMigrationService->getUpdateSuggestions($dropRename, 'remove'),
);

$updateResult = new SchemaUpdateResult();

foreach ($schemaUpdateTypes as $schemaUpdateType) {
$statementTypes = $this->getStatementTypes($schemaUpdateType);

foreach ($statementTypes as $statementType) {
if (isset($updateStatements[$statementType])) {
$statements = $updateStatements[$statementType];
foreach ($statementTypes as $statementType => $statementGroup) {
if (isset($updateStatements[$statementGroup][$statementType])) {
$statements = $updateStatements[$statementGroup][$statementType];
$result = $this->schemaMigrationService->performUpdateQueries(
$statements,
// Generate a map of statements as keys and true as values
Expand Down