m170519_134656_create_workflow_transitions_log.php 2.31 KB
Newer Older
Marcello Pivanti's avatar
Marcello Pivanti committed
1
<?php
Aster's avatar
Aster committed
2

Marcello Pivanti's avatar
Marcello Pivanti committed
3
/**
Aster's avatar
Aster committed
4
5
 * Emilia Romagna Open Innovation
 * Arter
Marcello Pivanti's avatar
Marcello Pivanti committed
6
7
 *
 *
Aster's avatar
Aster committed
8
 * @package    arter\amos\workflow\migrations
Marcello Pivanti's avatar
Marcello Pivanti committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 * @category   CategoryName
 */

use yii\db\Migration;

class m170519_134656_create_workflow_transitions_log extends Migration
{
    const TABLE = '{{%amos_workflow_transitions_log}}';

    public function safeUp()
    {
        $tableName = $this->db->getSchema()->getRawTableName(self::TABLE);
        if ($this->db->schema->getTableSchema(self::TABLE, true) === null) {
            try {
                $this->createTable(self::TABLE, [
                    'id' => $this->primaryKey(),
                    'classname' => $this->text(255)->defaultValue(null)->comment('Name of the class'),
                    'owner_primary_key' => $this->text(255)->defaultValue(null)->comment('Primary key'),
                    'start_status' => $this->text(255)->defaultValue(null)->comment('Start status'),
                    'end_status' => $this->text(255)->defaultValue(null)->comment('End status'),
                    'created_at' => $this->dateTime()->null()->defaultValue(null),
                    'updated_at' => $this->dateTime()->null()->defaultValue(null),
                    'deleted_at' => $this->dateTime()->null()->defaultValue(null),
                    'created_by' => $this->integer()->null()->defaultValue(null),
                    'updated_by' => $this->integer()->null()->defaultValue(null),
                    'deleted_by' => $this->integer()->null()->defaultValue(null),
                ], $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB AUTO_INCREMENT=1' : null);
            } catch (Exception $e) {
                echo "Error on creation " . $tableName . "\n";
                echo $e->getMessage() . "\n";
                return false;
            }
        } else {
            echo "Table already exist " . $tableName . "\n";
        }

        return true;
    }

    public function safeDown()
    {
        try {
//            $this->execute("SET FOREIGN_KEY_CHECKS = 0;");
            $this->dropTable(self::TABLE);
//            $this->execute("SET FOREIGN_KEY_CHECKS = 1;");
        } catch (Exception $e) {
            echo "Error on drop table " . self::TABLE . "\n";
            echo $e->getMessage() . "\n";
            return false;
        }

        return true;
    }

}