如何永久删除学说迁移?

How to remove doctrine migrations permanently?

如何执行 迁移 并只显示我现有的实体?

问题是:

  1. 我从迁移中删除了所有版本文件
  2. 我删除了架构 public
  3. 我创建了新架构public
  4. 我做了一个make:migration
  5. 我做了一个doctrine:migrations:migrate

并且出现了旧数据 - 我的意思是没有实体并且很久以前就被删除的表。

架构已创建,但包含冗余和不必要的数据。

如何完全重置迁移?是否有任何缓存可以保存删除的表(不考虑迁移版本)?

这是我最新的迁移文件 - 我想进行迁移,但我没有 user_to_offert_user 等表格。 请不要给我手动解决方案 - 我知道我可以在迁移之前修改它,但每次我要更改某些内容时,我都这样做似乎毫无意义。

有什么不明白的地方请问我。我尽量详细说明问题。

附加信息:

我到底在做什么:

  1. 我从迁移中删除了 所有 个版本。
  2. 我运行涵盖了所有数据
  3. 我删除了我的 public 模式
  4. 我创建了新的 public 模式
  5. 我运行bin/consolemake:migration
  6. 我运行bin/consoledoctrine:migrations:migrate

这是我的大问题: 我有这种实体:

当我 运行 迁移所有这些表时显示:

如您所见,表格太多了。其中一些我很久以前就删除了,但它们仍然出现在每次迁移中。 我不知道如何度过,我很绝望,因为我已经在第 3 天花在这个问题上了。

我在 Heroku 上有我的数据库 - 我使用 Postgres,当我删除所有表时,它们不会在 heroku 中显示:

