]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Таблица хранения чатов
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 25 Dec 2024 12:49:36 +0000 (15:49 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 25 Dec 2024 12:49:36 +0000 (15:49 +0300)
erp24/migrations/m241224_140248_add_column_telegram_chat_id_to_users_table.php [deleted file]
erp24/migrations/m241224_140248_create_users_telegram_chat_id_table.php [new file with mode: 0644]

diff --git a/erp24/migrations/m241224_140248_add_column_telegram_chat_id_to_users_table.php b/erp24/migrations/m241224_140248_add_column_telegram_chat_id_to_users_table.php
deleted file mode 100644 (file)
index 322e5e6..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-use yii\db\Migration;
-
-/**
- * Class m241224_140248_add_telegram_chat_id_to_users_table
- */
-class m241224_140248_add_column_telegram_chat_id_to_users_table extends Migration
-{
-    const TABLE_NAME = 'erp24.users';
-    const COLUMN_NAME = 'telegram_chat_id';
-    /**
-     * {@inheritdoc}
-     */
-    public function safeUp()
-    {
-        if (!$this->db->getTableSchema(self::TABLE_NAME, true)->getColumn(self::COLUMN_NAME)) {
-            $this->addColumn(self::TABLE_NAME, self::COLUMN_NAME, $this->string()->comment('Telegram Chat ID'));
-        }
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function safeDown()
-    {
-        if ($this->db->getTableSchema(self::TABLE_NAME, true)->getColumn(self::COLUMN_NAME)) {
-            $this->dropColumn(self::TABLE_NAME, self::COLUMN_NAME);
-        }
-    }
-
-    /*
-    // Use up()/down() to run migration code without a transaction.
-    public function up()
-    {
-
-    }
-
-    public function down()
-    {
-        echo "m241224_140248_add_telegram_chat_id_to_users_table cannot be reverted.\n";
-
-        return false;
-    }
-    */
-}
diff --git a/erp24/migrations/m241224_140248_create_users_telegram_chat_id_table.php b/erp24/migrations/m241224_140248_create_users_telegram_chat_id_table.php
new file mode 100644 (file)
index 0000000..53217ec
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m241224_140248_add_telegram_chat_id_to_users_table
+ */
+class m241224_140248_create_users_telegram_chat_id_table extends Migration
+{
+    const TABLE_NAME = 'erp24.users_telegram_chat_id';
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+        if (!isset($tableSchema)) {
+            $this->createTable(self::TABLE_NAME, [
+                'chat_id' => $this->string()->notNull()->comment('Chat ID'),
+                'phone' => $this->string()->null()->comment('Телефон'),
+                'username' => $this->string()->null()->comment('Имя пользователя в Телеграм'),
+                'first_name' => $this->string()->null()->comment('Имя пользователя'),
+                'is_blocked' => $this->integer(1)->notNull()->defaultValue(0)->comment(
+                    'Заблокирован: 0 - нет, 1 - да'
+                ),
+                'is_registered' => $this->integer(1)->notNull()->defaultValue(0)->comment(
+                    'Зарегистрирован: 0 - нет, 1 - да'
+                ),
+            ]);
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+        if (isset($tableSchema)) {
+            $this->dropTable(self::TABLE_NAME);
+        }
+    }
+
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m241224_140248_add_telegram_chat_id_to_users_table cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}