Skip to content

Commit

Permalink
BUGFIX: Make initial migration work for both fresh installs where all…
Browse files Browse the repository at this point in the history
… migrations (Flow+UserManagement) are run at once, as well as cases where Flow is already installed and UserManagement is added later.
  • Loading branch information
Bastian Heist committed Jun 1, 2017
1 parent 2b0ce02 commit 9864a84
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Migrations/Mysql/Version20160519150828.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@
*/
class Version20160519150828 extends AbstractMigration
{

/**
* @param Schema $schema
* @return void
*/
public function up(Schema $schema)
{
// this up() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");

$this->addSql("CREATE TABLE sandstorm_usermanagement_domain_model_user (persistence_object_identifier VARCHAR(40) NOT NULL, account VARCHAR(40) DEFAULT NULL, email VARCHAR(255) NOT NULL, gender VARCHAR(255) DEFAULT NULL, firstname VARCHAR(255) DEFAULT NULL, lastname VARCHAR(255) DEFAULT NULL, companyname VARCHAR(255) DEFAULT NULL, resetpasswordtoken VARCHAR(255) DEFAULT NULL, activationtoken VARCHAR(255) DEFAULT NULL, activationtokenvaliduntil DATETIME DEFAULT NULL, resetpasswordtokenvaliduntil DATETIME DEFAULT NULL, newactivationtokenrequested TINYINT(1) DEFAULT NULL, dtype VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_5DEB8A977D3656A4 (account), PRIMARY KEY(persistence_object_identifier)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE sandstorm_usermanagement_domain_model_user ADD CONSTRAINT FK_5DEB8A977D3656A4 FOREIGN KEY (account) REFERENCES neos_flow_security_account (persistence_object_identifier)");

/**
* We need to check what the name of table flow accounts table is. If you install flow, run migrations, then add usermananagement,
* then run the UserManagement migrations, the name will will be neos_flow_...
* However, if you install everything in one go and run migrations then, the order will be different because this migration
* comes before the Flow migration where the table is renamed (Version20161124185047). So we need to check which of these two
* tables exist and set the FK relation accordingly.
**/
$query = "SELECT * FROM information_schema.tables WHERE table_schema = '".$this->connection->getDatabase()."' AND table_name = 'neos_flow_security_account'";
$result = $this->connection->executeQuery($query)->fetchAll();
if(count($result) > 0){
// Neos table is there - this means flow migrations have already been run.
$this->addSql("ALTER TABLE sandstorm_usermanagement_domain_model_user ADD CONSTRAINT FK_5DEB8A977D3656A4 FOREIGN KEY (account) REFERENCES neos_flow_security_account (persistence_object_identifier)");
} else {
// Table is called typo3_
$this->addSql("ALTER TABLE sandstorm_usermanagement_domain_model_user ADD CONSTRAINT FK_5DEB8A977D3656A4 FOREIGN KEY (account) REFERENCES typo3_flow_security_account (persistence_object_identifier)");
}
}

/**
Expand Down

0 comments on commit 9864a84

Please sign in to comment.