PHP code example of yousign / safe-migrations

1. Go to this page and download the library: Download yousign/safe-migrations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yousign / safe-migrations example snippets




declare(strict_types=1);

namespace <namespace>;

use Doctrine\DBAL\Schema\Schema;
use Yousign\SafeMigrations\Doctrine\Migration;

class <className> extends Migration
{
    public function up(Schema $schema): void
    {
<up>
    }
}

$this->createTable(table: 'test', columnDefinitions: [
    'id UUID NOT NULL', 
    'PRIMARY KEY(id)',
])

$this->addForeignKey(table: 'address', name: 'fk_address_contact', column: 'contact', referenceTable: 'contact', referenceColumn: 'id', options: 'ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE')

$this->renameConstraint(table: 'address', from: 'id_pkey', to: 'pkey_id')

$this->commentOnColumn(table: 'address', name: 'name', comment: null)

$this->addIndex(name: 'idx_contact_email', table: 'contact', columns: ['email'], unique: false, usingMethod: 'GIN', where: 'country = "France"')

$this->dropIndex(name: 'idx_contact_email')

$this->renameIndex(from: 'idx_email_signer', to: 'idx_signer_email')

$this->addColumn(table: 'contact', name: 'mobile', type: 'text', defaultValue: null, nullable: true)

$this->dropColumn(table: 'contact', name: 'landline')

$this->setDefaultOnColumn(table: 'contact', name: 'email', value: "'[email protected]'")

$this->dropDefaultOnColumn(table: 'contact', name: 'email')

$this->setColumnNullable(table: 'contact', name: 'email')

$this->setColumnNotNullable(table: 'contact', name: 'email')
yaml
doctrine_migrations:
  custom_template: "%kernel.project_dir%/migrations/migration.php.tpl"