+++ /dev/null
-<?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;
- }
- */
-}
--- /dev/null
+<?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;
+ }
+ */
+}