Commit 92bb547ffbd04870089a0f54feeadb0a7d2a3bb9

Authored by Mihail
1 parent 2501a752

add migration and AR for importer table

backend/models/Importer.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use Yii;
  6 +use backend\components\base\BaseActiveRecord;
  7 +
  8 +/**
  9 + * This is the model class for table "{{%importer}}".
  10 + *
  11 + * @property integer $id
  12 + * @property string $code
  13 + * @property string $name
  14 + * @property string $name_price
  15 + * @property string $currency_id
  16 + * @property string $delivery
  17 + * @property string $email
  18 + * @property string $info
  19 + * @property integer $active
  20 + * @property integer $PARSER_IS_ACTIVE
  21 + * @property string $PARSER_COLUMN_COUNT
  22 + * @property string $PARSER_FIELD_BRAND
  23 + * @property string $PARSER_FIELD_ARTICLE
  24 + * @property integer $PARSER_FIELD_ARTICLE_PREFIX
  25 + * @property string $PARSER_FIELD_PRICE
  26 + * @property string $PARSER_FIELD_DESCR
  27 + * @property string $PARSER_FIELD_BOX
  28 + * @property string $PARSER_FIELD_ADD_BOX
  29 + * @property string $PARSER_FIELD_GROUP_RG
  30 + * @property string $PARSER_FIELD_SIGN
  31 + * @property double $PARSER_FIELD_MULTIPLIER
  32 + * @property string $price_date_update
  33 + */
  34 +class Importer extends BaseActiveRecord
  35 +{
  36 + /**
  37 + * @inheritdoc
  38 + */
  39 + public static function tableName()
  40 + {
  41 + return '{{%importer}}';
  42 + }
  43 +
  44 + /**
  45 + * @inheritdoc
  46 + */
  47 + public function rules()
  48 + {
  49 + return [
  50 + [['code', 'name', 'name_price', 'currency_id', 'delivery', 'email', 'info', 'PARSER_FIELD_SIGN', 'price_date_update'], 'required'],
  51 + [['currency_id', 'active', 'PARSER_IS_ACTIVE', 'PARSER_COLUMN_COUNT', 'PARSER_FIELD_BRAND', 'PARSER_FIELD_ARTICLE', 'PARSER_FIELD_ARTICLE_PREFIX', 'PARSER_FIELD_PRICE', 'PARSER_FIELD_DESCR', 'PARSER_FIELD_BOX', 'PARSER_FIELD_ADD_BOX', 'PARSER_FIELD_GROUP_RG'], 'integer'],
  52 + [['info'], 'string'],
  53 + [['PARSER_FIELD_MULTIPLIER'], 'number'],
  54 + [['code', 'name', 'name_price', 'delivery', 'email'], 'string', 'max' => 254],
  55 + [['PARSER_FIELD_SIGN'], 'string', 'max' => 1],
  56 + [['price_date_update'], 'string', 'max' => 15],
  57 + [['code'], 'unique'],
  58 + [['name'], 'unique']
  59 + ];
  60 + }
  61 +
  62 + /**
  63 + * @inheritdoc
  64 + */
  65 + public function attributeLabels()
  66 + {
  67 + return [
  68 + 'id' => Yii::t('app', 'ID'),
  69 + 'code' => Yii::t('app', 'Code'),
  70 + 'name' => Yii::t('app', 'Name'),
  71 + 'name_price' => Yii::t('app', 'Name Price'),
  72 + 'currency_id' => Yii::t('app', 'Currency ID'),
  73 + 'delivery' => Yii::t('app', 'Delivery'),
  74 + 'email' => Yii::t('app', 'Email'),
  75 + 'info' => Yii::t('app', 'Info'),
  76 + 'active' => Yii::t('app', 'Active'),
  77 + 'PARSER_IS_ACTIVE' => Yii::t('app', 'Parser Is Active'),
  78 + 'PARSER_COLUMN_COUNT' => Yii::t('app', 'Parser Column Count'),
  79 + 'PARSER_FIELD_BRAND' => Yii::t('app', 'Parser Field Brand'),
  80 + 'PARSER_FIELD_ARTICLE' => Yii::t('app', 'Parser Field Article'),
  81 + 'PARSER_FIELD_ARTICLE_PREFIX' => Yii::t('app', 'Parser Field Article Prefix'),
  82 + 'PARSER_FIELD_PRICE' => Yii::t('app', 'Parser Field Price'),
  83 + 'PARSER_FIELD_DESCR' => Yii::t('app', 'Parser Field Descr'),
  84 + 'PARSER_FIELD_BOX' => Yii::t('app', 'Parser Field Box'),
  85 + 'PARSER_FIELD_ADD_BOX' => Yii::t('app', 'Parser Field Add Box'),
  86 + 'PARSER_FIELD_GROUP_RG' => Yii::t('app', 'Parser Field Group Rg'),
  87 + 'PARSER_FIELD_SIGN' => Yii::t('app', 'Parser Field Sign'),
  88 + 'PARSER_FIELD_MULTIPLIER' => Yii::t('app', 'Parser Field Multiplier'),
  89 + 'price_date_update' => Yii::t('app', 'Price Date Update'),
  90 + ];
  91 + }
  92 +}
... ...
console/migrations/m150831_130250_addImporters.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Schema;
  4 +use yii\db\Migration;
  5 +
  6 +class m150831_130250_addImporters extends Migration
  7 +{
  8 + public function up()
  9 + {
  10 + $tableOptions = null;
  11 + if ($this->db->driverName === 'mysql') {
  12 + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
  13 + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
  14 + }
  15 +
  16 +// 'userid' => Schema::TYPE_PK . ' AUTO_INCREMENT',
  17 +// 'email' => Schema::TYPE_STRING . '(45) NOT NULL',
  18 +// 'name' => Schema::TYPE_STRING . '(100) NOT NULL',
  19 +//
  20 +// CREATE TABLE 'w_importers' (
  21 +// 'id' int(6) unsigned NOT NULL AUTO_INCREMENT,
  22 +// 'code' varchar(254) NOT NULL,
  23 +// 'name' varchar(254) NOT NULL,
  24 +// 'name_price' varchar(254) NOT NULL,
  25 +// 'currency_id' int(3) unsigned NOT NULL,
  26 +// 'delivery' varchar(254) NOT NULL,
  27 +// 'email' varchar(254) NOT NULL,
  28 +// 'info' text NOT NULL,
  29 +// 'active' tinyint(1) unsigned NOT NULL DEFAULT '1',
  30 +// 'PARSER_IS_ACTIVE' tinyint(1) unsigned NOT NULL DEFAULT '0',
  31 +// 'PARSER_COLUMN_COUNT' int(6) unsigned DEFAULT NULL,
  32 +// 'PARSER_FIELD_BRAND' int(3) unsigned DEFAULT NULL,
  33 +// 'PARSER_FIELD_ARTICLE' int(3) unsigned DEFAULT NULL,
  34 +// 'PARSER_FIELD_ARTICLE_PREFIX' tinyint(1) unsigned NOT NULL DEFAULT '0',
  35 +// 'PARSER_FIELD_PRICE' int(3) unsigned DEFAULT NULL,
  36 +// 'PARSER_FIELD_DESCR' int(3) unsigned DEFAULT NULL,
  37 +// 'PARSER_FIELD_BOX' int(3) unsigned DEFAULT NULL,
  38 +// 'PARSER_FIELD_ADD_BOX' int(3) unsigned DEFAULT NULL,
  39 +// 'PARSER_FIELD_GROUP_RG' int(3) unsigned DEFAULT NULL,
  40 +// 'PARSER_FIELD_SIGN' varchar(1) NOT NULL DEFAULT '',
  41 +// 'PARSER_FIELD_MULTIPLIER' float(8,2) unsigned DEFAULT NULL,
  42 +// 'price_date_update' varchar(15) NOT NULL,
  43 +// PRIMARY KEY ('id'),
  44 +// UNIQUE KEY 'code' ('code'),
  45 +// UNIQUE KEY 'name' ('name'),
  46 +// KEY 'active' ('active')
  47 +// ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  48 +
  49 + $this->createTable('{{%importer}}', [
  50 + 'id' => $this->primaryKey(6)->notNull() . ' AUTO_INCREMENT',
  51 + 'code' =>'varchar(254) NOT NULL',
  52 + 'name' => 'varchar(254) NOT NULL',
  53 + 'name_price' => 'varchar(254) NOT NULL',
  54 + 'currency_id' => 'int(3) unsigned NOT NULL',
  55 + 'delivery' => 'varchar(254) NOT NULL',
  56 + 'email' => 'varchar(254) NOT NULL',
  57 + 'info' => 'text NOT NULL',
  58 + 'active' => 'tinyint(1) unsigned NOT NULL DEFAULT 1',
  59 + 'PARSER_IS_ACTIVE' => 'tinyint(1) unsigned NOT NULL DEFAULT 0',
  60 + 'PARSER_COLUMN_COUNT' => 'int(6) unsigned DEFAULT NULL',
  61 + 'PARSER_FIELD_BRAND' => 'int(3) unsigned DEFAULT NULL',
  62 + 'PARSER_FIELD_ARTICLE' => 'int(3) unsigned DEFAULT NULL',
  63 + 'PARSER_FIELD_ARTICLE_PREFIX' => 'tinyint(1) unsigned NOT NULL DEFAULT 0',
  64 + 'PARSER_FIELD_PRICE' => 'int(3) unsigned DEFAULT NULL',
  65 + 'PARSER_FIELD_DESCR' =>'int(3) unsigned DEFAULT NULL',
  66 + 'PARSER_FIELD_BOX' => 'int(3) unsigned DEFAULT NULL',
  67 + 'PARSER_FIELD_ADD_BOX' => 'int(3) unsigned DEFAULT NULL',
  68 + 'PARSER_FIELD_GROUP_RG' => 'int(3) unsigned DEFAULT NULL',
  69 + 'PARSER_FIELD_SIGN' => 'varchar(1) NOT NULL',
  70 + 'PARSER_FIELD_MULTIPLIER' => 'float(8,2) unsigned DEFAULT NULL',
  71 + 'price_date_update' => 'varchar(15) NOT NULL'
  72 +
  73 + ], $tableOptions);
  74 +
  75 + $this->createIndex('code', '{{%importer}}', 'code', true);
  76 + $this->createIndex('name', '{{%importer}}', 'name', true);
  77 + $this->createIndex('active', '{{%importer}}', 'active', false);
  78 + }
  79 +
  80 + public function down()
  81 + {
  82 + $this->dropTable('{{%importer}}');
  83 +
  84 + return false;
  85 + }
  86 +
  87 + /*
  88 + // Use safeUp/safeDown to run migration code within a transaction
  89 + public function safeUp()
  90 + {
  91 + }
  92 +
  93 + public function safeDown()
  94 + {
  95 + }
  96 + */
  97 +}
... ...