src/Tenant/Migration/Version0_15_0.php
public function up(Schema $schema, array $tenants = [])
    {
        $sequences['ds_tenant_id_seq'] = 1 + count($tenants);

        switch ($this->platform->getName()) {
            case 'postgresql':
                $this->addSql('CREATE SEQUENCE ds_tenant_id_seq INCREMENT BY 1 MINVALUE 1 START '.$sequences['ds_tenant_id_seq']);
                $this->addSql('CREATE TABLE ds_tenant (id INT NOT NULL, uuid UUID NOT NULL, version INT DEFAULT 1 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
                $this->addSql('CREATE UNIQUE INDEX UNIQ_EF5FAEEAD17F50A6 ON ds_tenant (uuid)');

                $i = 0;

                foreach ($tenants as $tenant) {
                    if (null === $tenant->uuid) {
                        $tenant->uuid = Uuid::uuid4()->toString();
                    }

                    $this->addSql(sprintf(
                        'INSERT INTO ds_tenant (id, uuid, created_at, updated_at) VALUES (%d, %s, %s, %s);',
                        ++$i,
                        $this->connection->quote($tenant->uuid),
                        'now()',
                        'now()'
                    ));
                }

                break;

            default:
                $this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".');
                break;
        }
    }
public function up(Schema $schema, array $tenants = [])
    {
        $sequences['ds_tenant_id_seq'] = 1 + count($tenants);

        switch ($this->platform->getName()) {
            case 'postgresql':
                $this->addSql('CREATE SEQUENCE ds_tenant_id_seq INCREMENT BY 1 MINVALUE 1 START '.$sequences['ds_tenant_id_seq']);
                $this->addSql('CREATE TABLE ds_tenant (id INT NOT NULL, uuid UUID NOT NULL, version INT DEFAULT 1 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
                $this->addSql('CREATE UNIQUE INDEX UNIQ_EF5FAEEAD17F50A6 ON ds_tenant (uuid)');

                $i = 0;

                foreach ($tenants as $tenant) {
                    if (null === $tenant->uuid) {
                        $tenant->uuid = Uuid::uuid4()->toString();
                    }

                    $this->addSql(sprintf(
                        'INSERT INTO ds_tenant (id, uuid, created_at, updated_at) VALUES (%d, %s, %s, %s);',
                        ++$i,
                        $this->connection->quote($tenant->uuid),
                        'now()',
                        'now()'
                    ));
                }

                break;

            default:
                $this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".');
                break;
        }
    }
public function up ( Schema $ schema , array $ tenants = [ ] ) { $ sequences [ 'ds_tenant_id_seq' ] = 1 + count ( $ tenants ) ; switch ( $ this -> platform -> getName ( ) ) { case 'postgresql' : $ this -> addSql ( 'CREATE SEQUENCE ds_tenant_id_seq INCREMENT BY 1 MINVALUE 1 START ' . $ sequences [ 'ds_tenant_id_seq' ] ) ; $ this -> addSql ( 'CREATE TABLE ds_tenant (id INT NOT NULL, uuid UUID NOT NULL, version INT DEFAULT 1 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))' ) ; $ this -> addSql ( 'CREATE UNIQUE INDEX UNIQ_EF5FAEEAD17F50A6 ON ds_tenant (uuid)' ) ; $ i = 0 ; foreach ( $ tenants as $ tenant ) { if ( null === $ tenant -> uuid ) { $ tenant -> uuid = Uuid :: uuid4 ( ) -> toString ( ) ; } $ this -> addSql ( sprintf ( 'INSERT INTO ds_tenant (id, uuid, created_at, updated_at) VALUES (%d, %s, %s, %s);' , ++ $ i , $ this -> connection -> quote ( $ tenant -> uuid ) , 'now()' , 'now()' ) ) ; } break ; default : $ this -> abortIf ( true , 'Migration cannot be executed on "' . $ this -> platform -> getName ( ) . '".' ) ; break ; } }
Up migration

@param \Doctrine\DBAL\Schema\Schema $schema
@param array $tenants
Up migration