PHP code example of svmk / yii-migration-postgresql-sectioning

1. Go to this page and download the library: Download svmk/yii-migration-postgresql-sectioning 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/ */

    

svmk / yii-migration-postgresql-sectioning example snippets

 

use svmk\yiiMigrationSectioningPostgres\PostgresqlMigrationHelper;
use svmk\yiiMigrationSectioningPostgres\DateTimeWeekOfYearGrouping;
class m151019_123058_create_table_page_stat extends CDbMigration
{

	protected function getHelper() {
		$helper = new PostgresqlMigrationHelper(
			$this,
			'page_stat',
			array(
				'id' => 'bigserial NOT NULL PRIMARY KEY',
				'data_id' => 'BIGINT',
				'event_date' => 'TIMESTAMP',
				'region_id'  => 'INT',
				'city_id'    => 'INT',
				'views'		 => 'INT',
			)
		);
		return $helper->grouping(
			new DateTimeWeekOfYearGrouping('id','event_date')
		);
	}
	public function getDbConnection()
	{
		return Yii::app()->statisticsDb;
	}
	public function safeUp()
	{
		$this->getHelper()->up(
			function($migration,$tableName,$columns,$config,$isMainTable){
				$migration->createTable(
					$tableName,
					$columns,
					$config
				);
				if (!$isMainTable) {
					$migration->createIndex($tableName.'_data_id',$tableName,'data_id');
					$migration->createIndex($tableName.'_event_date',$tableName,'event_date');
				}
			}
		);
	}

	public function safeDown()
	{
		$this->getHelper()->down(function($migration,$tableName,$isMainTable){			
			$migration->dropTable($tableName);
		});
	}
}