m170615_080920_odoo_remote_tables.php 3.86 KB
<?php
    
    use yii\db\Migration;
    
    class m170615_080920_odoo_remote_tables extends Migration
    {
        public function safeUp()
        {
            $this->createTable(
                'odoo_to_product',
                [
                    'product_id' => $this->integer()
                                         ->notNull(),
                    'remote_id'  => $this->integer()
                                         ->notNull(),
                ]
            );
            
            $this->createIndex(
                'odoo_to_product_uindex',
                'odoo_to_product',
                [
                    'product_id',
                    'remote_id',
                ],
                true
            );
            
            $this->addForeignKey(
                'odoo_to_product_product_fkey',
                'odoo_to_product',
                'product_id',
                'product',
                'id',
                'CASCADE',
                'CASCADE'
            );
            
            $this->createTable(
                'odoo_to_order',
                [
                    'order_id'  => $this->integer()
                                        ->notNull(),
                    'remote_id' => $this->integer()
                                        ->notNull(),
                ]
            );
            
            $this->createIndex(
                'odoo_to_order_uindex',
                'odoo_to_order',
                [
                    'order_id',
                    'remote_id',
                ],
                true
            );
            
            $this->addForeignKey(
                'odoo_to_order_order_fkey',
                'odoo_to_order',
                'order_id',
                'order',
                'id',
                'CASCADE',
                'CASCADE'
            );
            
            $this->createTable(
                'odoo_to_category',
                [
                    'category_id' => $this->integer()
                                          ->notNull(),
                    'remote_id'   => $this->integer()
                                          ->notNull(),
                ]
            );
            
            $this->createIndex(
                'odoo_to_category_uindex',
                'odoo_to_category',
                [
                    'category_id',
                    'remote_id',
                ],
                true
            );
            
            $this->addForeignKey(
                'odoo_to_category_category_fkey',
                'odoo_to_category',
                'category_id',
                'category',
                'id',
                'CASCADE',
                'CASCADE'
            );
            
            $this->createTable(
                'odoo_to_customer',
                [
                    'customer_id' => $this->integer()
                                          ->notNull(),
                    'remote_id'   => $this->integer()
                                          ->notNull(),
                ]
            );
            
            $this->createIndex(
                'odoo_to_customer_uindex',
                'odoo_to_customer',
                [
                    'customer_id',
                    'remote_id',
                ],
                true
            );
            
            $this->addForeignKey(
                'odoo_to_customer_customer_fkey',
                'odoo_to_customer',
                'customer_id',
                'customer',
                'id',
                'CASCADE',
                'CASCADE'
            );
        }
        
        public function safeDown()
        {
            $this->dropTable('odoo_to_order');
            $this->dropTable('odoo_to_product');
            $this->dropTable('odoo_to_category');
            $this->dropTable('odoo_to_customer');
        }
    }