Création de la base de donnée (du moins, des scripts pour la base de donnée)

This commit is contained in:
Mysaa 2022-11-16 14:49:55 +01:00
parent 1aa054ab4c
commit 87c1d313fb
Signed by: Mysaa
GPG Key ID: 7054D5D6A90F084F
25 changed files with 2750 additions and 4 deletions

View File

@ -7,15 +7,17 @@
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.13",
"symfony/console": "5.4.*",
"symfony/dotenv": "5.4.*",
"symfony/flex": "^1.17|^2",
"symfony/framework-bundle": "5.4.*",
"symfony/proxy-manager-bridge": "5.4.*",
"symfony/runtime": "5.4.*",
"symfony/yaml": "5.4.*"
},
"require-dev": {
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
@ -63,5 +65,8 @@
"allow-contrib": false,
"require": "5.4.*"
}
},
"require-dev": {
"symfony/maker-bundle": "^1.43"
}
}

1916
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,4 +2,7 @@
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
];

View File

@ -0,0 +1,45 @@
doctrine:
dbal:
driver: 'pdo_pgsql'
dbname: 'encartes-data'
host: '127.0.0.1'
port: 5432
user: 'encartes'
password: 'c0BanMCsQyxmPXhU1TjgXNvoSuXVsSNrxeWHKHyTYMk='
server_version: '13'
charset: 'utf8'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system

View File

@ -0,0 +1,6 @@
doctrine_migrations:
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
'DoctrineMigrations': '%kernel.project_dir%/migrations'
enable_profiler: false

View File

@ -0,0 +1,7 @@
controllers:
resource: ../../src/Controller/
type: annotation
kernel:
resource: ../../src/Kernel.php
type: annotation

View File

@ -0,0 +1,8 @@
version: '3'
services:
###> doctrine/doctrine-bundle ###
database:
ports:
- "5432"
###< doctrine/doctrine-bundle ###

21
docker-compose.yml Normal file
View File

@ -0,0 +1,21 @@
version: '3'
services:
###> doctrine/doctrine-bundle ###
database:
image: postgres:${POSTGRES_VERSION:-14}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
# You should definitely change the password in production
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!U9vqdZlhMPI5yUy2I7wRg7DPpUPmIvQoe76aZ0Y!}
POSTGRES_USER: ${POSTGRES_USER:-app}
volumes:
- db-data:/var/lib/postgresql/data:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# - ./docker/db/data:/var/lib/postgresql/data:rw
###< doctrine/doctrine-bundle ###
volumes:
###> doctrine/doctrine-bundle ###
db-data:
###< doctrine/doctrine-bundle ###

0
migrations/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,57 @@
<?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 Version20221116134026 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 building_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE corridor_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE floor_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE place_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE room_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE site_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE building (id INT NOT NULL, site_id INT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_E16F61D4F6BD1646 ON building (site_id)');
$this->addSql('CREATE TABLE corridor (id INT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE floor (id INT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE place (id INT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE room (id INT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE site (id INT NOT NULL, zero_latitude DOUBLE PRECISION NOT NULL, zero_longitude DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))');
$this->addSql('ALTER TABLE building ADD CONSTRAINT FK_E16F61D4F6BD1646 FOREIGN KEY (site_id) REFERENCES site (id) 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('DROP SEQUENCE building_id_seq CASCADE');
$this->addSql('DROP SEQUENCE corridor_id_seq CASCADE');
$this->addSql('DROP SEQUENCE floor_id_seq CASCADE');
$this->addSql('DROP SEQUENCE place_id_seq CASCADE');
$this->addSql('DROP SEQUENCE room_id_seq CASCADE');
$this->addSql('DROP SEQUENCE site_id_seq CASCADE');
$this->addSql('ALTER TABLE building DROP CONSTRAINT FK_E16F61D4F6BD1646');
$this->addSql('DROP TABLE building');
$this->addSql('DROP TABLE corridor');
$this->addSql('DROP TABLE floor');
$this->addSql('DROP TABLE place');
$this->addSql('DROP TABLE room');
$this->addSql('DROP TABLE site');
}
}

0
src/Entity/.gitignore vendored Normal file
View File

42
src/Entity/Building.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace App\Entity;
use App\Repository\BuildingRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=BuildingRepository::class)
*/
class Building
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Site::class, inversedBy="buildings")
* @ORM\JoinColumn(nullable=false)
*/
private $site;
public function getId(): ?int
{
return $this->id;
}
public function getSite(): ?Site
{
return $this->site;
}
public function setSite(?Site $site): self
{
$this->site = $site;
return $this;
}
}

24
src/Entity/Corridor.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use App\Repository\CorridorRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CorridorRepository::class)
*/
class Corridor
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}

24
src/Entity/Floor.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use App\Repository\FloorRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=FloorRepository::class)
*/
class Floor
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}