这里是这个迁移的代码:

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20210403092535 extends AbstractMigration
{
    public function getDescription() : string
    {
        return '';
    }

    public function up(Schema $schema) : void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE SEQUENCE requirement_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE SEQUENCE skill_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE SEQUENCE "user_id_seq" INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE SEQUENCE user_to_offert_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE TABLE login_history (id SERIAL NOT NULL, user_id_id INT NOT NULL, login_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, login_status BOOLEAN NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE INDEX IDX_37976E369D86650F ON login_history (user_id_id)');
        $this->addSql('CREATE TABLE offert (id SERIAL NOT NULL, event_firm_id INT NOT NULL, event_name VARCHAR(100) NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE INDEX IDX_44229184CF8D1CF ON offert (event_firm_id)');
        $this->addSql('CREATE TABLE requirement (id INT NOT NULL, requirement VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE TABLE requirement_user (requirement_id INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY(requirement_id, user_id))');
        $this->addSql('CREATE INDEX IDX_598D28707B576F77 ON requirement_user (requirement_id)');
        $this->addSql('CREATE INDEX IDX_598D2870A76ED395 ON requirement_user (user_id)');
        $this->addSql('CREATE TABLE skill (id INT NOT NULL, skill VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE TABLE skill_user (skill_id INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY(skill_id, user_id))');
        $this->addSql('CREATE INDEX IDX_CAD24AFB5585C142 ON skill_user (skill_id)');
        $this->addSql('CREATE INDEX IDX_CAD24AFBA76ED395 ON skill_user (user_id)');
        $this->addSql('CREATE TABLE "user" (id INT NOT NULL, user_details_id_id INT NOT NULL, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, account_type VARCHAR(100) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D64912595E8 ON "user" (user_details_id_id)');
        $this->addSql('CREATE TABLE user_details (id SERIAL NOT NULL, name VARCHAR(255) NOT NULL, surname VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE TABLE user_to_offert (id INT NOT NULL, hired BOOLEAN NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE TABLE user_to_offert_offert (user_to_offert_id INT NOT NULL, offert_id INT NOT NULL, PRIMARY KEY(user_to_offert_id, offert_id))');
        $this->addSql('CREATE INDEX IDX_4AA1878F8C2827E4 ON user_to_offert_offert (user_to_offert_id)');
        $this->addSql('CREATE INDEX IDX_4AA1878F3D478C97 ON user_to_offert_offert (offert_id)');
        $this->addSql('CREATE TABLE user_to_offert_user (user_to_offert_id INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY(user_to_offert_id, user_id))');
        $this->addSql('CREATE INDEX IDX_7BE6CF748C2827E4 ON user_to_offert_user (user_to_offert_id)');
        $this->addSql('CREATE INDEX IDX_7BE6CF74A76ED395 ON user_to_offert_user (user_id)');
        $this->addSql('ALTER TABLE login_history ADD CONSTRAINT FK_37976E369D86650F FOREIGN KEY (user_id_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE offert ADD CONSTRAINT FK_44229184CF8D1CF FOREIGN KEY (event_firm_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE requirement_user ADD CONSTRAINT FK_598D28707B576F77 FOREIGN KEY (requirement_id) REFERENCES requirement (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE requirement_user ADD CONSTRAINT FK_598D2870A76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE skill_user ADD CONSTRAINT FK_CAD24AFB5585C142 FOREIGN KEY (skill_id) REFERENCES skill (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE skill_user ADD CONSTRAINT FK_CAD24AFBA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE "user" ADD CONSTRAINT FK_8D93D64912595E8 FOREIGN KEY (user_details_id_id) REFERENCES user_details (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE user_to_offert_offert ADD CONSTRAINT FK_4AA1878F8C2827E4 FOREIGN KEY (user_to_offert_id) REFERENCES user_to_offert (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE user_to_offert_offert ADD CONSTRAINT FK_4AA1878F3D478C97 FOREIGN KEY (offert_id) REFERENCES offert (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE user_to_offert_user ADD CONSTRAINT FK_7BE6CF748C2827E4 FOREIGN KEY (user_to_offert_id) REFERENCES user_to_offert (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE user_to_offert_user ADD CONSTRAINT FK_7BE6CF74A76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema) : void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE SCHEMA public');
        $this->addSql('ALTER TABLE user_to_offert_offert DROP CONSTRAINT FK_4AA1878F3D478C97');
        $this->addSql('ALTER TABLE requirement_user DROP CONSTRAINT FK_598D28707B576F77');
        $this->addSql('ALTER TABLE skill_user DROP CONSTRAINT FK_CAD24AFB5585C142');
        $this->addSql('ALTER TABLE login_history DROP CONSTRAINT FK_37976E369D86650F');
        $this->addSql('ALTER TABLE offert DROP CONSTRAINT FK_44229184CF8D1CF');
        $this->addSql('ALTER TABLE requirement_user DROP CONSTRAINT FK_598D2870A76ED395');
        $this->addSql('ALTER TABLE skill_user DROP CONSTRAINT FK_CAD24AFBA76ED395');
        $this->addSql('ALTER TABLE user_to_offert_user DROP CONSTRAINT FK_7BE6CF74A76ED395');
        $this->addSql('ALTER TABLE "user" DROP CONSTRAINT FK_8D93D64912595E8');
        $this->addSql('ALTER TABLE user_to_offert_offert DROP CONSTRAINT FK_4AA1878F8C2827E4');
        $this->addSql('ALTER TABLE user_to_offert_user DROP CONSTRAINT FK_7BE6CF748C2827E4');
        $this->addSql('DROP SEQUENCE requirement_id_seq CASCADE');
        $this->addSql('DROP SEQUENCE skill_id_seq CASCADE');
        $this->addSql('DROP SEQUENCE "user_id_seq" CASCADE');
        $this->addSql('DROP SEQUENCE user_to_offert_id_seq CASCADE');
        $this->addSql('DROP TABLE login_history');
        $this->addSql('DROP TABLE offert');
        $this->addSql('DROP TABLE requirement');
        $this->addSql('DROP TABLE requirement_user');
        $this->addSql('DROP TABLE skill');
        $this->addSql('DROP TABLE skill_user');
        $this->addSql('DROP TABLE "user"');
        $this->addSql('DROP TABLE user_details');
        $this->addSql('DROP TABLE user_to_offert');
        $this->addSql('DROP TABLE user_to_offert_offert');
        $this->addSql('DROP TABLE user_to_offert_user');
    }
}

Doctrine MigrationsBundle 有一个 table 存储先前迁移的信息 运行。如果您重置迁移,您还必须重置 table。您可以为此使用汇总命令:

php bin/console doctrine:migrations:rollup

如果这不起作用,您可能需要手动更改 table,例如在迁移中,但如果可能的话,你应该避免这种情况。默认情况下 table 称为 doctrine_migration_versions,但您可以使用 debug:config 命令检查您的配置是否不同:

php bin/console debug:config doctrine_migrations storage

这是默认情况下的样子:

doctrine_migrations:
    # ...
    storage:
        # Default (SQL table) metadata storage configuration
        table_storage:
            table_name: 'doctrine_migration_versions'
            version_column_name: 'version'
            version_column_length: 1024
            executed_at_column_name: 'executed_at'