Schema represents the database schema information that is DBMS specific.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Object
 public function columnTypes()
 {
     return [[Schema::TYPE_PK, Schema::primaryKey(), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'], [Schema::TYPE_PK . '(8)', Schema::primaryKey(8), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'], [Schema::TYPE_PK . ' CHECK (value > 5)', Schema::primaryKey()->check('value > 5'), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)'], [Schema::TYPE_PK . '(8) CHECK (value > 5)', Schema::primaryKey(8)->check('value > 5'), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)'], [Schema::TYPE_STRING, Schema::string(), 'varchar(255)'], [Schema::TYPE_STRING . '(32)', Schema::string(32), 'varchar(32)'], [Schema::TYPE_STRING . ' CHECK (value LIKE "test%")', Schema::string()->check('value LIKE "test%"'), 'varchar(255) CHECK (value LIKE "test%")'], [Schema::TYPE_STRING . '(32) CHECK (value LIKE "test%")', Schema::string(32)->check('value LIKE "test%"'), 'varchar(32) CHECK (value LIKE "test%")'], [Schema::TYPE_STRING . ' NOT NULL', Schema::string()->notNull(), 'varchar(255) NOT NULL'], [Schema::TYPE_TEXT, Schema::text(), 'text'], [Schema::TYPE_TEXT . '(255)', Schema::text(255), 'text'], [Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")', Schema::text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")'], [Schema::TYPE_TEXT . '(255) CHECK (value LIKE "test%")', Schema::text(255)->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")'], [Schema::TYPE_TEXT . ' NOT NULL', Schema::text()->notNull(), 'text NOT NULL'], [Schema::TYPE_TEXT . '(255) NOT NULL', Schema::text(255)->notNull(), 'text NOT NULL'], [Schema::TYPE_SMALLINT, Schema::smallInteger(), 'smallint'], [Schema::TYPE_SMALLINT . '(8)', Schema::smallInteger(8), 'smallint'], [Schema::TYPE_INTEGER, Schema::integer(), 'integer'], [Schema::TYPE_INTEGER . '(8)', Schema::integer(8), 'integer'], [Schema::TYPE_INTEGER . ' CHECK (value > 5)', Schema::integer()->check('value > 5'), 'integer CHECK (value > 5)'], [Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', Schema::integer(8)->check('value > 5'), 'integer CHECK (value > 5)'], [Schema::TYPE_INTEGER . ' NOT NULL', Schema::integer()->notNull(), 'integer NOT NULL'], [Schema::TYPE_BIGINT, Schema::bigInteger(), 'bigint'], [Schema::TYPE_BIGINT . '(8)', Schema::bigInteger(8), 'bigint'], [Schema::TYPE_BIGINT . ' CHECK (value > 5)', Schema::bigInteger()->check('value > 5'), 'bigint CHECK (value > 5)'], [Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', Schema::bigInteger(8)->check('value > 5'), 'bigint CHECK (value > 5)'], [Schema::TYPE_BIGINT . ' NOT NULL', Schema::bigInteger()->notNull(), 'bigint NOT NULL'], [Schema::TYPE_FLOAT, Schema::float(), 'float'], [Schema::TYPE_FLOAT . '(16,5)', Schema::float(16, 5), 'float'], [Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', Schema::float()->check('value > 5.6'), 'float CHECK (value > 5.6)'], [Schema::TYPE_FLOAT . '(16,5) CHECK (value > 5.6)', Schema::float(16, 5)->check('value > 5.6'), 'float CHECK (value > 5.6)'], [Schema::TYPE_FLOAT . ' NOT NULL', Schema::float()->notNull(), 'float NOT NULL'], [Schema::TYPE_DECIMAL, Schema::decimal(), 'decimal(10,0)'], [Schema::TYPE_DECIMAL . '(12,4)', Schema::decimal(12, 4), 'decimal(12,4)'], [Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', Schema::decimal()->check('value > 5.6'), 'decimal(10,0) CHECK (value > 5.6)'], [Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', Schema::decimal(12, 4)->check('value > 5.6'), 'decimal(12,4) CHECK (value > 5.6)'], [Schema::TYPE_DECIMAL . ' NOT NULL', Schema::decimal()->notNull(), 'decimal(10,0) NOT NULL'], [Schema::TYPE_DATETIME, Schema::dateTime(), 'datetime'], [Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", Schema::dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "datetime CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"], [Schema::TYPE_DATETIME . ' NOT NULL', Schema::dateTime()->notNull(), 'datetime NOT NULL'], [Schema::TYPE_TIMESTAMP, Schema::timestamp(), 'timestamp'], [Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", Schema::timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"], [Schema::TYPE_TIMESTAMP . ' NOT NULL', Schema::timestamp()->notNull(), 'timestamp NOT NULL'], [Schema::TYPE_TIME, Schema::time(), 'time'], [Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", Schema::time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), "time CHECK (value BETWEEN '12:00:00' AND '13:01:01')"], [Schema::TYPE_TIME . ' NOT NULL', Schema::time()->notNull(), 'time NOT NULL'], [Schema::TYPE_DATE, Schema::date(), 'date'], [Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", Schema::date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "date CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"], [Schema::TYPE_DATE . ' NOT NULL', Schema::date()->notNull(), 'date NOT NULL'], [Schema::TYPE_BINARY, Schema::binary(), 'blob'], [Schema::TYPE_BOOLEAN, Schema::boolean(), 'boolean'], [Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->default(1), 'boolean NOT NULL DEFAULT 1'], [Schema::TYPE_MONEY, Schema::money(), 'decimal(19,4)'], [Schema::TYPE_MONEY . '(16,2)', Schema::money(16, 2), 'decimal(16,2)'], [Schema::TYPE_MONEY . ' CHECK (value > 0.0)', Schema::money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'], [Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', Schema::money(16, 2)->check('value > 0.0'), 'decimal(16,2) CHECK (value > 0.0)'], [Schema::TYPE_MONEY . ' NOT NULL', Schema::money()->notNull(), 'decimal(19,4) NOT NULL']];
 }
 /**
  * @param string $alias
  * @param string|array $columns
  * @param \yii\db\Schema $schema
  * @return string
  */
 protected function quoteColumn($alias, $columns, $schema)
 {
     $t = $schema->quoteSimpleTableName($alias);
     if (!is_array($columns)) {
         return $t . '.' . $schema->quoteSimpleColumnName($columns);
     }
     $result = array();
     foreach ($columns as $column) {
         $result[] = $t . '.' . $schema->quoteSimpleColumnName($column);
     }
     return implode(',', $result);
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->defaultSchema === null) {
         $this->defaultSchema = strtoupper($this->db->username);
     }
 }
 public function up()
 {
     mb_internal_encoding("UTF-8");
     $tableOptions = $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB' : null;
     $this->createTable('{{%wysiwyg}}', ['id' => Schema::primaryKey(), 'name' => Schema::string()->notNull(), 'class_name' => Schema::string()->notNull(), 'params' => Schema::text(), 'configuration_model' => Schema::string()], $tableOptions);
     $this->insert('{{%wysiwyg}}', ['name' => 'Imperavi', 'class_name' => 'vova07\\imperavi\\Widget', 'params' => Json::encode(['settings' => ['replaceDivs' => false, 'minHeight' => 200, 'paragraphize' => false, 'pastePlainText' => true, 'buttonSource' => true, 'imageManagerJson' => Url::to(['/backend/dashboard/imperavi-images-get']), 'plugins' => ['table', 'fontsize', 'fontfamily', 'fontcolor', 'video', 'imagemanager'], 'replaceStyles' => [], 'replaceTags' => [], 'deniedTags' => [], 'removeEmpty' => [], 'imageUpload' => Url::to(['/backend/dashboard/imperavi-image-upload'])]]), 'configuration_model' => 'app\\modules\\core\\models\\WysiwygConfiguration\\Imperavi']);
 }
示例#5
0
 public function quoteSimpleColumnName($name)
 {
     if (in_array(strtoupper($name), $this->reservedWords)) {
         return parent::quoteSimpleColumnName($name);
     }
     return $name;
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%file_storage_item}}', ['id' => Schema::primaryKey(), 'component' => Schema::string()->notNull(), 'base_url' => Schema::string(1024)->notNull(), 'path' => Schema::string(1024)->notNull(), 'type' => Schema::string(), 'size' => Schema::integer(), 'name' => Schema::string(), 'upload_ip' => Schema::string(15), 'created_at' => Schema::integer()->notNull()], $tableOptions);
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%page}}', ['id' => Schema::primaryKey(), 'slug' => Schema::string(2048)->notNull(), 'title' => Schema::string(512)->notNull(), 'body' => Schema::string()->notNull(), 'view' => Schema::string(), 'status' => Schema::smallInteger()->notNull(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer()], $tableOptions);
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%widget_menu}}', ['id' => Schema::primaryKey(), 'key' => Schema::string(32)->notNull(), 'title' => Schema::string()->notNull(), 'items' => Schema::text()->notNull(), 'status' => Schema::smallInteger()->notNull()->default(0)], $tableOptions);
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%user}}', ['id' => Schema::primaryKey(), 'username' => Schema::string()->notNull()->unique(), 'auth_key' => Schema::string(32)->notNull(), 'password_hash' => Schema::string()->notNull(), 'password_reset_token' => Schema::string()->unique(), 'email' => Schema::string()->notNull()->unique(), 'status' => Schema::smallInteger()->notNull()->default(10), 'created_at' => Schema::integer()->notNull(), 'updated_at' => Schema::integer()->notNull()], $tableOptions);
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%widget_text}}', ['id' => Schema::primaryKey(), 'key' => Schema::string()->notNull(), 'title' => Schema::string()->notNull(), 'body' => Schema::text()->notNull(), 'status' => Schema::smallInteger(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer()], $tableOptions);
     $this->createIndex('idx_widget_text_key', '{{%widget_text}}', 'key');
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci';
     }
     $this->createTable('{{%key_storage_item}}', ['key' => Schema::string(128)->notNull(), 'value' => Schema::text()->notNull(), 'comment' => Schema::text(), 'updated_at' => Schema::integer(), 'created_at' => Schema::integer()], $tableOptions);
     $this->addPrimaryKey('pk_key_storage_item_key', '{{%key_storage_item}}', 'key');
     $this->createIndex('idx_key_storage_item_key', '{{%key_storage_item}}', 'key', true);
 }
 public function safeUp()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%widget_carousel}}', ['id' => Schema::primaryKey(), 'key' => Schema::string()->notNull(), 'status' => Schema::smallInteger()->default(0)], $tableOptions);
     $this->createTable('{{%widget_carousel_item}}', ['id' => Schema::primaryKey(), 'carousel_id' => Schema::integer()->notNull(), 'base_url' => Schema::string(1024), 'path' => Schema::string(1024), 'type' => Schema::string(), 'url' => Schema::string(1024), 'caption' => Schema::string(1024), 'status' => Schema::smallInteger()->notNull()->default(0), 'order' => Schema::integer()->default(0), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer()], $tableOptions);
     $this->addForeignKey('fk_item_carousel', '{{%widget_carousel_item}}', 'carousel_id', '{{%widget_carousel}}', 'id', 'cascade', 'cascade');
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%timeline_event}}', ['id' => Schema::primaryKey(), 'application' => Schema::string(64)->notNull(), 'category' => Schema::string(64)->notNull(), 'event' => Schema::string(64)->notNull(), 'data' => Schema::text(), 'created_at' => Schema::integer()->notNull()], $tableOptions);
     $this->createIndex('idx_created_at', '{{%timeline_event}}', 'created_at');
     $this->batchInsert('{{%timeline_event}}', ['application', 'category', 'event', 'data', 'created_at'], [['frontend', 'user', 'signup', json_encode(['public_identity' => 'webmaster', 'user_id' => 1, 'created_at' => time()]), time()], ['frontend', 'user', 'signup', json_encode(['public_identity' => 'manager', 'user_id' => 2, 'created_at' => time()]), time()], ['frontend', 'user', 'signup', json_encode(['public_identity' => 'user', 'user_id' => 3, 'created_at' => time()]), time()]]);
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%user}}', ['id' => Schema::primaryKey(), 'username' => Schema::string(32), 'auth_key' => Schema::string(32)->notNull(), 'password_hash' => Schema::string()->notNull(), 'password_reset_token' => Schema::string(), 'oauth_client' => Schema::string(), 'oauth_client_user_id' => Schema::string(), 'email' => Schema::string()->notNull(), 'status' => Schema::smallInteger()->notNull()->default(User::STATUS_ACTIVE), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer(), 'logged_at' => Schema::integer()], $tableOptions);
     $this->createTable('{{%user_profile}}', ['user_id' => Schema::primaryKey(), 'firstname' => Schema::string(), 'middlename' => Schema::string(), 'lastname' => Schema::string(), 'avatar_path' => Schema::string(), 'avatar_base_url' => Schema::string(), 'locale' => Schema::string(32)->notNull(), 'gender' => Schema::smallInteger(1)], $tableOptions);
     $this->addForeignKey('fk_user', '{{%user_profile}}', 'user_id', '{{%user}}', 'id', 'cascade', 'cascade');
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%i18n_source_message}}', ['id' => Schema::primaryKey(), 'category' => Schema::string(32), 'message' => Schema::text()], $tableOptions);
     $this->createTable('{{%i18n_message}}', ['id' => Schema::integer(), 'language' => Schema::string(16), 'translation' => Schema::text()], $tableOptions);
     $this->addPrimaryKey('i18n_message_pk', '{{%i18n_message}}', ['id', 'language']);
     $this->addForeignKey('fk_i18n_message_source_message', '{{%i18n_message}}', 'id', '{{%i18n_source_message}}', 'id', 'cascade', 'restrict');
 }
 public function safeUp()
 {
     $tableNames = array_merge($this->tableNames, ArrayHelper::getValue(Yii::$app->params, 'migration.rbac', []));
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable($tableNames['ruleTable'], ['name' => Schema::string(64)->notNull(), 'data' => Schema::text(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer(), 'PRIMARY KEY (name)'], $tableOptions);
     $this->createTable($tableNames['itemTable'], ['name' => Schema::string(64)->notNull(), 'type' => Schema::integer()->notNull(), 'description' => Schema::text(), 'rule_name' => Schema::string(64), 'data' => Schema::text(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer(), 'PRIMARY KEY (name)', 'FOREIGN KEY (rule_name) REFERENCES ' . $tableNames['ruleTable'] . ' (name) ON DELETE SET NULL ON UPDATE CASCADE'], $tableOptions);
     $this->createIndex('idx-auth_item-type', $tableNames['itemTable'], 'type');
     $this->createTable($tableNames['itemChildTable'], ['parent' => Schema::string(64)->notNull(), 'child' => Schema::string(64)->notNull(), 'PRIMARY KEY (parent, child)', 'FOREIGN KEY (parent) REFERENCES ' . $tableNames['itemTable'] . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', 'FOREIGN KEY (child) REFERENCES ' . $tableNames['itemTable'] . ' (name) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
     $this->createTable($tableNames['assignmentTable'], ['item_name' => Schema::string(64)->notNull(), 'user_id' => Schema::string(64)->notNull(), 'created_at' => Schema::integer(), 'PRIMARY KEY (item_name, user_id)', 'FOREIGN KEY (item_name) REFERENCES ' . $tableNames['itemTable'] . ' (name) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
 }
 public function up()
 {
     $authManager = $this->getAuthManager();
     $this->db = $authManager->db;
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable($authManager->ruleTable, ['name' => Schema::string(64)->notNull(), 'data' => Schema::text(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer(), 'PRIMARY KEY (name)'], $tableOptions);
     $this->createTable($authManager->itemTable, ['name' => Schema::string(64)->notNull(), 'type' => Schema::integer()->notNull(), 'description' => Schema::text(), 'rule_name' => Schema::string(64), 'data' => Schema::text(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer(), 'PRIMARY KEY (name)', 'FOREIGN KEY (rule_name) REFERENCES ' . $authManager->ruleTable . ' (name) ON DELETE SET NULL ON UPDATE CASCADE'], $tableOptions);
     $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type');
     $this->createTable($authManager->itemChildTable, ['parent' => Schema::string(64)->notNull(), 'child' => Schema::string(64)->notNull(), 'PRIMARY KEY (parent, child)', 'FOREIGN KEY (parent) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', 'FOREIGN KEY (child) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
     $this->createTable($authManager->assignmentTable, ['item_name' => Schema::string(64)->notNull(), 'user_id' => Schema::string(64)->notNull(), 'created_at' => Schema::integer(), 'PRIMARY KEY (item_name, user_id)', 'FOREIGN KEY (item_name) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
 }
 public function safeUp()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('{{%article_category}}', ['id' => Schema::primaryKey(), 'slug' => Schema::string(1024)->notNull(), 'title' => Schema::string(512)->notNull(), 'body' => Schema::text(), 'parent_id' => Schema::integer(), 'status' => Schema::smallInteger()->notNull()->default(0), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer()], $tableOptions);
     $this->createTable('{{%article}}', ['id' => Schema::primaryKey(), 'slug' => Schema::string(1024)->notNull(), 'title' => Schema::string(512)->notNull(), 'body' => Schema::text()->notNull(), 'view' => Schema::string(), 'category_id' => Schema::integer(), 'thumbnail_base_url' => Schema::string(1024), 'thumbnail_path' => Schema::string(1024), 'author_id' => Schema::integer(), 'updater_id' => Schema::integer(), 'status' => Schema::smallInteger()->notNull()->default(0), 'published_at' => Schema::integer(), 'created_at' => Schema::integer(), 'updated_at' => Schema::integer()], $tableOptions);
     $this->createTable('{{%article_attachment}}', ['id' => Schema::primaryKey(), 'article_id' => Schema::integer()->notNull(), 'path' => Schema::string()->notNull(), 'base_url' => Schema::string(), 'type' => Schema::string(), 'size' => Schema::integer(), 'name' => Schema::string(), 'created_at' => Schema::integer()]);
     $this->addForeignKey('fk_article_attachment_article', '{{%article_attachment}}', 'article_id', '{{%article}}', 'id', 'cascade', 'cascade');
     $this->addForeignKey('fk_article_author', '{{%article}}', 'author_id', '{{%user}}', 'id', 'cascade', 'cascade');
     $this->addForeignKey('fk_article_updater', '{{%article}}', 'updater_id', '{{%user}}', 'id', 'set null', 'cascade');
     $this->addForeignKey('fk_article_category', '{{%article}}', 'category_id', '{{%article_category}}', 'id');
     $this->addForeignKey('fk_article_category_section', '{{%article_category}}', 'parent_id', '{{%article_category}}', 'id', 'cascade', 'cascade');
 }
示例#19
0
文件: Schema.php 项目: janatzend/app
 public function getSchemaNames($refresh = false)
 {
     return parent::getSchemaNames($refresh);
 }
示例#20
0
 /**
  *
  * @param \yii\db\ColumnSchema $column
  * @return string
  */
 public function getSchemaType($column)
 {
     if ($this->constans === null) {
         $this->constans = [];
         $ref = new \ReflectionClass(Schema::className());
         foreach ($ref->getConstants() as $constName => $constValue) {
             if (strpos($constName, 'TYPE_') === 0) {
                 $this->constans[$constValue] = 'Schema::' . $constName;
             }
         }
     }
     if ($column->type !== Schema::TYPE_BOOLEAN && $column->size !== null) {
         $size = [$column->size];
         if ($column->scale !== null) {
             $size[] = $column->scale;
         }
         $size = '(' . implode(',', $size) . ')';
     } else {
         $size = '';
     }
     if (isset($this->constans[$column->type])) {
         return [$this->constans[$column->type], $size];
     } else {
         return [$column->dbType, ''];
     }
 }
示例#21
0
 /**
  *
  * @param \yii\db\ColumnSchema $column
  * @return array
  */
 public function getSchemaType($column)
 {
     if ($this->constans === null) {
         $this->constans = [];
         $ref = new \ReflectionClass(Schema::className());
         foreach ($ref->getConstants() as $constName => $constValue) {
             if (strpos($constName, 'TYPE_') === 0) {
                 $this->constans[$constValue] = '$this->' . $constValue;
             }
         }
         $this->constans['smallint'] = '$this->smallInteger';
         $this->constans['bigint'] = '$this->bigInteger';
     }
     if ($column->type !== Schema::TYPE_BOOLEAN && $column->size !== null) {
         $size = [$column->size];
         if ($column->scale !== null) {
             $size[] = $column->scale;
         }
     } else {
         $size = [];
     }
     $result = '';
     if (isset($this->constans[$column->type])) {
         $result = $this->constans[$column->type] . '(' . implode(',', $size) . ')';
         if (!$column->allowNull) {
             $result .= '->notNull()';
         }
         if ($column->defaultValue !== null) {
             $default = is_string($column->defaultValue) ? "'" . addslashes($column->defaultValue) . "'" : $column->defaultValue;
             $result .= "->defaultValue({$default})";
         }
     } else {
         $result = $column->dbType;
         if (!empty($size)) {
             $result .= '(' . implode(',', $size) . ')';
         }
         if (!$column->allowNull) {
             $result .= ' NOT NULL';
         }
         if ($column->defaultValue !== null) {
             $default = is_string($column->defaultValue) ? "'" . addslashes($column->defaultValue) . "'" : $column->defaultValue;
             $result .= " DEFAULT {$default}";
         }
         $result = '"' . $result . '"';
     }
     return $result;
 }
 public function up()
 {
     $this->addColumn('{{image}}', 'image_alt', Schema::text());
     $this->renameColumn('{{image}}', 'image_description', 'image_title');
 }
示例#23
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
 }
示例#24
0
 /**
  * @inheritdoc
  */
 public function getTableSchema($name, $refresh = false)
 {
     // Internal table name is uppercase and
     // to ensure the consistency of the key cache
     return parent::getTableSchema(strtoupper($name), $refresh);
 }
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * It checks the existence of the [[migrationPath]].
  * @param \yii\base\Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id !== 'create') {
             $this->db = Instance::ensure($this->db, Connection::className());
             Schema::setDb($this->db);
         }
         return true;
     } else {
         return false;
     }
 }
示例#26
0
 /**
  * Refreshes the particular table schema.
  * This method cleans up cached table schema so that it can be re-created later
  * to reflect the database schema change.
  * @param string $name table name.
  * @since 2.0.6
  */
 public function refreshTableSchema($name)
 {
     try {
         $sql = "CALL ADMIN_CMD ('REORG TABLE " . $this->db->quoteTableName($name) . "')";
         $this->db->createCommand($sql)->execute();
     } catch (\Exception $ex) {
         // Do not throw error on table which doesn't exist
         if (!(isset($ex->errorInfo[1]) && $ex->errorInfo[1] === -2211)) {
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
         }
     }
     parent::refreshTableSchema($name);
 }
示例#27
0
文件: Schema.php 项目: yiisoft/yii2
 /**
  * @inheritdoc
  * @see http://www.cubrid.org/manual/91/en/sql/transaction.html#database-concurrency
  */
 public function setTransactionIsolationLevel($level)
 {
     // translate SQL92 levels to CUBRID levels:
     switch ($level) {
         case Transaction::SERIALIZABLE:
             $level = '6';
             // SERIALIZABLE
             break;
         case Transaction::REPEATABLE_READ:
             $level = '5';
             // REPEATABLE READ CLASS with REPEATABLE READ INSTANCES
             break;
         case Transaction::READ_COMMITTED:
             $level = '4';
             // REPEATABLE READ CLASS with READ COMMITTED INSTANCES
             break;
         case Transaction::READ_UNCOMMITTED:
             $level = '3';
             // REPEATABLE READ CLASS with READ UNCOMMITTED INSTANCES
             break;
     }
     parent::setTransactionIsolationLevel($level);
 }
示例#28
0
 /**
  * Sets the isolation level of the current transaction.
  * @param string $level The transaction isolation level to use for this transaction.
  * This can be one of [[Transaction::READ_UNCOMMITTED]], [[Transaction::READ_COMMITTED]], [[Transaction::REPEATABLE_READ]]
  * and [[Transaction::SERIALIZABLE]] but also a string containing DBMS specific syntax to be used
  * after `SET TRANSACTION ISOLATION LEVEL`.
  * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels
  */
 public function setTransactionIsolationLevel($level)
 {
     if ($level == \yii\db\Transaction::READ_UNCOMMITTED) {
         parent::setTransactionIsolationLevel('READ COMMITTED RECORD_VERSION');
     } elseif ($level == \yii\db\Transaction::REPEATABLE_READ) {
         parent::setTransactionIsolationLevel('SNAPSHOT');
     } elseif ($level == \yii\db\Transaction::SERIALIZABLE) {
         parent::setTransactionIsolationLevel('SNAPSHOT TABLE STABILITY');
     } else {
         parent::setTransactionIsolationLevel($level);
     }
 }
 public function up()
 {
     $this->addColumn('{{%wysiwyg}}', 'configuration_view', Schema::string());
     $this->update('{{%wysiwyg}}', ['configuration_view' => '@app/modules/core/wysiwyg/imperavi-config.php'], ['name' => 'Imperavi']);
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->db->enableSavepoint = false;
 }