24
src/Entity/Place.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use App\Repository\PlaceRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=PlaceRepository::class)
*/
class Place
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}

24
src/Entity/Room.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use App\Repository\RoomRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=RoomRepository::class)
*/
class Room
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}

100
src/Entity/Site.php Normal file
View File

@ -0,0 +1,100 @@
<?php
namespace App\Entity;
use App\Repository\SiteRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=SiteRepository::class)
*/
class Site
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="float")
*/
private $zeroLatitude;
/**
* @ORM\Column(type="float")
*/
private $zeroLongitude;
/**
* @ORM\OneToMany(targetEntity=Building::class, mappedBy="site")
*/
private $buildings;
public function __construct()
{
$this->buildings = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getZeroLatitude(): ?float
{
return $this->zeroLatitude;
}
public function setZeroLatitude(float $zeroLatitude): self
{
$this->zeroLatitude = $zeroLatitude;
return $this;
}
public function getZeroLongitude(): ?float
{
return $this->zeroLongitude;
}
public function setZeroLongitude(float $zeroLongitude): self
{
$this->zeroLongitude = $zeroLongitude;
return $this;
}
/**
* @return Collection<int, Building>
*/
public function getBuildings(): Collection
{
return $this->buildings;
}
public function addBuilding(Building $building): self
{
if (!$this->buildings->contains($building)) {
$this->buildings[] = $building;
$building->setSite($this);
}
return $this;
}
public function removeBuilding(Building $building): self
{
if ($this->buildings->removeElement($building)) {
// set the owning side to null (unless already changed)
if ($building->getSite() === $this) {
$building->setSite(null);
}
}
return $this;
}
}

0
src/Repository/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Building;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Building>
*
* @method Building|null find($id, $lockMode = null, $lockVersion = null)
* @method Building|null findOneBy(array $criteria, array $orderBy = null)
* @method Building[] findAll()
* @method Building[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BuildingRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Building::class);
}
public function add(Building $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Building $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Building[] Returns an array of Building objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('b.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Building
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Corridor;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Corridor>
*
* @method Corridor|null find($id, $lockMode = null, $lockVersion = null)
* @method Corridor|null findOneBy(array $criteria, array $orderBy = null)
* @method Corridor[] findAll()
* @method Corridor[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CorridorRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Corridor::class);
}
public function add(Corridor $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Corridor $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Corridor[] Returns an array of Corridor objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Corridor
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Floor;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Floor>
*
* @method Floor|null find($id, $lockMode = null, $lockVersion = null)
* @method Floor|null findOneBy(array $criteria, array $orderBy = null)
* @method Floor[] findAll()
* @method Floor[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class FloorRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Floor::class);
}
public function add(Floor $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Floor $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Floor[] Returns an array of Floor objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('f.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Floor
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Place;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Place>
*
* @method Place|null find($id, $lockMode = null, $lockVersion = null)
* @method Place|null findOneBy(array $criteria, array $orderBy = null)
* @method Place[] findAll()
* @method Place[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PlaceRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Place::class);
}
public function add(Place $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Place $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Place[] Returns an array of Place objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Place
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Room;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Room>
*
* @method Room|null find($id, $lockMode = null, $lockVersion = null)
* @method Room|null findOneBy(array $criteria, array $orderBy = null)
* @method Room[] findAll()
* @method Room[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class RoomRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Room::class);
}
public function add(Room $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Room $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Room[] Returns an array of Room objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('r.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Room
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Site;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Site>
*
* @method Site|null find($id, $lockMode = null, $lockVersion = null)
* @method Site|null findOneBy(array $criteria, array $orderBy = null)
* @method Site[] findAll()
* @method Site[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SiteRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Site::class);
}
public function add(Site $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Site $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Site[] Returns an array of Site objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Site
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -1,4 +1,43 @@
{
"doctrine/annotations": {
"version": "1.13",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "a2759dd6123694c8d901d0ec80006e044c2e6457"
},
"files": [
"config/routes/annotations.yaml"
]
},
"doctrine/doctrine-bundle": {
"version": "2.7",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.4",
"ref": "da713d006953b90d1c085c1be480ecdd6c4a95e0"
},
"files": [
"config/packages/doctrine.yaml",
"src/Entity/.gitignore",
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.1",
"ref": "1d01ec03c6ecbd67c3375c5478c9a423ae5d6a33"
},
"files": [
"config/packages/doctrine_migrations.yaml",
"migrations/.gitignore"
]
},
"symfony/console": {
"version": "5.4",
"recipe": {
@ -42,6 +81,15 @@
"src/Kernel.php"
]
},
"symfony/maker-bundle": {
"version": "1.43",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
}
},
"symfony/routing": {
"version": "5.4",
"recipe": {