dates
This commit is contained in:
parent
f251e6eb0d
commit
1c542e3455
|
@ -0,0 +1,47 @@
|
||||||
|
<?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 Version20220523132530 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODIFICATION NEEDED: added DATETIME() to INSERTS to prevent:
|
||||||
|
// SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: mer_para_sub.sub_date
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, red_code FROM mer_para_sub');
|
||||||
|
$this->addSql('DROP TABLE mer_para_sub');
|
||||||
|
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, red_code VARCHAR(255) DEFAULT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
|
||||||
|
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
|
||||||
|
, CONSTRAINT FK_E4F82A3DED5CA9E6 FOREIGN KEY (service_id) REFERENCES mer_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO mer_para_sub (id, service_id, red_code, sub_date) SELECT id, service_id, red_code, DATETIME() FROM __temp__mer_para_sub');
|
||||||
|
$this->addSql('DROP TABLE __temp__mer_para_sub');
|
||||||
|
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, red_code FROM mer_para_sub');
|
||||||
|
$this->addSql('DROP TABLE mer_para_sub');
|
||||||
|
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, red_code VARCHAR(255) DEFAULT NULL)');
|
||||||
|
$this->addSql('INSERT INTO mer_para_sub (id, service_id, red_code) SELECT id, service_id, red_code FROM __temp__mer_para_sub');
|
||||||
|
$this->addSql('DROP TABLE __temp__mer_para_sub');
|
||||||
|
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ class IndexController extends AbstractController
|
||||||
$sm = $repo->getSchemaManager();
|
$sm = $repo->getSchemaManager();
|
||||||
$entity8 = $repo->findOneByName('entity 8');
|
$entity8 = $repo->findOneByName('entity 8');
|
||||||
|
|
||||||
$sub = $subRepo->findOneById(1);
|
$sub = $subRepo->findOne();
|
||||||
dump($sub);
|
dump($sub);
|
||||||
dump($sub->getService());
|
dump($sub->getService());
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class MerFixtures extends Fixture
|
||||||
$manager->persist($tmp);
|
$manager->persist($tmp);
|
||||||
|
|
||||||
$sub = new MerParaSub();
|
$sub = new MerParaSub();
|
||||||
$sub->setService($tmp)->setRedCode('redcode1');
|
$sub->setService($tmp)->setRedCode('redcode1')->setSubDate(new \DateTimeImmutable('now'));
|
||||||
$manager->persist($sub);
|
$manager->persist($sub);
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
|
@ -20,6 +20,12 @@ class MerParaSub
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
private MerService $service;
|
private MerService $service;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'datetime_immutable')]
|
||||||
|
private $subDate;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
||||||
|
private $unsubDate;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
@ -48,4 +54,28 @@ class MerParaSub
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSubDate(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->subDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSubDate(\DateTimeImmutable $subDate): self
|
||||||
|
{
|
||||||
|
$this->subDate = $subDate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUnsubDate(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->unsubDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUnsubDate(?\DateTimeImmutable $unsubDate): self
|
||||||
|
{
|
||||||
|
$this->unsubDate = $unsubDate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,4 +63,14 @@ class MerParaSubRepository extends ServiceEntityRepository
|
||||||
->getOneOrNullResult()
|
->getOneOrNullResult()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findOne(): ?MerParaSub
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('m')
|
||||||
|
->orderBy('m.id', 'DESC')
|
||||||
|
->setMaxResults(1)
|
||||||
|
->getQuery()
|
||||||
|
->getOneOrNullResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue