🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #232372

Re: Migracje w Symfony 4 - jak je budować automatycznie?

#232372
From: Marek S
Date: Tue, 16 Apr 2019 20:39
92 lines
3319 bytes
W dniu 2019-04-16 o 09:43, Wojciech Bancer pisze:
> 
> Symfony nie ma nic do tego, bazy obsługuje Doctrine.

Doctrine to nie jest jeden z pierdyliona komponentów Symfony?

> A Doctrine zrobił najprawdopodobniej to co mu kazałeś.
> Pokaż definicję tej encji, bo bez tego to się tylko można domyślać.

Proszę bardzo:

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
  * @ORM\Entity(repositoryClass="App\Repository\UsersRepository")
  */
class Users
{
     /**
      * @ORM\Id()
      * @ORM\GeneratedValue()
      * @ORM\Column(type="integer")
      */
     private $id;

     /**
      * @ORM\Column(type="string", length=255)
      */
     private $name;

     public function getId(): ?int
     {
         return $this->id;
     }

     public function getName(): ?string
     {
         return $this->name;
     }

     public function setName(string $name): self
     {
         $this->name = $name;

         return $this;
     }
}

Co do typów mapowania, to jeszcze nie wiem, gdzie tego się dokonuje. 
Znalazłem w config/packages/doctrine.yaml

parameters:
     # Adds a fallback DATABASE_URL if the env var is not set.
     # This allows you to run cache:warmup even if your
     # environment variables are not available yet.
     # You should not need to change this value.
     env(DATABASE_URL): ''

doctrine:
     dbal:
         # configure these for your database server
         driver: 'pdo_pgsql'
         server_version: '10.5'
         charset: utf8
         default_table_options:
             charset: utf8
             collate: utf8_unicode_ci

         url: '%env(resolve:DATABASE_URL)%'
     orm:
         auto_generate_proxy_classes: true
         naming_strategy: doctrine.orm.naming_strategy.underscore
         auto_mapping: true
         mappings:
             App:
                 is_bundle: false
                 type: annotation
                 dir: '%kernel.project_dir%/src/Entity'
                 prefix: 'App\Entity'
                 alias: App

Czy o to chodziło?

Generalnie wszystko działo się samo: ja niczego nie "kazałem" poza 
podaniem typu pola name. Generator make:entity nie pytał się mnie o 
żadne sekwencje, o primary key też nie. Nie miałem na nic wpływu.

-- 
Pozdrawiam,
Marek
Technical Details
Message-ID: <q95ehk$ie4$1@node2.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
References: <q930nv$c5i$1@node2.news.atman.pl> <slrnqbb1ta.1t8l.wojciech.bancer@pl-test.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: Marek S <precz@spamowi.com>
Newsgroups: pl.comp.lang.php
Subject: Re: Migracje w Symfony 4 - jak je budować
 automatycznie?
Date: Tue, 16 Apr 2019 22:39:14 +0200
Organization: ATMAN - ATM S.A.
Lines: 92
Message-ID: <q95ehk$ie4$1@node2.news.atman.pl>
References: <q930nv$c5i$1@node2.news.atman.pl> <slrnqbb1ta.1t8l.wojciech.bancer@pl-test.org>
NNTP-Posting-Host: 89-70-94-204.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: node2.news.atman.pl 1555447156 18884 89.70.94.204 (16 Apr 2019 20:39:16 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Tue, 16 Apr 2019 20:39:16 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1
In-Reply-To: <slrnqbb1ta.1t8l.wojciech.bancer@pl-test.org>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit