Moved to PostgreSQL.
This commit is contained in:
parent
c900f2a8a5
commit
b7c6539477
|
@ -1,46 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Application\Migrations;
|
|
||||||
|
|
||||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-generated Migration: Please modify to your needs!
|
|
||||||
*/
|
|
||||||
class Version20150329170323 extends AbstractMigration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param Schema $schema
|
|
||||||
*/
|
|
||||||
public function up(Schema $schema)
|
|
||||||
{
|
|
||||||
// this up() migration is auto-generated, please modify it to your needs
|
|
||||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
|
||||||
|
|
||||||
$this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, login VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, INDEX idx_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
|
||||||
$this->addSql('CREATE TABLE subscriptions_events (id INT AUTO_INCREMENT NOT NULL, subscriber_id INT NOT NULL, author_id INT NOT NULL, date DATETIME NOT NULL, action VARCHAR(12) NOT NULL, INDEX IDX_7778274B7808B1AD (subscriber_id), INDEX IDX_7778274BF675F31B (author_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
|
||||||
$this->addSql('CREATE TABLE subscriptions (author_id INT NOT NULL, subscriber_id INT NOT NULL, INDEX IDX_4778A01F675F31B (author_id), INDEX IDX_4778A017808B1AD (subscriber_id), PRIMARY KEY(author_id, subscriber_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions_events ADD CONSTRAINT FK_7778274B7808B1AD FOREIGN KEY (subscriber_id) REFERENCES users (id)');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions_events ADD CONSTRAINT FK_7778274BF675F31B FOREIGN KEY (author_id) REFERENCES users (id)');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions ADD CONSTRAINT FK_4778A01F675F31B FOREIGN KEY (author_id) REFERENCES users (id)');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions ADD CONSTRAINT FK_4778A017808B1AD FOREIGN KEY (subscriber_id) REFERENCES users (id)');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Schema $schema
|
|
||||||
*/
|
|
||||||
public function down(Schema $schema)
|
|
||||||
{
|
|
||||||
// this down() migration is auto-generated, please modify it to your needs
|
|
||||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
|
||||||
|
|
||||||
$this->addSql('ALTER TABLE subscriptions_events DROP FOREIGN KEY FK_7778274B7808B1AD');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions_events DROP FOREIGN KEY FK_7778274BF675F31B');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions DROP FOREIGN KEY FK_4778A01F675F31B');
|
|
||||||
$this->addSql('ALTER TABLE subscriptions DROP FOREIGN KEY FK_4778A017808B1AD');
|
|
||||||
$this->addSql('DROP TABLE users');
|
|
||||||
$this->addSql('DROP TABLE subscriptions_events');
|
|
||||||
$this->addSql('DROP TABLE subscriptions');
|
|
||||||
}
|
|
||||||
}
|
|
59
app/DoctrineMigrations/Version20150528203127.php
Normal file
59
app/DoctrineMigrations/Version20150528203127.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Application\Migrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PostgreSQL database initialization
|
||||||
|
*/
|
||||||
|
class Version20150528203127 extends AbstractMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Schema $schema
|
||||||
|
*/
|
||||||
|
public function up(Schema $schema)
|
||||||
|
{
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||||
|
|
||||||
|
$this->addSql('CREATE SCHEMA IF NOT EXISTS users');
|
||||||
|
$this->addSql('CREATE SCHEMA IF NOT EXISTS subscriptions');
|
||||||
|
|
||||||
|
$this->addSql('CREATE SEQUENCE subscriptions.log_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||||
|
$this->addSql('CREATE TABLE subscriptions.subscriptions (author_id INT NOT NULL, subscriber_id INT NOT NULL, PRIMARY KEY(author_id, subscriber_id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_3B7621A2F675F31B ON subscriptions.subscriptions (author_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_3B7621A27808B1AD ON subscriptions.subscriptions (subscriber_id)');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX subscription_unique ON subscriptions.subscriptions (author_id, subscriber_id)');
|
||||||
|
$this->addSql('CREATE TABLE subscriptions.log (id INT NOT NULL, author_id INT NOT NULL, subscriber_id INT NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, action VARCHAR(12) NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_22DA64DDF675F31B ON subscriptions.log (author_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_22DA64DD7808B1AD ON subscriptions.log (subscriber_id)');
|
||||||
|
$this->addSql('CREATE INDEX date_idx ON subscriptions.log (date)');
|
||||||
|
$this->addSql('CREATE TABLE users.users (id INT NOT NULL, login VARCHAR(255) NOT NULL, name VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_338ADFC4AA08CB10 ON users.users (login)');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.subscriptions ADD CONSTRAINT FK_3B7621A2F675F31B FOREIGN KEY (author_id) REFERENCES users.users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.subscriptions ADD CONSTRAINT FK_3B7621A27808B1AD FOREIGN KEY (subscriber_id) REFERENCES users.users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.log ADD CONSTRAINT FK_22DA64DDF675F31B FOREIGN KEY (author_id) REFERENCES users.users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.log ADD CONSTRAINT FK_22DA64DD7808B1AD FOREIGN KEY (subscriber_id) REFERENCES users.users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Schema $schema
|
||||||
|
*/
|
||||||
|
public function down(Schema $schema)
|
||||||
|
{
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.subscriptions DROP CONSTRAINT FK_3B7621A2F675F31B');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.subscriptions DROP CONSTRAINT FK_3B7621A27808B1AD');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.log DROP CONSTRAINT FK_22DA64DDF675F31B');
|
||||||
|
$this->addSql('ALTER TABLE subscriptions.log DROP CONSTRAINT FK_22DA64DD7808B1AD');
|
||||||
|
$this->addSql('DROP SEQUENCE subscriptions.log_id_seq CASCADE');
|
||||||
|
$this->addSql('DROP TABLE subscriptions.subscriptions');
|
||||||
|
$this->addSql('DROP TABLE subscriptions.log');
|
||||||
|
$this->addSql('DROP TABLE users.users');
|
||||||
|
|
||||||
|
$this->addSql('DROP SCHEMA IF EXISTS users');
|
||||||
|
$this->addSql('DROP SCHEMA IF EXISTS subscriptions');
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,12 +53,6 @@ doctrine:
|
||||||
user: "%database_user%"
|
user: "%database_user%"
|
||||||
password: "%database_password%"
|
password: "%database_password%"
|
||||||
charset: UTF8
|
charset: UTF8
|
||||||
# if using pdo_sqlite as your database driver:
|
|
||||||
# 1. add the path in parameters.yml
|
|
||||||
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
|
|
||||||
# 2. Uncomment database_path in parameters.yml.dist
|
|
||||||
# 3. Uncomment next line:
|
|
||||||
# path: "%database_path%"
|
|
||||||
|
|
||||||
orm:
|
orm:
|
||||||
auto_generate_proxy_classes: "%kernel.debug%"
|
auto_generate_proxy_classes: "%kernel.debug%"
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
# This file is a "template" of what your parameters.yml file should look like
|
# This file is a "template" of what your parameters.yml file should look like
|
||||||
parameters:
|
parameters:
|
||||||
database_driver: pdo_mysql
|
database_driver: pdo_pgsql
|
||||||
database_host: 127.0.0.1
|
database_host: 127.0.0.1
|
||||||
database_port: ~
|
database_port: ~
|
||||||
database_name: symfony
|
database_name: point
|
||||||
database_user: root
|
database_user: point
|
||||||
database_password: ~
|
database_password: ~
|
||||||
# You should uncomment this if you want use pdo_sqlite
|
|
||||||
# database_path: "%kernel.root_dir%/data.db3"
|
|
||||||
|
|
||||||
mailer_transport: smtp
|
mailer_transport: smtp
|
||||||
mailer_host: 127.0.0.1
|
mailer_host: 127.0.0.1
|
||||||
|
|
|
@ -7,8 +7,10 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
/**
|
/**
|
||||||
* Subscription
|
* Subscription
|
||||||
*
|
*
|
||||||
* @ORM\Table(name="subscriptions")
|
* @ORM\Table(name="subscriptions.subscriptions", uniqueConstraints={
|
||||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionRepository")
|
* @ORM\UniqueConstraint(name="subscription_unique", columns={"author_id", "subscriber_id"})}
|
||||||
|
* )
|
||||||
|
* @ORM\Entity
|
||||||
*/
|
*/
|
||||||
class Subscription
|
class Subscription
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,11 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
/**
|
/**
|
||||||
* SubscriptionEvent
|
* SubscriptionEvent
|
||||||
*
|
*
|
||||||
* @ORM\Table(name="subscriptions_events")
|
* @ORM\Table(name="subscriptions.log", indexes={
|
||||||
|
* @ORM\Index(name="author_idx", columns={"author_id"}),
|
||||||
|
* @ORM\Index(name="subscriber_idx", columns={"subscriber_id"}),
|
||||||
|
* @ORM\Index(name="date_idx", columns={"date"})
|
||||||
|
* })
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
*/
|
*/
|
||||||
class SubscriptionEvent
|
class SubscriptionEvent
|
||||||
|
@ -23,29 +27,29 @@ class SubscriptionEvent
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var User Blog author
|
||||||
|
*
|
||||||
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriberEvents")
|
||||||
|
* @ORM\JoinColumn(name="author_id", nullable=false)
|
||||||
|
*/
|
||||||
|
private $author;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var User Blog subscriber
|
* @var User Blog subscriber
|
||||||
*
|
*
|
||||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriptionEvents")
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriptionEvents")
|
||||||
* @ORM\JoinColumn(name="subscriber_id", nullable=false)
|
* @ORM\JoinColumn(name="subscriber_id", nullable=false)
|
||||||
*/
|
*/
|
||||||
private $subscriber;
|
private $subscriber;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var User Blog author
|
|
||||||
*
|
|
||||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriberEvents")
|
|
||||||
* @ORM\JoinColumn(name="author_id", nullable=false)
|
|
||||||
*/
|
|
||||||
private $author;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
*
|
*
|
||||||
* @ORM\Column(name="date", type="datetime", nullable=false)
|
* @ORM\Column(name="date", type="datetime", nullable=false)
|
||||||
*/
|
*/
|
||||||
private $dateTime;
|
private $date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -57,7 +61,7 @@ class SubscriptionEvent
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
*
|
*
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getId()
|
public function getId()
|
||||||
{
|
{
|
||||||
|
@ -65,26 +69,26 @@ class SubscriptionEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set dateTime
|
* Set date
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateTime
|
* @param \DateTime $date
|
||||||
* @return SubscriptionEvent
|
* @return SubscriptionEvent
|
||||||
*/
|
*/
|
||||||
public function setDateTime($dateTime)
|
public function setDate($date)
|
||||||
{
|
{
|
||||||
$this->dateTime = $dateTime;
|
$this->date = $date;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get dateTime
|
* Get date
|
||||||
*
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
public function getDateTime()
|
public function getDate()
|
||||||
{
|
{
|
||||||
return $this->dateTime;
|
return $this->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Skobkin\Bundle\PointToolsBundle\Entity;
|
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubscriptionRepository
|
|
||||||
*
|
|
||||||
* This class was generated by the Doctrine ORM. Add your own custom
|
|
||||||
* repository methods below.
|
|
||||||
*/
|
|
||||||
class SubscriptionRepository extends EntityRepository
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -8,10 +8,9 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
/**
|
/**
|
||||||
* User
|
* User
|
||||||
*
|
*
|
||||||
* @ORM\Table(name="users", indexes={
|
* @ORM\Table(name="users.users")
|
||||||
* @ORM\Index(name="idx_name", columns={"name"})
|
|
||||||
* })
|
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
* @ORM\HasLifecycleCallbacks
|
||||||
*/
|
*/
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
@ -20,24 +19,30 @@ class User
|
||||||
*
|
*
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(name="login", type="string", length=255)
|
* @ORM\Column(name="login", type="string", length=255, nullable=false, unique=true)
|
||||||
*/
|
*/
|
||||||
private $login;
|
private $login;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(name="name", type="string", length=255)
|
* @ORM\Column(name="name", type="string", length=255, nullable=true)
|
||||||
*/
|
*/
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \DateTime
|
||||||
|
*
|
||||||
|
* @ORM\Column(name="created_at", type="datetime")
|
||||||
|
*/
|
||||||
|
private $createdAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ArrayCollection
|
* @var ArrayCollection
|
||||||
*
|
*
|
||||||
|
@ -74,6 +79,14 @@ class User
|
||||||
$this->newSubscriptionEvents = new ArrayCollection();
|
$this->newSubscriptionEvents = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\PrePersist
|
||||||
|
*/
|
||||||
|
public function onCreate()
|
||||||
|
{
|
||||||
|
$this->createdAt = new \DateTime();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
*
|
*
|
||||||
|
@ -274,4 +287,22 @@ class User
|
||||||
{
|
{
|
||||||
return $this->newSubscriberEvents;
|
return $this->newSubscriberEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \DateTime $createdAt
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
|
public function setCreatedAt($createdAt)
|
||||||
|
{
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue