product as OneToOne

This commit is contained in:
Sergio Álvarez 2022-05-25 09:54:28 +02:00
parent 937c2a459d
commit 258c79b954
No known key found for this signature in database
GPG Key ID: 622780889DFDBDA5
12 changed files with 66 additions and 129 deletions

2
.env
View File

@ -24,5 +24,5 @@ APP_SECRET=927b6476c39dc61a41e55ee144b865f2
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"
DATABASE_URL="sqlite:///%kernel.project_dir%/var/app.db"
DATABASE_URL="sqlite:///%kernel.project_dir%/var/app2.db"
###< doctrine/doctrine-bundle ###

View File

@ -1,65 +0,0 @@
<?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 Version20220524145844 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('DROP INDEX IDX_CA4C3EB8ED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_be_sub AS SELECT id, service_id, code, status, sub_date, unsub_date FROM mer_be_sub');
$this->addSql('DROP TABLE mer_be_sub');
$this->addSql('CREATE TABLE mer_be_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, code VARCHAR(255) DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
, CONSTRAINT FK_CA4C3EB8ED5CA9E6 FOREIGN KEY (service_id) REFERENCES mer_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO mer_be_sub (id, service_id, code, status, sub_date, unsub_date) SELECT id, service_id, code, status, sub_date, unsub_date FROM __temp__mer_be_sub');
$this->addSql('DROP TABLE __temp__mer_be_sub');
$this->addSql('CREATE INDEX IDX_CA4C3EB8ED5CA9E6 ON mer_be_sub (service_id)');
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, pin, status, sub_date, unsub_date 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, pin INTEGER DEFAULT NULL, status INTEGER NOT 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, pin, status, sub_date, unsub_date) SELECT id, service_id, pin, status, sub_date, unsub_date 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_CA4C3EB8ED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_be_sub AS SELECT id, service_id, code, status, sub_date, unsub_date FROM mer_be_sub');
$this->addSql('DROP TABLE mer_be_sub');
$this->addSql('CREATE TABLE mer_be_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, code VARCHAR(255) DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('INSERT INTO mer_be_sub (id, service_id, code, status, sub_date, unsub_date) SELECT id, service_id, code, status, sub_date, unsub_date FROM __temp__mer_be_sub');
$this->addSql('DROP TABLE __temp__mer_be_sub');
$this->addSql('CREATE INDEX IDX_CA4C3EB8ED5CA9E6 ON mer_be_sub (service_id)');
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, pin, status, sub_date, unsub_date 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, pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('INSERT INTO mer_para_sub (id, service_id, pin, status, sub_date, unsub_date) SELECT id, service_id, pin, status, sub_date, unsub_date 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)');
}
}

View File

@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220524145056 extends AbstractMigration
final class Version20220524155905 extends AbstractMigration
{
public function getDescription(): string
{
@ -25,15 +25,16 @@ final class Version20220524145056 extends AbstractMigration
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('CREATE INDEX IDX_CA4C3EB8ED5CA9E6 ON mer_be_sub (service_id)');
$this->addSql('CREATE TABLE mer_dm (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, offer_id INTEGER NOT NULL)');
$this->addSql('CREATE TABLE mer_dt (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id VARCHAR(255) NOT NULL)');
$this->addSql('CREATE TABLE mer_dm (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ott_id INTEGER DEFAULT NULL, offer_id INTEGER NOT NULL)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_C03EF7C6396F71CA ON mer_dm (ott_id)');
$this->addSql('CREATE TABLE mer_dt (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ott_id INTEGER DEFAULT NULL, service_id VARCHAR(255) NOT NULL)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_A4555F06396F71CA ON mer_dt (ott_id)');
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
$this->addSql('CREATE TABLE mer_service (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, platform_id INTEGER NOT NULL, mcc_mnc INTEGER DEFAULT NULL, metadata CLOB DEFAULT NULL --(DC2Type:json)
$this->addSql('CREATE TABLE mer_service (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, mcc_mnc INTEGER DEFAULT NULL, metadata CLOB DEFAULT NULL --(DC2Type:json)
, discr VARCHAR(255) NOT NULL, product_code VARCHAR(255) DEFAULT NULL, api_key VARCHAR(255) DEFAULT NULL, activation_code VARCHAR(255) DEFAULT NULL)');
$this->addSql('CREATE INDEX IDX_E9ABEA72FFE6496F ON mer_service (platform_id)');
}
public function down(Schema $schema): void

View File

@ -19,27 +19,27 @@ class MerFixtures extends Fixture
{
$ser1 = new MerParaDM();
$ser1->setMccMnc(12345)
->setPlatform((new MerDM())->setOfferId(221))
->setPlatform((new MerDM())->setOfferId(221)->setPlatform($ser1))
->setProductCode('code1');
$ser2 = new MerParaDM();
$ser2->setMccMnc(12345)
->setPlatform((new MerDM())->setOfferId(223))
->setPlatform((new MerDM())->setOfferId(223)->setPlatform($ser2))
->setProductCode('code2');
$ser3 = new MerParaDT();
$ser3->setMccMnc(12345)
->setPlatform((new MerDT())->setServiceId('ser-vi-ce1'))
->setPlatform((new MerDT())->setServiceId('ser-vi-ce1')->setPlatform($ser3))
->setApiKey('api1');
$ser4 = new MerParaDT();
$ser4->setMccMnc(12341)
->setPlatform((new MerDT())->setServiceId('ser-vi-ce2'))
->setPlatform((new MerDT())->setServiceId('ser-vi-ce2')->setPlatform($ser4))
->setApiKey('api2');
$ser5 = new MerBeDM();
$ser5->setMccMnc(12341)
->setPlatform((new MerDM())->setOfferId(112))
->setPlatform((new MerDM())->setOfferId(112)->setPlatform($ser5))
->setActivationCode('active1');
$sub1 = new MerParaSub();

View File

@ -6,7 +6,7 @@ use App\Repository\MerBeDMRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MerBeDMRepository::class)]
class MerBeDM extends MerService
class MerBeDM extends MerService implements OttInterface
{
// #[ORM\Id]
// #[ORM\GeneratedValue]
@ -16,10 +16,6 @@ class MerBeDM extends MerService
#[ORM\Column(type: 'string', length: 255)]
private $activation_code;
#[ORM\OneToOne(targetEntity: MerDM::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
private MerDM $platform;
// public function getId(): ?int
// {
// return $this->id;
@ -36,16 +32,4 @@ class MerBeDM extends MerService
return $this;
}
public function getPlatform(): ?MerDM
{
return $this->platform;
}
public function setPlatform(?MerDM $platform): self
{
$this->platform = $platform;
return $this;
}
}

View File

@ -6,7 +6,7 @@ use App\Repository\MerDMRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MerDMRepository::class)]
class MerDM
class MerDM extends Platform
{
#[ORM\Id]
#[ORM\GeneratedValue]

View File

@ -6,7 +6,7 @@ use App\Repository\MerDTRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MerDTRepository::class)]
class MerDT
class MerDT extends Platform
{
#[ORM\Id]
#[ORM\GeneratedValue]

View File

@ -6,7 +6,7 @@ use App\Repository\MerParaDMRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MerParaDMRepository::class)]
class MerParaDM extends MerService
class MerParaDM extends MerService implements OttInterface
{
// #[ORM\Id]
// #[ORM\GeneratedValue]
@ -16,10 +16,6 @@ class MerParaDM extends MerService
#[ORM\Column(type: 'string', length: 255)]
private $product_code;
#[ORM\OneToOne(targetEntity: MerDM::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
private MerDM $platform;
// public function getId(): ?int
// {
// return $this->id;
@ -36,16 +32,4 @@ class MerParaDM extends MerService
return $this;
}
public function getPlatform(): ?MerDM
{
return $this->platform;
}
public function setPlatform(?MerDM $platform): self
{
$this->platform = $platform;
return $this;
}
}

View File

@ -6,7 +6,7 @@ use App\Repository\MerParaDTRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MerParaDTRepository::class)]
class MerParaDT extends MerService
class MerParaDT extends MerService implements OttInterface
{
// #[ORM\Id]
// #[ORM\GeneratedValue]
@ -16,10 +16,6 @@ class MerParaDT extends MerService
#[ORM\Column(type: 'string', length: 255)]
private $api_key;
#[ORM\OneToOne(targetEntity: MerDT::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
private MerDT $platform;
// public function getId(): ?int
// {
// return $this->id;
@ -36,16 +32,4 @@ class MerParaDT extends MerService
return $this;
}
public function getPlatform(): ?MerDT
{
return $this->platform;
}
public function setPlatform(?MerDT $platform): self
{
$this->platform = $platform;
return $this;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Entity;
use App\Repository\MerServiceRepository;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\ORM\Mapping as ORM;
#[ORM\InheritanceType('SINGLE_TABLE')]
@ -26,6 +27,9 @@ abstract class MerService
#[ORM\Column(type: 'json', nullable: true)]
private $metadata = [];
#[ORM\OneToOne(targetEntity: Platform::class, cascade: ['persist'], mappedBy: 'ott')]
private Platform $platform;
public function getId(): ?int
{
return $this->id;
@ -54,4 +58,16 @@ abstract class MerService
return $this;
}
public function getPlatform(): ?Platform
{
return $this->platform;
}
public function setPlatform(?Platform $platform): self
{
$this->platform = $platform;
return $this;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\Entity;
interface OttInterface
{
}

25
src/Entity/Platform.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\MappedSuperclass]
class Platform
{
#[ORM\OneToOne(targetEntity: "MerService", inversedBy: "platform")]
#[ORM\JoinColumn(name: "ott_id", referencedColumnName: "id")]
private ?MerService $ott;
public function getOtt(): ?MerService
{
return $this->ott;
}
public function setPlatform(?MerService $ott): self
{
$this->ott = $ott;
return $this;
}
}