]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление логирования на загрузку файлов в документ списания.
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Tue, 17 Feb 2026 06:39:01 +0000 (09:39 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Tue, 17 Feb 2026 06:39:01 +0000 (09:39 +0300)
erp24/migrations/m250123_100000_create_table_products_1c_class_dynamic.php
erp24/migrations/m260127_105454_create_shift_reminder_shown_table.php
erp24/migrations/m260215_200000_create_upload_speed_tests_table.php

index b69225550255c2180ad28be0f275a1f20cbff6bf..f9d02414398515198cc843d4e581cf6ddbcbfc1c 100644 (file)
@@ -54,56 +54,72 @@ class m250123_100000_create_table_products_1c_class_dynamic extends Migration
             ]);
 
             // Индексы
-            $this->createIndex(
-                'idx_p1c_class_dyn_product_id',
-                self::TABLE_NAME,
-                'product_id'
-            );
-
-            $this->createIndex(
-                'idx_p1c_class_dyn_active',
-                self::TABLE_NAME,
-                'active'
-            );
-
-            $this->createIndex(
-                'idx_p1c_class_dyn_dates',
-                self::TABLE_NAME,
-                ['date_from', 'date_to']
-            );
-
-            $this->createIndex(
-                'idx_p1c_class_dyn_class_tip',
-                self::TABLE_NAME,
-                'class_tip'
-            );
-
-            $this->createIndex(
-                'idx_p1c_class_dyn_product_active',
-                self::TABLE_NAME,
-                ['product_id', 'active']
-            );
-
-            $this->createIndex(
-                'idx_p1c_class_dyn_parent_id',
-                self::TABLE_NAME,
-                'parent_id'
-            );
+            if (!$this->indexExists('idx_p1c_class_dyn_product_id')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_product_id',
+                    self::TABLE_NAME,
+                    'product_id'
+                );
+            }
+
+            if (!$this->indexExists('idx_p1c_class_dyn_active')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_active',
+                    self::TABLE_NAME,
+                    'active'
+                );
+            }
+
+            if (!$this->indexExists('idx_p1c_class_dyn_dates')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_dates',
+                    self::TABLE_NAME,
+                    ['date_from', 'date_to']
+                );
+            }
+
+            if (!$this->indexExists('idx_p1c_class_dyn_class_tip')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_class_tip',
+                    self::TABLE_NAME,
+                    'class_tip'
+                );
+            }
+
+            if (!$this->indexExists('idx_p1c_class_dyn_product_active')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_product_active',
+                    self::TABLE_NAME,
+                    ['product_id', 'active']
+                );
+            }
+
+            if (!$this->indexExists('idx_p1c_class_dyn_parent_id')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_parent_id',
+                    self::TABLE_NAME,
+                    'parent_id'
+                );
+            }
 
             // Covering index для исторических запросов по датам
             // Оптимизирует: WHERE product_id = ? AND date_from <= ? AND date_to >= ?
-            $this->createIndex(
-                'idx_p1c_class_dyn_product_dates',
-                self::TABLE_NAME,
-                ['product_id', 'date_from', 'date_to']
-            );
+            if (!$this->indexExists('idx_p1c_class_dyn_product_dates')) {
+                $this->createIndex(
+                    'idx_p1c_class_dyn_product_dates',
+                    self::TABLE_NAME,
+                    ['product_id', 'date_from', 'date_to']
+                );
+            }
 
             // Partial unique index: только одна активная запись на товар
-            $this->execute("
-                CREATE UNIQUE INDEX idx_p1c_class_dyn_product_active_unique
-                ON " . self::TABLE_NAME . " (product_id)
-                WHERE active = 1
-            ");
+            if (!$this->indexExists('idx_p1c_class_dyn_product_active_unique')) {
+                $this->execute("
+                    CREATE UNIQUE INDEX idx_p1c_class_dyn_product_active_unique
+                    ON " . self::TABLE_NAME . " (product_id)
+                    WHERE active = 1
+                ");
+            }
 
             // Комментарий к таблице
             $this->execute("COMMENT ON TABLE " . self::TABLE_NAME . " IS 'Версионированный каталог товаров с классификацией (SCD Type 2)'");
@@ -120,4 +136,13 @@ class m250123_100000_create_table_products_1c_class_dynamic extends Migration
             $this->dropTable(self::TABLE_NAME);
         }
     }
