@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m221108_125006_drop_unnecessary_tables_for_document
|
||||
*/
|
||||
class m221108_125006_drop_unnecessary_tables_for_document extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->dropTable('accompanying_document');
|
||||
$this->dropTable('document_field_value');
|
||||
$this->dropTable('template_document_field');
|
||||
$this->dropTable('document');
|
||||
$this->dropTable('template');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->createTable('{{%template}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'title' => $this->string(),
|
||||
'created_at' => $this->dateTime(),
|
||||
'updated_at' => $this->dateTime(),
|
||||
'template_file_name' => $this->string(255),
|
||||
'document_type' => $this->integer()->defaultValue(null)
|
||||
|
||||
]);
|
||||
|
||||
|
||||
$this->createTable('{{%document}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'title' => $this->string(),
|
||||
'created_at' => $this->dateTime(),
|
||||
'updated_at' => $this->dateTime(),
|
||||
'template_id' => $this->integer(11)->notNull(),
|
||||
'manager_id' => $this->integer(11)->notNull(),
|
||||
]);
|
||||
$this->addForeignKey('document_template', 'document', 'template_id', 'template', 'id');
|
||||
$this->addForeignKey('document_manager', 'document', 'manager_id', 'manager', 'id');
|
||||
|
||||
|
||||
$this->createTable('{{%template_document_field}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'template_id' => $this->integer(11)->notNull(),
|
||||
'field_id' => $this->integer(11)->notNull()
|
||||
]);
|
||||
$this->addForeignKey('template_template_document_field', 'template_document_field', 'template_id', 'template', 'id');
|
||||
$this->addForeignKey('document_field_template_document_field', 'template_document_field', 'field_id', 'document_field', 'id');
|
||||
|
||||
|
||||
$this->createTable('{{%document_field_value}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'field_id' => $this->integer(11)->notNull(),
|
||||
'document_id' => $this->integer(11)->notNull(),
|
||||
'value' => $this->string()
|
||||
]);
|
||||
$this->addForeignKey('document_field_document_field_value', 'document_field_value', 'field_id', 'document_field', 'id');
|
||||
$this->addForeignKey('document_document_field_value', 'document_field_value', 'document_id', 'document', 'id');
|
||||
|
||||
|
||||
$this->createTable('{{%accompanying_document}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'document_id' => $this->integer(11),
|
||||
'title' => $this->string()->notNull(),
|
||||
]);
|
||||
$this->addForeignKey('document_accompanying_document', 'accompanying_document', 'document_id', 'document', 'id');
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m221108_125006_drop_unnecessary_tables_for_document cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%document_template}}`.
|
||||
*/
|
||||
class m221108_135514_create_document_template_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%document_template}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'title' => $this->string(),
|
||||
'template_body' => $this->text(),
|
||||
'status' => $this->integer(),
|
||||
'created_at' => $this->dateTime(),
|
||||
'updated_at' => $this->dateTime(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropTable('{{%document_template}}');
|
||||
}
|
||||
}
|
42
console/migrations/m221108_135939_create_document_table.php
Normal file
42
console/migrations/m221108_135939_create_document_table.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%document}}`.
|
||||
*/
|
||||
class m221108_135939_create_document_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%document}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'company_id' => $this->integer(11)->notNull(),
|
||||
'contractor_company_id' => $this->integer(11)->notNull(),
|
||||
'manager_id' => $this->integer(11)->notNull(),
|
||||
'contractor_manager_id' => $this->integer(11)->notNull(),
|
||||
'template_id' => $this->integer(11)->notNull(),
|
||||
'title' => $this->string(),
|
||||
'body' => $this->text(),
|
||||
'created_at' => $this->dateTime(),
|
||||
'updated_at' => $this->dateTime(),
|
||||
]);
|
||||
|
||||
$this->addForeignKey('company_document', 'document', 'company_id', 'company', 'id');
|
||||
$this->addForeignKey('contractor_company_document', 'document', 'contractor_company_id', 'company', 'id');
|
||||
$this->addForeignKey('manager_document', 'document', 'manager_id','manager', 'id');
|
||||
$this->addForeignKey('contractor_manager_document', 'document', 'contractor_manager_id','manager', 'id');
|
||||
$this->addForeignKey('document_template_document', 'document', 'template_id','document_template', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropTable('{{%document}}');
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use common\models\DocumentField;
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m221115_094557_add_update_default_and_add_new_fields_in_document_field_table
|
||||
*/
|
||||
class m221115_094557_update_default_and_add_new_fields_in_document_field_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$documentFields = DocumentField::find()->all();
|
||||
foreach ($documentFields as $documentField) {
|
||||
$documentField->field_template = '${' . $documentField->field_template . '}';
|
||||
$documentField->update();
|
||||
}
|
||||
|
||||
Yii::$app->db->createCommand()->batchInsert('document_field', [ 'title', 'field_template'],
|
||||
[
|
||||
['№ договора', '${contract_number}'],
|
||||
['Название', '${title}'],
|
||||
['Компания', '${company}'],
|
||||
['Представитель', '${manager}'],
|
||||
['Компания контрагент', '${contractor_company}'],
|
||||
['Представитель контрагента', '${contractor_manager}']
|
||||
])->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
Yii::$app->db->createCommand()->delete('document_field',
|
||||
[
|
||||
'in', 'title', [
|
||||
'№ договора',
|
||||
'Название',
|
||||
'Компания',
|
||||
'Представитель',
|
||||
'Компания контрагент',
|
||||
'Представитель контрагента',
|
||||
]
|
||||
])->execute();
|
||||
|
||||
$documentFields = DocumentField::find()->all();
|
||||
foreach ($documentFields as $documentField) {
|
||||
$documentField->field_template = str_replace(['${', '}'], '', $documentField->field_template);
|
||||
$documentField->update();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m221115_094557_add_update_default_andaddnewfieldsin_document_field_table cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user