From: Aleksey Filippov Date: Tue, 17 Feb 2026 06:39:01 +0000 (+0300) Subject: Добавление логирования на загрузку файлов в документ списания. X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=7c0a719dfdedb7aec3779e01fed7f619ffe6ac71;p=erp24_rep%2Fyii-erp24%2F.git Добавление логирования на загрузку файлов в документ списания. --- diff --git a/erp24/migrations/m250123_100000_create_table_products_1c_class_dynamic.php b/erp24/migrations/m250123_100000_create_table_products_1c_class_dynamic.php index b6922555..f9d02414 100644 --- a/erp24/migrations/m250123_100000_create_table_products_1c_class_dynamic.php +++ b/erp24/migrations/m250123_100000_create_table_products_1c_class_dynamic.php @@ -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; + } } diff --git a/erp24/migrations/m260127_105454_create_shift_reminder_shown_table.php b/erp24/migrations/m260127_105454_create_shift_reminder_shown_table.php index d2094202..1f09a48c 100644 --- a/erp24/migrations/m260127_105454_create_shift_reminder_shown_table.php +++ b/erp24/migrations/m260127_105454_create_shift_reminder_shown_table.php @@ -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; + } } diff --git a/erp24/migrations/m260215_200000_create_upload_speed_tests_table.php b/erp24/migrations/m260215_200000_create_upload_speed_tests_table.php index dc97542d..f9e5f888 100644 --- a/erp24/migrations/m260215_200000_create_upload_speed_tests_table.php +++ b/erp24/migrations/m260215_200000_create_upload_speed_tests_table.php @@ -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; + } }