Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee05c3a

Browse files
committed
We can now insert in db / POST new data without sending a specific id ! THank you pgSQL...
1 parent 0099c3b commit ee05c3a

5 files changed

Lines changed: 48 additions & 45 deletions

File tree

api/migrations/Version20200828181711.php

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20201230215549 extends AbstractMigration
14+
{
15+
public function getDescription() : string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema) : void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('CREATE TABLE consumer (id SERIAL NOT NULL, provider_id INT NOT NULL, given_name VARCHAR(100) DEFAULT NULL, family_name VARCHAR(100) DEFAULT NULL, email VARCHAR(100) NOT NULL, PRIMARY KEY(id))');
24+
$this->addSql('CREATE INDEX IDX_705B3727A53A8AA ON consumer (provider_id)');
25+
$this->addSql('CREATE TABLE customer (id SERIAL NOT NULL, username VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
26+
$this->addSql('CREATE UNIQUE INDEX UNIQ_81398E09F85E0677 ON customer (username)');
27+
$this->addSql('CREATE TABLE product (id SERIAL NOT NULL, name VARCHAR(100) NOT NULL, brand VARCHAR(100) NOT NULL, released_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, is_available BOOLEAN NOT NULL, PRIMARY KEY(id))');
28+
$this->addSql('ALTER TABLE consumer ADD CONSTRAINT FK_705B3727A53A8AA FOREIGN KEY (provider_id) REFERENCES customer (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
29+
}
30+
31+
public function down(Schema $schema) : void
32+
{
33+
// this down() migration is auto-generated, please modify it to your needs
34+
$this->addSql('CREATE SCHEMA public');
35+
$this->addSql('ALTER TABLE consumer DROP CONSTRAINT FK_705B3727A53A8AA');
36+
$this->addSql('DROP TABLE consumer');
37+
$this->addSql('DROP TABLE customer');
38+
$this->addSql('DROP TABLE product');
39+
}
40+
}

api/src/Entity/Consumer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
* @UniqueEntity(fields="email", message="This email address already exists.")
1616
* @ApiResource(
1717
* normalizationContext={"groups"={"consumer:read"}},
18-
* denormalizationContext={"groups"={"consumer:write"}}
18+
* denormalizationContext={"groups"={"consumer:write"}},
19+
* shortName="Users"
1920
* )
2021
* @ApiFilter(SearchFilter::class, properties={"email": "partial"})
2122
*/
2223
class Consumer
2324
{
2425
/**
2526
* @ORM\Id
26-
* @ORM\GeneratedValue
27-
* @ORM\Column(type="integer")
27+
* @ORM\GeneratedValue(strategy="IDENTITY")
28+
* @ORM\Column(type="integer", nullable=false)
2829
* @Groups({"consumer:read"})
2930
*/
3031
private $id;

api/src/Entity/Customer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Customer implements UserInterface
1717
{
1818
/**
1919
* @ORM\Id
20-
* @ORM\GeneratedValue
21-
* @ORM\Column(type="integer")
20+
* @ORM\GeneratedValue(strategy="IDENTITY")
21+
* @ORM\Column(type="integer", nullable=false)
2222
*/
2323
private $id;
2424

api/src/Entity/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Product
1919
{
2020
/**
2121
* @ORM\Id
22-
* @ORM\GeneratedValue
23-
* @ORM\Column(type="integer")
22+
* @ORM\GeneratedValue(strategy="IDENTITY")
23+
* @ORM\Column(type="integer", nullable=false)
2424
*/
2525
private $id;
2626

0 commit comments

Comments
 (0)