sandstorm / UserManagement

User Management Package for Neos and Flow
MIT License
37 stars 28 forks source link

Doctrine migrations fail in Flow 6 #45

Open robertlemke opened 4 years ago

robertlemke commented 4 years ago

Using a basic Flow distribution (6.x) with one custom package (which requires sandstorm/usermanagent), and an empty database doctrine:migrate will fail:

SQLSTATE[HY000]: General error: 1005 Can't create table `weclapp-importer`.`sandstorm_usermanagement_domain_model_user` (errno: 150 "Foreign key constraint is incorrectly formed")

caused by this query:

ALTER TABLE sandstorm_usermanagement_domain_model_user ADD CONSTRAINT FK_5DEB8A977D3656A4 FOREIGN KEY (account) REFERENCES typo3_flow_security_account (persistence_object_identifier)

At that time of migration, the database contains the typo3_flow_security_account table, but for some reason, the foreign key constraint is not accepted.

Tested with MariaDB 10.2.

davidspiola commented 4 years ago

I experience the same issue, but in my case it's not typo3_flow_security_account . I just basiclly installed the package and let the migrations run.

An exception occurred while executing 'ALTER TABLE sandstorm_usermanagement_domain_model_user ADD CONSTRAINT FK_5DEB8A977D3656A4 FOREIGN KEY (account) REFERENCES neos_flow_security_account (persistence_object_identifier)':

davidspiola commented 4 years ago

To keep going I created a fresh migration. I don't know why altering the table does not work.

namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Migrations\AbortMigrationException;

/**
 * Auto-generated Migration: Please modify to your needs! This block will be used as the migration description if getDescription() is not used.
 */
class Version20200227125430 extends AbstractMigration
{

    /**
     * @return string
     */
    public function getDescription(): string
    {
        return '';
    }

    /**
     * @param Schema $schema
     * @return void
     * @throws AbortMigrationException
     */
    public function up(Schema $schema): void
    {
        // this up() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');

        $this->addSql('CREATE TABLE sandstorm_usermanagement_domain_model_registrationflow (persistence_object_identifier VARCHAR(40) NOT NULL, email VARCHAR(255) NOT NULL, encryptedpassword VARCHAR(255) NOT NULL, attributes LONGTEXT NOT NULL COMMENT \'(DC2Type:json_array)\', activationtoken VARCHAR(255) DEFAULT NULL, activationtokenvaliduntil DATETIME DEFAULT NULL, PRIMARY KEY(persistence_object_identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE sandstorm_usermanagement_domain_model_resetpasswordflow (persistence_object_identifier VARCHAR(40) NOT NULL, email VARCHAR(255) NOT NULL, resetpasswordtoken VARCHAR(255) DEFAULT NULL, resetpasswordtokenvaliduntil DATETIME DEFAULT NULL, PRIMARY KEY(persistence_object_identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $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, dtype VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_5DEB8A977D3656A4 (account), PRIMARY KEY(persistence_object_identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_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)');
    }

    /**
     * @param Schema $schema
     * @return void
     * @throws AbortMigrationException
     */
    public function down(Schema $schema): void
    {
        // this down() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');

        $this->addSql('DROP TABLE sandstorm_usermanagement_domain_model_registrationflow');
        $this->addSql('DROP TABLE sandstorm_usermanagement_domain_model_resetpasswordflow');
        $this->addSql('DROP TABLE sandstorm_usermanagement_domain_model_user');
    }
}
skurfuerst commented 4 years ago

Sorry for not responding for so long; I'll check this out ASAP

skurfuerst commented 4 years ago

I think I fixed this with https://github.com/sandstorm/UserManagement/commit/54823f73ccf7f4662714461b5fe980203255c41b

Can you re-test plz? :)

skurfuerst commented 4 years ago

@robertlemke @davidspiola plz retest :)