mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
fix folder name
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Insert Main Bundle table and indexes
|
||||
*/
|
||||
class Version20141128194409 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql("CREATE TABLE Country (id INT NOT NULL, name JSON NOT NULL, countryCode VARCHAR(3) NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE TABLE centers (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE TABLE Language (id VARCHAR(255) NOT NULL, name JSON NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE TABLE group_centers (id INT NOT NULL, center_id INT DEFAULT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE INDEX IDX_A14D8F3D5932F377 ON group_centers (center_id);");
|
||||
$this->addSql("CREATE TABLE groupcenter_permissionsgroup (groupcenter_id INT NOT NULL, permissionsgroup_id INT NOT NULL, PRIMARY KEY(groupcenter_id, permissionsgroup_id));");
|
||||
$this->addSql("CREATE INDEX IDX_55DFEC607EC2FA68 ON groupcenter_permissionsgroup (groupcenter_id);");
|
||||
$this->addSql("CREATE INDEX IDX_55DFEC606FA97D46 ON groupcenter_permissionsgroup (permissionsgroup_id);");
|
||||
$this->addSql("CREATE TABLE role_scopes (id INT NOT NULL, scope_id INT DEFAULT NULL, role VARCHAR(255) NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE INDEX IDX_AFF20281682B5931 ON role_scopes (scope_id);");
|
||||
$this->addSql("CREATE TABLE permission_groups (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE TABLE permissionsgroup_rolescope (permissionsgroup_id INT NOT NULL, rolescope_id INT NOT NULL, PRIMARY KEY(permissionsgroup_id, rolescope_id));");
|
||||
$this->addSql("CREATE INDEX IDX_B22441DC6FA97D46 ON permissionsgroup_rolescope (permissionsgroup_id);");
|
||||
$this->addSql("CREATE INDEX IDX_B22441DCA0AE1DB7 ON permissionsgroup_rolescope (rolescope_id);");
|
||||
$this->addSql("CREATE TABLE users (id INT NOT NULL, username VARCHAR(80) NOT NULL, password VARCHAR(255) NOT NULL, salt VARCHAR(255) DEFAULT NULL, enabled BOOLEAN NOT NULL, locked BOOLEAN NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE TABLE user_groupcenter (user_id INT NOT NULL, groupcenter_id INT NOT NULL, PRIMARY KEY(user_id, groupcenter_id));");
|
||||
$this->addSql("CREATE INDEX IDX_33FFE54AA76ED395 ON user_groupcenter (user_id);");
|
||||
$this->addSql("CREATE INDEX IDX_33FFE54A7EC2FA68 ON user_groupcenter (groupcenter_id);");
|
||||
$this->addSql("CREATE TABLE scopes (id INT NOT NULL, name JSON NOT NULL, PRIMARY KEY(id));");
|
||||
$this->addSql("CREATE SEQUENCE Country_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("CREATE SEQUENCE centers_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("CREATE SEQUENCE group_centers_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("CREATE SEQUENCE role_scopes_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("CREATE SEQUENCE permission_groups_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("CREATE SEQUENCE users_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("CREATE SEQUENCE scopes_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
|
||||
$this->addSql("ALTER TABLE group_centers ADD CONSTRAINT FK_A14D8F3D5932F377 FOREIGN KEY (center_id) REFERENCES centers (id) NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE groupcenter_permissionsgroup ADD CONSTRAINT FK_55DFEC607EC2FA68 FOREIGN KEY (groupcenter_id) REFERENCES group_centers (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE groupcenter_permissionsgroup ADD CONSTRAINT FK_55DFEC606FA97D46 FOREIGN KEY (permissionsgroup_id) REFERENCES permission_groups (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE role_scopes ADD CONSTRAINT FK_AFF20281682B5931 FOREIGN KEY (scope_id) REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE permissionsgroup_rolescope ADD CONSTRAINT FK_B22441DC6FA97D46 FOREIGN KEY (permissionsgroup_id) REFERENCES permission_groups (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE permissionsgroup_rolescope ADD CONSTRAINT FK_B22441DCA0AE1DB7 FOREIGN KEY (rolescope_id) REFERENCES role_scopes (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE user_groupcenter ADD CONSTRAINT FK_33FFE54AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
$this->addSql("ALTER TABLE user_groupcenter ADD CONSTRAINT FK_33FFE54A7EC2FA68 FOREIGN KEY (groupcenter_id) REFERENCES group_centers (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
|
||||
}
|
||||
}
|
145
src/Bundle/ChillMainBundle/migrations/Version20150821105642.php
Normal file
145
src/Bundle/ChillMainBundle/migrations/Version20150821105642.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
/**
|
||||
* Migrate association from
|
||||
* ManyToMany between PermissionGroup <-> GroupCenter
|
||||
* to
|
||||
* ManyToOne : a GroupCenter can have only one PermissionGroup
|
||||
*
|
||||
* @link https://redmine.champs-libres.coop/issues/578 The issue describing the move
|
||||
*/
|
||||
class Version20150821105642 extends AbstractMigration implements
|
||||
\Symfony\Component\DependencyInjection\ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE group_centers ADD permissionsGroup_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE group_centers ADD CONSTRAINT FK_A14D8F3D447BBB3B FOREIGN KEY (permissionsGroup_id) REFERENCES permission_groups (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('CREATE INDEX IDX_A14D8F3D447BBB3B ON group_centers (permissionsGroup_id)');
|
||||
|
||||
}
|
||||
|
||||
public function postUp(Schema $schema): void
|
||||
{
|
||||
/*
|
||||
* Before the upgrade to symfony version 4, this code worked.
|
||||
*
|
||||
* But it doesn't work any more after the migration and currently this
|
||||
* code should note be necessary.
|
||||
*
|
||||
* This code is kept for reference, and may be re-activated if needed, but
|
||||
* the probability that this will happens is near 0
|
||||
*/
|
||||
return;
|
||||
|
||||
|
||||
//transform data from groupcenter_permissionsgroup table
|
||||
$em = $this->container->get('doctrine.orm.entity_manager');
|
||||
|
||||
//get all existing associations
|
||||
$rsm = new ResultSetMapping();
|
||||
$rsm->addScalarResult('groupcenter_id', 'groupcenter_id');
|
||||
$rsm->addScalarResult('permissionsgroup_id', 'permissionsgroup_id');
|
||||
|
||||
$groupPermissionsAssociations = $em->createNativeQuery(
|
||||
"SELECT groupcenter_id, permissionsgroup_id "
|
||||
. "FROM groupcenter_permissionsgroup",
|
||||
$rsm
|
||||
)
|
||||
->getScalarResult();
|
||||
|
||||
//update
|
||||
foreach ($groupPermissionsAssociations as $groupPermissionAssociation) {
|
||||
//get the corresponding groupCenter
|
||||
$rsmGroupCenter = new ResultSetMapping();
|
||||
$rsmGroupCenter->addScalarResult('id', 'id');
|
||||
$rsmGroupCenter->addScalarResult('permissionsGroup_id', 'permissionsGroup_id');
|
||||
$rsmGroupCenter->addScalarResult('center_id', 'center_id');
|
||||
|
||||
$groupCenters = $em->createNativeQuery("SELECT id, permissionsGroup_id, center_id "
|
||||
. "FROM group_centers "
|
||||
. "WHERE id = :groupcenter_id AND permissionsGroup_id IS NULL",
|
||||
$rsmGroupCenter)
|
||||
->setParameter('groupcenter_id', $groupPermissionAssociation['groupcenter_id'])
|
||||
->getResult();
|
||||
|
||||
if (count($groupCenters) === 1) {
|
||||
// we have to update this group with the current association
|
||||
$em->getConnection()->executeUpdate("UPDATE group_centers "
|
||||
. "SET permissionsGroup_id = ? "
|
||||
. "WHERE id = ?", array(
|
||||
$groupPermissionAssociation['permissionsgroup_id'],
|
||||
$groupPermissionAssociation['groupcenter_id'])
|
||||
);
|
||||
} elseif (count($groupCenters) === 0) {
|
||||
// the association was multiple. We have to create a new group_center
|
||||
$rsmNewId = new ResultSetMapping();
|
||||
$rsmNewId->addScalarResult('new_id', 'new_id');
|
||||
$newId = $em->createNativeQuery("select nextval('group_centers_id_seq') as new_id",
|
||||
$rsmNewId)
|
||||
->getSingleScalarResult();
|
||||
|
||||
$em->getConnection()->insert("group_centers", array(
|
||||
'id' => $newId,
|
||||
'center_id' => $group_center['center_id'],
|
||||
'permissionsGroup_id' => $groupPermissionAssociation['permissionsgroup_id']
|
||||
));
|
||||
|
||||
// we have to link existing users to new created groupcenter
|
||||
$em->getConnection()->executeQuery('INSERT INTO user_groupcenter '
|
||||
. '(user_id, groupcenter_id) SELECT user_id, '.$newId.' '
|
||||
. 'FROM user_groupcenter WHERE groupcenter_id = '
|
||||
.$groupPermissionAssociation['groupcenter_id']);
|
||||
} else {
|
||||
throw new \RuntimeException("Error in the data : we should not have two groupCenter "
|
||||
. "with the same id !");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE group_centers DROP CONSTRAINT FK_A14D8F3D447BBB3B');
|
||||
$this->addSql('DROP INDEX IDX_A14D8F3D447BBB3B');
|
||||
$this->addSql('ALTER TABLE group_centers DROP permissionGroup_id');
|
||||
|
||||
}
|
||||
|
||||
public function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container = null)
|
||||
{
|
||||
if ($container === NULL) {
|
||||
throw new \RuntimeException('Container is not provided. This migration '
|
||||
. 'need container to set a default center');
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* drop table groupcenter_permissionsgroup, not necessary after
|
||||
* 20150821105642
|
||||
*/
|
||||
class Version20150821122935 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
|
||||
$this->addSql('DROP TABLE groupcenter_permissionsgroup');
|
||||
$this->addSql('ALTER TABLE group_centers ALTER permissionsGroup_id SET NOT NULL');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE group_centers ALTER permissionsGroup_id SET DEFAULT NULL');
|
||||
$this->addSql('CREATE TABLE groupcenter_permissionsgroup (groupcenter_id INT NOT NULL, permissionsgroup_id INT NOT NULL, PRIMARY KEY(groupcenter_id, permissionsgroup_id))');
|
||||
$this->addSql('CREATE INDEX idx_55dfec607ec2fa68 ON groupcenter_permissionsgroup (groupcenter_id)');
|
||||
$this->addSql('CREATE INDEX idx_55dfec606fa97d46 ON groupcenter_permissionsgroup (permissionsgroup_id)');
|
||||
|
||||
$this->addSql('ALTER TABLE groupcenter_permissionsgroup ADD CONSTRAINT fk_55dfec607ec2fa68 FOREIGN KEY (groupcenter_id) REFERENCES group_centers (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('ALTER TABLE groupcenter_permissionsgroup ADD CONSTRAINT fk_55dfec606fa97d46 FOREIGN KEY (permissionsgroup_id) REFERENCES permission_groups (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Add postal code and addresses
|
||||
*/
|
||||
class Version20160310122322 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('CREATE SEQUENCE chill_main_address_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE SEQUENCE chill_main_postal_code_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE chill_main_address ('
|
||||
. 'id INT NOT NULL, '
|
||||
. 'postcode_id INT DEFAULT NULL, '
|
||||
. 'streetAddress1 VARCHAR(255) NOT NULL, '
|
||||
. 'streetAddress2 VARCHAR(255) NOT NULL, '
|
||||
. 'validFrom DATE NOT NULL, '
|
||||
. 'PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE INDEX IDX_165051F6EECBFDF1 ON chill_main_address '
|
||||
. '(postcode_id)');
|
||||
$this->addSql('CREATE TABLE chill_main_postal_code ('
|
||||
. 'id INT NOT NULL, '
|
||||
. 'country_id INT DEFAULT NULL, '
|
||||
. 'label VARCHAR(255) NOT NULL, '
|
||||
. 'code VARCHAR(100) NOT NULL, '
|
||||
. 'PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE INDEX IDX_6CA145FAF92F3E70 ON chill_main_postal_code '
|
||||
. '(country_id)');
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT '
|
||||
. 'FK_165051F6EECBFDF1 '
|
||||
. 'FOREIGN KEY (postcode_id) '
|
||||
. 'REFERENCES chill_main_postal_code (id) '
|
||||
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('ALTER TABLE chill_main_postal_code ADD CONSTRAINT '
|
||||
. 'FK_6CA145FAF92F3E70 '
|
||||
. 'FOREIGN KEY (country_id) '
|
||||
. 'REFERENCES Country (id) '
|
||||
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_address '
|
||||
. 'DROP CONSTRAINT FK_165051F6EECBFDF1');
|
||||
$this->addSql('DROP SEQUENCE chill_main_address_id_seq CASCADE');
|
||||
$this->addSql('DROP SEQUENCE chill_main_postal_code_id_seq CASCADE');
|
||||
$this->addSql('DROP TABLE chill_main_address');
|
||||
$this->addSql('DROP TABLE chill_main_postal_code');
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Add index to postal code
|
||||
*/
|
||||
final class Version20180703191509 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
try {
|
||||
$this->addSql('CREATE EXTENSION IF NOT EXISTS pg_trgm');
|
||||
$this->addSql('CREATE INDEX search_name_code ON chill_main_postal_code USING GIN (LOWER(code) gin_trgm_ops, LOWER(label) gin_trgm_ops)');
|
||||
} catch (\Exception $e) {
|
||||
$this->skipIf(true, "Could not create extension pg_trgm");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('DROP INDEX search_name_code');
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* add username and username canonical, email and email canonical columns
|
||||
* to users
|
||||
*/
|
||||
final class Version20180709181423 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE users ADD usernameCanonical VARCHAR(80) DEFAULT NULL');
|
||||
$this->addSql('UPDATE users SET usernameCanonical=LOWER(UNACCENT(username))');
|
||||
$this->addSql('ALTER TABLE users ALTER usernameCanonical DROP NOT NULL');
|
||||
$this->addSql('ALTER TABLE users ALTER usernameCanonical SET DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE users ADD email VARCHAR(150) DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE users ADD emailCanonical VARCHAR(150) DEFAULT NULL');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9F5A5DC32 ON users (usernameCanonical)');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9885281E ON users (emailCanonical)');
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE OR REPLACE FUNCTION canonicalize_user_on_update() RETURNS TRIGGER AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
IF NEW.username <> OLD.username OR NEW.email <> OLD.email OR OLD.emailcanonical IS NULL OR OLD.usernamecanonical IS NULL THEN
|
||||
UPDATE users SET usernamecanonical=LOWER(UNACCENT(NEW.username)), emailcanonical=LOWER(UNACCENT(NEW.email)) WHERE id=NEW.id;
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$BODY$ LANGUAGE PLPGSQL
|
||||
SQL
|
||||
);
|
||||
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TRIGGER canonicalize_user_on_update
|
||||
AFTER UPDATE
|
||||
ON users
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE canonicalize_user_on_update();
|
||||
SQL
|
||||
);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE OR REPLACE FUNCTION canonicalize_user_on_insert() RETURNS TRIGGER AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
UPDATE users SET usernamecanonical=LOWER(UNACCENT(NEW.username)), emailcanonical=LOWER(UNACCENT(NEW.email)) WHERE id=NEW.id;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$BODY$ LANGUAGE PLPGSQL;
|
||||
SQL
|
||||
);
|
||||
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TRIGGER canonicalize_user_on_insert
|
||||
AFTER INSERT
|
||||
ON users
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE canonicalize_user_on_insert();
|
||||
SQL
|
||||
);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('DROP INDEX UNIQ_1483A5E9F5A5DC32');
|
||||
$this->addSql('DROP INDEX UNIQ_1483A5E9885281E');
|
||||
$this->addSql('ALTER TABLE users DROP usernameCanonical');
|
||||
$this->addSql('ALTER TABLE users DROP email');
|
||||
$this->addSql('ALTER TABLE users DROP emailCanonical');
|
||||
$this->addSql('DROP TRIGGER canonicalize_user_on_insert ON users');
|
||||
$this->addSql('DROP FUNCTION canonicalize_user_on_insert()');
|
||||
$this->addSql('DROP TRIGGER canonicalize_user_on_update ON users');
|
||||
$this->addSql('DROP FUNCTION canonicalize_user_on_update()');
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20180905101426 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE permission_groups ADD flags JSONB DEFAULT \'[]\' NOT NULL');
|
||||
$this->addSql('ALTER TABLE group_centers ALTER permissionsgroup_id DROP NOT NULL');
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE permission_groups DROP COLUMN flags');
|
||||
$this->addSql('ALTER TABLE group_centers ALTER permissionsgroup_id SET DEFAULT NULL');
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Fix error with recursive trigger on update
|
||||
*/
|
||||
final class Version20180911093642 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql("DROP TRIGGER canonicalize_user_on_update ON users");
|
||||
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TRIGGER canonicalize_user_on_update
|
||||
AFTER UPDATE
|
||||
ON users
|
||||
FOR EACH ROW
|
||||
WHEN (pg_trigger_depth() = 0)
|
||||
EXECUTE PROCEDURE canonicalize_user_on_update();
|
||||
SQL
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql("DROP TRIGGER canonicalize_user_on_update ON users");
|
||||
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TRIGGER canonicalize_user_on_update
|
||||
AFTER UPDATE
|
||||
ON users
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE canonicalize_user_on_update();
|
||||
SQL
|
||||
);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Add a field "isNoAddress" on addresses
|
||||
*/
|
||||
final class Version20200422122715 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD isNoAddress BOOLEAN NOT NULL DEFAULT FALSE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address DROP isNoAddress');
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210304085819 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE users ADD attributes JSONB DEFAULT NULL');
|
||||
$this->addSql('COMMENT ON COLUMN users.attributes IS \'(DC2Type:json_array)\'');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE users DROP attributes');
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Add custom data in address
|
||||
*/
|
||||
final class Version20210308111926 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD customs JSONB DEFAULT \'[]\'');
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_address DROP customs');
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Add custom data in addresses";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user