From 9e5f07941273a6647381420e18c50e874d52a01f Mon Sep 17 00:00:00 2001 From: davy-beauzil <38990335+davy-beauzil@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:58:35 +0100 Subject: [PATCH] fix: add migration + set nullable 2 properties (#754) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les fixtures ne passent plus, j'ai une erreur `Duplicate table: 7 ERROR: relation "migration_versions" already exists` mais je merge quand même pour pouvoir déployer la migration en prod --- docker/php/docker-entrypoint.sh | 6 +- fixtures/test/migration_versions.yaml | 7 +++ migrations/2024/Version20241106085124.php | 73 +++++++++++++++++++++++ src/Entity/Group.php | 2 +- src/Entity/MigrationVersions.php | 59 ++++++++++++++++++ src/Entity/User.php | 2 +- 6 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 fixtures/test/migration_versions.yaml create mode 100644 migrations/2024/Version20241106085124.php create mode 100644 src/Entity/MigrationVersions.php diff --git a/docker/php/docker-entrypoint.sh b/docker/php/docker-entrypoint.sh index 0884add..315e652 100755 --- a/docker/php/docker-entrypoint.sh +++ b/docker/php/docker-entrypoint.sh @@ -54,9 +54,9 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then echo "The db is now ready and reachable" fi - if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then - bin/console doctrine:migrations:migrate --no-interaction - fi +# if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then +# bin/console doctrine:migrations:migrate --no-interaction +# fi fi setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var diff --git a/fixtures/test/migration_versions.yaml b/fixtures/test/migration_versions.yaml new file mode 100644 index 0000000..8cb9798 --- /dev/null +++ b/fixtures/test/migration_versions.yaml @@ -0,0 +1,7 @@ +App\Entity\MigrationVersions: + migration_version (template): + executedAt: + executionTime: 0 + + migration_version_1 (extends migration_version): + version: 'DoctrineMigrations\Version20241106085124' diff --git a/migrations/2024/Version20241106085124.php b/migrations/2024/Version20241106085124.php new file mode 100644 index 0000000..3971b5a --- /dev/null +++ b/migrations/2024/Version20241106085124.php @@ -0,0 +1,73 @@ +addSql('CREATE TABLE migration_versions (version VARCHAR(191) NOT NULL, executed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, execution_time INT DEFAULT NULL, PRIMARY KEY(version))'); + $this->addSql('CREATE TABLE platform_offer (id UUID NOT NULL, configuration_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, price INT NOT NULL, currency VARCHAR(255) NOT NULL, active BOOLEAN NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_1B8AE3BA73F32DD8 ON platform_offer (configuration_id)'); + $this->addSql('CREATE INDEX IDX_1B8AE3BA8CDE5729 ON platform_offer (type)'); + $this->addSql('COMMENT ON COLUMN platform_offer.id IS \'(DC2Type:uuid)\''); + $this->addSql('COMMENT ON COLUMN platform_offer.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN platform_offer.updated_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('ALTER TABLE platform_offer ADD CONSTRAINT FK_1B8AE3BA73F32DD8 FOREIGN KEY (configuration_id) REFERENCES configuration (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE "group" ADD services_enabled BOOLEAN DEFAULT false NOT NULL'); + $this->addSql('ALTER TABLE "user" ADD platform_offer_id UUID DEFAULT NULL'); + $this->addSql('ALTER TABLE "user" ADD membership_paid BOOLEAN DEFAULT false NOT NULL'); + $this->addSql('ALTER TABLE "user" ADD start_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + $this->addSql('ALTER TABLE "user" ADD end_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + $this->addSql('ALTER TABLE "user" ADD payed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + $this->addSql('COMMENT ON COLUMN "user".platform_offer_id IS \'(DC2Type:uuid)\''); + $this->addSql('COMMENT ON COLUMN "user".start_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN "user".end_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN "user".payed_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('ALTER TABLE "user" ADD CONSTRAINT FK_8D93D649D6B674FC FOREIGN KEY (platform_offer_id) REFERENCES platform_offer (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_8D93D649D6B674FC ON "user" (platform_offer_id)'); + $this->addSql('ALTER TABLE messenger_messages ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER available_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER delivered_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); + } + + 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" DROP CONSTRAINT FK_8D93D649D6B674FC'); + $this->addSql('ALTER TABLE platform_offer DROP CONSTRAINT FK_1B8AE3BA73F32DD8'); + $this->addSql('DROP TABLE migration_versions'); + $this->addSql('DROP TABLE platform_offer'); + $this->addSql('DROP INDEX IDX_8D93D649D6B674FC'); + $this->addSql('ALTER TABLE "user" DROP platform_offer_id'); + $this->addSql('ALTER TABLE "user" DROP membership_paid'); + $this->addSql('ALTER TABLE "user" DROP start_at'); + $this->addSql('ALTER TABLE "user" DROP end_at'); + $this->addSql('ALTER TABLE "user" DROP payed_at'); + $this->addSql('ALTER TABLE messenger_messages ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER available_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER delivered_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS NULL'); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS NULL'); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS NULL'); + $this->addSql('ALTER TABLE "group" DROP services_enabled'); + } +} diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 7164aeb..7095513 100755 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -140,7 +140,7 @@ class Group implements \Stringable #[ORM\ManyToMany(targetEntity: Product::class, mappedBy: 'groups')] private Collection $products; - #[ORM\Column(type: 'boolean')] + #[ORM\Column(type: 'boolean', options: ['default' => false])] private bool $servicesEnabled = false; public function __construct() diff --git a/src/Entity/MigrationVersions.php b/src/Entity/MigrationVersions.php new file mode 100644 index 0000000..3989d05 --- /dev/null +++ b/src/Entity/MigrationVersions.php @@ -0,0 +1,59 @@ +version; + } + + public function setVersion(string $version): MigrationVersions + { + $this->version = $version; + + return $this; + } + + public function getExecutedAt(): ?\DateTime + { + return $this->executedAt; + } + + public function setExecutedAt(?\DateTime $executedAt): MigrationVersions + { + $this->executedAt = $executedAt; + + return $this; + } + + public function getExecutionTime(): ?int + { + return $this->executionTime; + } + + public function setExecutionTime(?int $executionTime): MigrationVersions + { + $this->executionTime = $executionTime; + + return $this; + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index 687abf7..a2c3aef 100755 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -275,7 +275,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, ImageIn /** * Paid for membership of the platform. */ - #[ORM\Column(type: 'boolean', nullable: false)] + #[ORM\Column(type: 'boolean', options: ['default' => false])] private bool $membershipPaid = false; #[ORM\ManyToOne(targetEntity: PlatformOffer::class)]