Skip to content

Instantly share code, notes, and snippets.

@StalkAlex
Last active January 22, 2016 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StalkAlex/b4c19869e974de226bfc to your computer and use it in GitHub Desktop.
Save StalkAlex/b4c19869e974de226bfc to your computer and use it in GitHub Desktop.
yii2-pages module migration. This is working version for postgres.
<?php
use yii\db\Schema;
use yii\db\Migration;
class m151103_064902_create_tree_manager_table extends Migration
{
public function up()
{
$this->execute("CREATE SEQUENCE dmstr_page_seq;");
$this->execute(
"
/* SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; */
/* SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; */
/* SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; */
-- ------------...
-- Table dmstr...
-- ------------...
/*CREATE SEQUENCE page_title;*/
CREATE TABLE IF NOT EXISTS dmstr_page (
id INT NOT NULL DEFAULT NEXTVAL ('dmstr_page_seq') ,
root INT NULL DEFAULT NULL ,
lft INT NOT NULL ,
rgt INT NOT NULL ,
lvl SMALLINT NOT NULL ,
page_title VARCHAR(255) NULL ,
name VARCHAR(60) NOT NULL ,
name_id VARCHAR(255) NOT NULL ,
slug VARCHAR(255) NULL ,
route VARCHAR(255) NULL ,
view VARCHAR(255) NULL ,
default_meta_keywords VARCHAR(255) NULL ,
default_meta_description TEXT NULL ,
request_params TEXT NULL ,
owner INT NULL ,
access_owner INT NULL DEFAULT NULL,
access_domain VARCHAR(8) NULL DEFAULT NULL,
access_read VARCHAR(255) NULL DEFAULT NULL,
access_update VARCHAR(255) NULL DEFAULT NULL,
access_delete VARCHAR(255) NULL DEFAULT NULL,
icon VARCHAR(255) NULL DEFAULT NULL ,
icon_type SMALLINT NOT NULL DEFAULT '1' ,
active SMALLINT NOT NULL DEFAULT '1' ,
selected SMALLINT NOT NULL DEFAULT '0' ,
disabled SMALLINT NOT NULL DEFAULT '0' ,
readonly SMALLINT NOT NULL DEFAULT '0' ,
visible SMALLINT NOT NULL DEFAULT '1' ,
collapsed SMALLINT NOT NULL DEFAULT '0' ,
movable_u SMALLINT NOT NULL DEFAULT '1' ,
movable_d SMALLINT NOT NULL DEFAULT '1' ,
movable_l SMALLINT NOT NULL DEFAULT '1' ,
movable_r SMALLINT NOT NULL DEFAULT '1' ,
removable SMALLINT NOT NULL DEFAULT '1' ,
removable_all SMALLINT NOT NULL DEFAULT '0' ,
created_at TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT name_id_UNIQUE UNIQUE (name_id))
;
");
$this->execute("comment on column dmstr_page.root is 'Tree root identifier';");
$this->execute("comment on column dmstr_page.lft is 'Nested set left property';");
$this->execute("comment on column dmstr_page.rgt is 'Nested set right property';");
$this->execute("comment on column dmstr_page.lvl is 'Nested set level / depth';");
$this->execute("comment on column dmstr_page.page_title is 'The page title';");
$this->execute("comment on column dmstr_page.name is 'The tree node name / label';");
$this->execute("comment on column dmstr_page.name_id is 'The unique name_id';");
$this->execute("comment on column dmstr_page.slug is 'The auto generated slugged name_id';");
$this->execute("comment on column dmstr_page.route is 'The controller/view route';");
$this->execute("comment on column dmstr_page.view is 'The view to render through the given route';");
$this->execute("comment on column dmstr_page.default_meta_keywords is 'SEO - meta keywords - comma seperated';");
$this->execute("comment on column dmstr_page.default_meta_description is 'SEO - meta description';");
$this->execute("comment on column dmstr_page.request_params is 'JSON - request params';");
$this->execute("comment on column dmstr_page.icon is 'The icon to use for the node';");
$this->execute("comment on column dmstr_page.icon_type is 'Icon Type: 1 = CSS Class, 2 = Raw Markup';");
$this->execute("comment on column dmstr_page.active is 'Whether the node is active (will be set to false on deletion)';");
$this->execute("comment on column dmstr_page.selected is 'Whether the node is selected/checked by default';");
$this->execute("comment on column dmstr_page.disabled is 'Whether the node is enabled';");
$this->execute("comment on column dmstr_page.readonly is 'Whether the node is read only (unlike disabled - will allow toolbar actions)';");
$this->execute("comment on column dmstr_page.visible is 'Whether the node is visible';");
$this->execute("comment on column dmstr_page.collapsed is 'Whether the node is collapsed by default';");
$this->execute("comment on column dmstr_page.movable_u is 'Whether the node is movable one position up';");
$this->execute("comment on column dmstr_page.movable_d is 'Whether the node is movable one position down';");
$this->execute("comment on column dmstr_page.movable_l is 'Whether the node is movable to the left (from sibling to parent)';");
$this->execute("comment on column dmstr_page.movable_r is 'Whether the node is movable to the right (from sibling to child)';");
$this->execute("comment on column dmstr_page.removable is 'Whether the node is removable (any children below will be moved as siblings before deletion)';");
$this->execute("comment on column dmstr_page.removable_all is 'Whether the node is removable along with descendants';");
$this->execute("ALTER SEQUENCE dmstr_page_seq RESTART WITH 1;");
$this->execute("CREATE INDEX tbl_tree_NK1 ON dmstr_page (root ASC);");
$this->execute("CREATE INDEX tbl_tree_NK2 ON dmstr_page (lft ASC);");
$this->execute("CREATE INDEX tbl_tree_NK3 ON dmstr_page (rgt ASC);");
$this->execute("CREATE INDEX tbl_tree_NK4 ON dmstr_page (lvl ASC);");
$this->execute("CREATE INDEX tbl_tree_NK5 ON dmstr_page (active ASC);");
/* $this->execute("SET SQL_MODE=@OLD_SQL_MODE;"); */
/* $this->execute("SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;"); */
/* $this->execute("SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;"); */
}
public function down()
{
$this->dropTable('dmstr_page');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment