fix: add migration + set nullable 2 properties (#754)
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
This commit is contained in:
parent
c807e2bc79
commit
9e5f079412
6 changed files with 144 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
7
fixtures/test/migration_versions.yaml
Normal file
7
fixtures/test/migration_versions.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
App\Entity\MigrationVersions:
|
||||
migration_version (template):
|
||||
executedAt: <date_create('today')>
|
||||
executionTime: 0
|
||||
|
||||
migration_version_1 (extends migration_version):
|
||||
version: 'DoctrineMigrations\Version20241106085124'
|
||||
73
migrations/2024/Version20241106085124.php
Normal file
73
migrations/2024/Version20241106085124.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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 Version20241106085124 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 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');
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
59
src/Entity/MigrationVersions.php
Normal file
59
src/Entity/MigrationVersions.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Table(name: 'migration_versions')]
|
||||
#[ORM\Entity]
|
||||
class MigrationVersions
|
||||
{
|
||||
#[ORM\Column(name: 'version', type: 'string', length: 191, nullable: false)]
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'NONE')]
|
||||
private string $version;
|
||||
|
||||
#[ORM\Column(name: 'executed_at', type: 'datetime', nullable: true)]
|
||||
private ?\DateTime $executedAt;
|
||||
|
||||
#[ORM\Column(name: 'execution_time', type: 'integer', nullable: true)]
|
||||
private ?int $executionTime;
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue