/** * Migrate up */ public function up() { $table = $this->table('settings'); $table->addColumn('scope', 'string', ['limit' => 255, 'null' => true])->addColumn('field', 'string', ['limit' => 255, 'null' => true])->addColumn('value', 'text', ['null' => true])->addColumn('serialized', 'boolean', ['null' => false, 'default' => 0])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('blog_categories')->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('description', 'text', ['null' => true, 'default' => null])->addColumn('slug', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('meta_description', 'text', ['null' => true, 'default' => null])->addColumn('post_count', 'integer', ['limit' => 11, 'signed' => false, 'null' => false, 'default' => 0])->addColumn('created', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false])->addColumn('modified', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false]); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('blog_blog_authors')->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('description_single_post', 'text', ['null' => true, 'default' => null])->addColumn('description_author_page', 'text', ['null' => true, 'default' => null])->addColumn('slug', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('is_default_author', 'integer', ['default' => 0, 'null' => false])->addColumn('meta_description', 'text', ['null' => true, 'default' => null])->addColumn('user_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('website', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('created', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false])->addColumn('modified', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false]); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => false])->addIndex('user_id', ['name' => 'FK_USER_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('blog_posts_tags')->addColumn('post_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('tag_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false]); $table->addIndex('post_id', ['name' => 'FK_POST_ID', 'unique' => false])->addIndex('tag_id', ['name' => 'FK_TAG_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('cms_collections'); $table->addColumn('page_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('type', 'string', ['limit' => 255, 'null' => false])->addColumn('identifier', 'string', ['limit' => 255, 'null' => false])->addColumn('model', 'string', ['limit' => 255, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('page_id', ['name' => 'FK_PAGE_ID'])->addIndex('type', ['name' => 'BY_TYPE'])->addIndex('identifier', ['name' => 'BY_IDENTIFIER']); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('routes'); $table->addColumn('url', 'text', ['default' => null, 'null' => false])->addColumn('model', 'string', ['length' => 255, 'default' => null, 'null' => false])->addColumn('foreign_key', 'integer', ['length' => 11, 'signed' => false, 'default' => null, 'null' => false])->addColumn('language_id', 'integer', ['length' => 11, 'signed' => false, 'default' => null, 'null' => false])->addColumn('page_type', 'string', ['length' => 255, 'default' => 'simple', 'null' => false])->addColumn('redirect_to', 'integer', ['length' => 11, 'signed' => false, 'default' => null, 'null' => true])->addColumn('status_code', 'integer', ['length' => 11, 'signed' => false, 'default' => null, 'null' => true])->addColumn('created', 'datetime', ['default' => null, 'null' => false])->addColumn('modified', 'datetime', ['default' => null, 'null' => false]); $table->addIndex(['model', 'foreign_key', 'language_id'], ['name' => 'BY_MODEL_FOREIGN_KEY_LANG_ID', 'unique' => false])->addIndex('redirect_to', ['name' => 'BY_REDIRECT_TO', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('tokens'); $table->addColumn('user_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('token', 'string', ['limit' => 32, 'null' => false])->addColumn('token_type', 'string', ['limit' => 50, 'null' => false])->addColumn('used', 'boolean', ['default' => 0, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('expires', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('user_id', ['name' => 'FK_USER_ID', 'unique' => false])->addIndex('token', ['name' => 'BY_TOKEN', 'unique' => true]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up. */ public function up() { $table = $this->table('cms_contents'); $table->addColumn('page_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('language_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('content', 'text', ['limit' => 255])->addColumn('created_by_user_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('modified_by_user_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('page_id', ['name' => 'BY_PAGE_ID'])->addIndex('language_id', ['name' => 'BY_LANGUAGE_ID'])->addIndex(['page_id', 'language_id'], ['name' => ['BY_PAGE_ID_AND_LANGUAGE_ID']])->addIndex('created_by_user_id', ['name' => 'BY_CREATED_BY_USER_ID'])->addIndex('modified_by_user_id', ['name' => 'BY_MODIFIED_BY_USER_ID']); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migration up */ public function up() { $table = $this->table('group_permissions'); $table->addColumn('group_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('path', 'string', ['limit' => 255, 'null' => false])->addColumn('plugin', 'string', ['limit' => 255, 'null' => false])->addColumn('controller', 'string', ['limit' => 255, 'null' => false])->addColumn('action', 'string', ['limit' => 255, 'null' => false])->addColumn('allowed', 'boolean', ['null' => false, 'default' => 0])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('group_id', ['name' => 'FK_GROUP_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('cms_attributes'); $table->addColumn('model', 'string', ['limit' => 255, 'null' => false])->addColumn('foreign_key', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('language_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('content', 'text', ['null' => true, 'default' => null])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('model', ['name' => 'BY_MODEL', 'unique' => false])->addIndex('foreign_key', ['name' => 'BY_FOREIGN_KEY', 'unique' => false])->addIndex('language_id', ['name' => 'FK_LANGUAGE_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('menus'); $table->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('menu_item_count', 'integer', ['default' => 0, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('blog_posts'); $table->addColumn('category_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('blog_author_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('slug', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('short', 'text', ['null' => true, 'default' => null])->addColumn('content', 'text', ['null' => true, 'default' => null])->addColumn('more_information', 'text', ['null' => true, 'default' => null])->addColumn('comments', 'integer', ['default' => 0, 'null' => false])->addColumn('comments_closed', 'integer', ['default' => 0, 'null' => false])->addColumn('comments_count', 'integer', ['default' => 0, 'null' => false])->addColumn('is_online', 'integer', ['default' => 0, 'null' => false])->addColumn('is_outdated', 'integer', ['default' => 0, 'null' => false])->addColumn('outdated_text', 'text', ['null' => true, 'default' => null])->addColumn('published_on', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false])->addColumn('meta_description', 'text', ['null' => true, 'default' => null])->addColumn('created', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false])->addColumn('modified', 'datetime', ['default' => '0000-00-00 00:00', 'null' => false]); $table->addIndex('category_id', ['name' => 'FK_CATEGORY_ID', 'unique' => false])->addIndex('blog_author_id', ['name' => 'FK_BLOG_AUTHOR_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('cms_menu_items'); $table->addColumn('menu_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('parent_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => true, 'default' => null])->addColumn('lft', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('rght', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('type', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('target', 'text', ['null' => true, 'default' => null])->addColumn('external_link', 'text', ['null' => true, 'default' => null])->addColumn('foreign_model', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('foreign_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => true, 'default' => null])->addColumn('plugin', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('controller', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('action', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('params', 'text', ['null' => true, 'default' => null])->addColumn('query', 'text', ['null' => true, 'default' => null])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('menu_id', ['name' => 'FK_MENU_ID', 'unique' => false]); $table->addIndex('parent_id', ['name' => 'FK_PARENT_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); }
/** * Migrate up */ public function up() { $table = $this->table('groups'); $table->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('user_count', 'integer', ['limit' => 11, 'signed' => false, 'null' => false, 'default' => 0])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => true]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); $group = new Group(['name' => 'Super Admin']); $Groups = TableRegistry::get('Wasabi/Core.Groups'); $Groups->save($group); }
/** * Migrate up */ public function up() { $table = $this->table('users'); $table->addColumn('group_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('username', 'string', ['limit' => 255, 'null' => false])->addColumn('password', 'string', ['limit' => 60, 'null' => false])->addColumn('email', 'string', ['limit' => 255, 'null' => false])->addColumn('verified', 'boolean', ['default' => 0, 'null' => false])->addColumn('active', 'boolean', ['default' => 0, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('username', ['name' => 'BY_USERNAME', 'unique' => true])->addIndex('group_id', ['name' => 'FK_GROUP_ID', 'unique' => false])->addIndex('email', ['name' => 'BY_EMAIL', 'unique' => true])->addIndex('active', ['name' => 'BY_ACTIVE', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); $user = new User(['username' => 'admin', 'group_id' => 1, 'email' => '*****@*****.**', 'password' => 'admin', 'verified' => 1, 'active' => 1]); $Users = TableRegistry::get('Wasabi/Core.Users'); $Users->save($user); }
/** * Migrate up */ public function up() { $table = $this->table('cms_pages'); $table->addColumn('parent_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => true, 'default' => null])->addColumn('lft', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('rght', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('slug', 'string', ['limit' => 255, 'null' => false])->addColumn('layout', 'string', ['limit' => 255, 'null' => false, 'default' => 'Default'])->addColumn('page_title', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('display_page_title_suffix', 'boolean', ['signed' => false, 'null' => false, 'default' => 0])->addColumn('meta_description', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('meta_robots_index', 'boolean', ['signed' => false, 'null' => true, 'default' => null])->addColumn('meta_robots_follow', 'boolean', ['signed' => false, 'null' => true, 'default' => null])->addColumn('status', 'integer', ['limit' => 11, 'signed' => false, 'null' => false, 'default' => 0])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('published', 'datetime', ['null' => true, 'default' => null]); $table->addIndex('name', ['name' => 'BY_NAME']); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); $page = new Page(['name' => 'Home', 'slug' => 'home']); $Pages = TableRegistry::get('Wasabi/Cms.Pages'); $Pages->save($page); }
/** * Migrate up */ public function up() { $table = $this->table('languages'); $table->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('iso2', 'string', ['limit' => 2, 'null' => false])->addColumn('iso3', 'string', ['limit' => 3, 'null' => false])->addColumn('lang', 'string', ['limit' => 5, 'null' => false])->addColumn('available_at_frontend', 'boolean', ['null' => false, 'default' => 0])->addColumn('available_at_backend', 'boolean', ['null' => false, 'default' => 0])->addColumn('in_progress', 'boolean', ['null' => false, 'default' => 1])->addColumn('position', 'integer', ['null' => false, 'default' => 99999])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => false])->addIndex('available_at_frontend', ['name' => 'BY_AVAILABLE_AT_FRONTEND', 'unique' => false])->addIndex('available_at_backend', ['name' => 'BY_AVAILABLE_AT_BACKEND', 'unique' => false])->addIndex('in_progress', ['name' => 'BY_IN_PROGRESS', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); $languages = [new Language(['name' => 'English', 'iso2' => 'en', 'iso3' => 'eng', 'lang' => 'en_US', 'available_at_frontend' => 1, 'available_at_backend' => 1, 'in_progress' => 0, 'position' => 1]), new Language(['name' => 'Deutsch', 'iso2' => 'de', 'iso3' => 'deu', 'lang' => 'de_DE', 'available_at_frontend' => 1, 'available_at_backend' => 1, 'in_progress' => 0, 'position' => 2])]; $Languages = TableRegistry::get('Wasabi/Core.Languages'); $Languages->connection()->transactional(function () use($Languages, $languages) { foreach ($languages as $language) { $Languages->save($language); } }); }
/** * Migrate up */ public function up() { $table = $this->table('cms_menus'); $table->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('menu_item_count', 'integer', ['default' => 0, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); $menus = [new Menu(['name' => 'Main']), new Menu(['name' => 'Footer'])]; $Menus = TableRegistry::get('Wasabi/Core.Menus'); $Menus->connection()->transactional(function () use($Menus, $menus) { foreach ($menus as $menu) { $Menus->save($menu); } }); }
/** * Gets the SqlServer Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column, $create = true) { $buffer = array(); $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in SQlServer $noLimits = array('bigint', 'int', 'tinyint'); if (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } if ($column->getPrecision() && $column->getScale()) { $buffer[] = '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $properties = $column->getProperties(); $buffer[] = $column->getType() === 'filestream' ? 'FILESTREAM' : ''; $buffer[] = isset($properties['rowguidcol']) ? 'ROWGUIDCOL' : ''; $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; if ($create === true) { if ($column->getDefault() === null && $column->isNull()) { $buffer[] = ' DEFAULT NULL'; } else { $buffer[] = $this->getDefaultValueDefinition($column->getDefault()); } } if ($column->isIdentity()) { $buffer[] = 'IDENTITY(1, 1)'; } return implode(' ', $buffer); }
/** * Gets the MySQL Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column) { $sqlType = $this->getSqlType($column->getType(), $column->getLimit()); $def = ''; $def .= strtoupper($sqlType['name']); if ($column->getPrecision() && $column->getScale()) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } elseif (isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; } if (($values = $column->getValues()) && is_array($values)) { $def .= "('" . implode("', '", $values) . "')"; } $def .= !$column->isSigned() && isset($this->signedColumnTypes[$column->getType()]) ? ' unsigned' : ''; $def .= !$column->isZerofill() && isset($this->zerofillColumnTypes[$column->getType()]) ? ' zerofill' : ''; $def .= $column->isNull() == false ? ' NOT NULL' : ' NULL'; $def .= $column->isIdentity() ? ' AUTO_INCREMENT' : ''; $def .= $this->getDefaultValueDefinition($column->getDefault()); if ($column->getComment()) { $def .= ' COMMENT ' . $this->getConnection()->quote($column->getComment()); } if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } return $def; }
/** * Gets the PostgreSQL Column Comment Defininition for a column object. * * @param Column $column Column * @param string $tableName Table name * @return string */ protected function getColumnCommentSqlDefinition(Column $column, $tableName) { // passing 'null' is to remove column comment $comment = strcasecmp($column->getComment(), 'NULL') !== 0 ? $this->getConnection()->quote($column->getComment()) : 'NULL'; return sprintf('COMMENT ON COLUMN %s.%s IS %s;', $tableName, $column->getName(), $comment); }
/** * Gets the PostgreSQL Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column) { $sqlType = $this->getSqlType($column->getType()); $def = strtoupper($sqlType['name']); // integers cant have limits in postgres if ('integer' !== $sqlType['name']) { $def .= $column->getLimit() || isset($sqlType['limit']) ? '(' . ($column->getLimit() ? $column->getLimit() : $sqlType['limit']) . ')' : ''; } $def .= $column->isNull() == false ? ' NOT NULL' : ' NULL'; $def .= $column->isIdentity() ? '' : ''; $default = $column->getDefault(); if (is_numeric($default)) { $def .= ' DEFAULT ' . $column->getDefault(); } else { $def .= is_null($column->getDefault()) ? '' : ' DEFAULT \'' . $column->getDefault() . '\''; } // TODO - add precision & scale for decimals return $def; }
/** * @expectedException \RuntimeException * @expectedExceptionMessage "0" is not a valid column option. */ public function testSetOptionThrowsExceptionIfOptionIsNotString() { $column = new Column(); $column->setOptions(['identity']); }
/** * {@inheritdoc} */ public function isValidColumnType(Column $column) { return in_array($column->getType(), $this->getColumnTypes()); }
/** * Gets the MySQL Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column) { $sqlType = $this->getSqlType($column->getType()); $def = ''; $def .= strtoupper($sqlType['name']); if ($column->getPrecision() && $column->getScale()) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $def .= $column->getLimit() || isset($sqlType['limit']) ? '(' . ($column->getLimit() ? $column->getLimit() : $sqlType['limit']) . ')' : ''; $def .= !$column->isSigned() && isset($this->signedColumnTypes[$column->getType()]) ? ' unsigned' : ''; $def .= $column->isNull() == false ? ' NOT NULL' : ' NULL'; $def .= $column->isIdentity() ? ' AUTO_INCREMENT' : ''; $default = $column->getDefault(); if (is_numeric($default) || $default == 'CURRENT_TIMESTAMP') { $def .= ' DEFAULT ' . $column->getDefault(); } else { $def .= is_null($column->getDefault()) ? '' : ' DEFAULT \'' . $column->getDefault() . '\''; } if ($column->getComment()) { $def .= ' COMMENT ' . $this->getConnection()->quote($column->getComment()); } if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } return $def; }
/** * Change a table column type. * * @param string $columnName Column Name * @param string|Column $newColumnType New Column Type * @param array $options Options * @return Table */ public function changeColumn($columnName, $newColumnType, $options = array()) { // create a column object if one wasn't supplied if (!$newColumnType instanceof Column) { $newColumn = new Column(); $newColumn->setType($newColumnType); $newColumn->setOptions($options); } else { $newColumn = $newColumnType; } // if the name was omitted use the existing column name if (null === $newColumn->getName() || strlen($newColumn->getName()) === 0) { $newColumn->setName($columnName); } $this->getAdapter()->changeColumn($this->getName(), $columnName, $newColumn); return $this; }
/** * Utility method that maps an array of column options to this objects methods. * * @param array $options Options * * @return $this */ public function setOptions(array $options) { $this->column->setOptions($options); return $this; }
/** * Gets the comment Definition for a Column object. * * @param Column $column Column * @return string */ protected function getCommentDefinition(Column $column) { if ($column->getComment()) { return ' /* ' . $column->getComment() . ' */ '; } return ''; }
/** * Gets the SqlServer Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column, $create = true) { $buffer = array(); $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in SQlServer $noLimits = array('bigint', 'int', 'tinyint'); if (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } $properties = $column->getProperties(); $buffer[] = $column->getType() == 'filestream' ? 'FILESTREAM' : ''; $buffer[] = isset($properties['rowguidcol']) ? 'ROWGUIDCOL' : ''; $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; $default = $column->getDefault(); if ($create) { if (is_numeric($default) || 'CURRENT_TIMESTAMP' === $default) { $buffer[] = 'DEFAULT'; $buffer[] = $default; } elseif ($default) { $buffer[] = "DEFAULT '{$default}'"; } } if ($column->isIdentity()) { $buffer[] = 'IDENTITY(1, 1)'; } // TODO - add precision & scale for decimals return implode(' ', $buffer); }
/** * Gets the MySQL Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column) { $sqlType = $this->getSqlType($column->getType()); $def = ''; $def = ''; $def .= strtoupper($sqlType['name']); $def .= $column->getLimit() || isset($sqlType['limit']) ? '(' . ($column->getLimit() ? $column->getLimit() : $sqlType['limit']) . ')' : ''; $def .= $column->isNull() == false ? ' NOT NULL' : ' NULL'; $def .= $column->isIdentity() ? ' AUTO_INCREMENT' : ''; $default = $column->getDefault(); if (is_numeric($default) || $default == 'CURRENT_TIMESTAMP') { $def .= ' DEFAULT ' . $column->getDefault(); } else { $def .= is_null($column->getDefault()) ? '' : ' DEFAULT \'' . $column->getDefault() . '\''; } if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } // TODO - add precision & scale for decimals return $def; }