+
+    private function indexExists(string $indexName): bool
+    {
+        $result = $this->db->createCommand(
+            "SELECT 1 FROM pg_indexes WHERE indexname = :name"
+        )->bindValue(':name', $indexName)->queryScalar();
+
+        return $result !== false;
+    }
 }
index d2094202e6317e4fa870e8a7cce2a8b8d8997f82..1f09a48cfc3f0afb4429194532c7744b45362165 100644 (file)
@@ -23,19 +23,23 @@ class m260127_105454_create_shift_reminder_shown_table extends Migration
         ]);
 
         // Создаем уникальный составной индекс для предотвращения дублирования напоминаний
-        $this->createIndex(
-            'idx-shift_reminder_shown-user_reminder_date',
-            self::TABLE_NAME,
-            ['user_id', 'reminder_key', 'reference_date'],
-            true
-        );
+        if (!$this->indexExists('idx-shift_reminder_shown-user_reminder_date')) {
+            $this->createIndex(
+                'idx-shift_reminder_shown-user_reminder_date',
+                self::TABLE_NAME,
+                ['user_id', 'reminder_key', 'reference_date'],
+                true
+            );
+        }
 
         // Создаем индекс для быстрого поиска по дате подтверждения
-        $this->createIndex(
-            'idx-shift_reminder_shown-confirmed_at',
-            self::TABLE_NAME,
-            'confirmed_at'
-        );
+        if (!$this->indexExists('idx-shift_reminder_shown-confirmed_at')) {
+            $this->createIndex(
+                'idx-shift_reminder_shown-confirmed_at',
+                self::TABLE_NAME,
+                'confirmed_at'
+            );
+        }
     }
 
     /**
@@ -45,4 +49,13 @@ class m260127_105454_create_shift_reminder_shown_table extends Migration
     {
         $this->dropTable(self::TABLE_NAME);
     }
+
+    private function indexExists(string $indexName): bool
+    {
+        $result = $this->db->createCommand(
+            "SELECT 1 FROM pg_indexes WHERE indexname = :name"
+        )->bindValue(':name', $indexName)->queryScalar();
+
+        return $result !== false;
+    }
 }
index dc97542da7d5a3d64ce5493cc7b6095a08aede1c..f9e5f8887acdb8b3bce42de1232f8101591d7f84 100644 (file)
@@ -29,33 +29,50 @@ class m260215_200000_create_upload_speed_tests_table extends Migration
             'created_at' => $this->timestamp()->notNull()->defaultExpression('CURRENT_TIMESTAMP')->comment('Дата и время теста'),
         ]);
 
-        $this->createIndex(
-            'idx-upload_speed_tests-admin_id',
-            self::TABLE_NAME,
-            'admin_id'
-        );
-
-        $this->createIndex(
-            'idx-upload_speed_tests-created_at',
-            self::TABLE_NAME,
-            'created_at'
-        );
-
-        $this->createIndex(
-            'idx-upload_speed_tests-ip',
-            self::TABLE_NAME,
-            'ip'
-        );
-
-        $this->createIndex(
-            'idx-upload_speed_tests-verdict',
-            self::TABLE_NAME,
-            'verdict'
-        );
+        if (!$this->indexExists('idx-upload_speed_tests-admin_id')) {
+            $this->createIndex(
+                'idx-upload_speed_tests-admin_id',
+                self::TABLE_NAME,
+                'admin_id'
+            );
+        }
+
+        if (!$this->indexExists('idx-upload_speed_tests-created_at')) {
+            $this->createIndex(
+                'idx-upload_speed_tests-created_at',
+                self::TABLE_NAME,
+                'created_at'
+            );
+        }
+
+        if (!$this->indexExists('idx-upload_speed_tests-ip')) {
+            $this->createIndex(
+                'idx-upload_speed_tests-ip',
+                self::TABLE_NAME,
+                'ip'
+            );
+        }
+
+        if (!$this->indexExists('idx-upload_speed_tests-verdict')) {
+            $this->createIndex(
+                'idx-upload_speed_tests-verdict',
+                self::TABLE_NAME,
+                'verdict'
+            );
+        }
     }
 
     public function safeDown()
     {
         $this->dropTable(self::TABLE_NAME);
     }
+
+    private function indexExists(string $indexName): bool
+    {
+        $result = $this->db->createCommand(
+            "SELECT 1 FROM pg_indexes WHERE indexname = :name"
+        )->bindValue(':name', $indexName)->queryScalar();
+
+        return $result !== false;
+    }
 }