]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
правки по миграциям
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 14 May 2026 10:51:17 +0000 (13:51 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 14 May 2026 10:51:17 +0000 (13:51 +0300)
erp24/migrations/m260420_120000_create_audit_log_table.php
erp24/migrations/m260420_130000_create_assortment_tables.php
erp24/migrations/m260420_140000_create_product_scores_table.php
erp24/migrations/m260420_150000_create_store_product_ratings_table.php
erp24/migrations/m260422_100000_add_classification_fields_to_nomenclature.php
erp24/migrations/m260422_110000_add_catmanager_rbac.php
erp24/migrations/m260422_120000_create_product_concepts_table.php
erp24/migrations/m260506_120000_add_automark_rbac_permissions.php

index 7beaf9be203ca2b942774abed1c7d95157e9c63a..f9014be3426906e85d19a3ea5a4a588c01329a53 100644 (file)
@@ -12,7 +12,7 @@ use yii\db\Migration;
  */
 class m260420_120000_create_audit_log_table extends Migration
 {
-    private const TABLE = 'audit_log';
+    private const TABLE = 'erp24.audit_log';
 
     public function safeUp(): void
     {
@@ -22,7 +22,7 @@ class m260420_120000_create_audit_log_table extends Migration
 
         // Родительская таблица с партиционированием по дате
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log (
+            CREATE TABLE erp24.audit_log (
                 id          BIGSERIAL,
                 entity_type VARCHAR(100)  NOT NULL,
                 entity_id   TEXT,
@@ -39,63 +39,63 @@ class m260420_120000_create_audit_log_table extends Migration
 
         // Кварталы 2026
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2026_q1 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2026_q1 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2026-01-01') TO ('2026-04-01')
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2026_q2 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2026_q2 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2026-04-01') TO ('2026-07-01')
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2026_q3 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2026_q3 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2026-07-01') TO ('2026-10-01')
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2026_q4 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2026_q4 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2026-10-01') TO ('2027-01-01')
         SQL)->execute();
 
         // Кварталы 2027
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2027_q1 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2027_q1 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2027-01-01') TO ('2027-04-01')
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2027_q2 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2027_q2 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2027-04-01') TO ('2027-07-01')
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2027_q3 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2027_q3 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2027-07-01') TO ('2027-10-01')
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE TABLE audit_log_2027_q4 PARTITION OF audit_log
+            CREATE TABLE erp24.audit_log_2027_q4 PARTITION OF erp24.audit_log
                 FOR VALUES FROM ('2027-10-01') TO ('2028-01-01')
         SQL)->execute();
 
         // Индексы на родительской таблице — автоматически наследуются партициями в PG 11+
         $this->db->createCommand(<<<SQL
-            CREATE INDEX idx_audit_log_entity ON audit_log (entity_type, entity_id)
+            CREATE INDEX idx_audit_log_entity ON erp24.audit_log (entity_type, entity_id)
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE INDEX idx_audit_log_user ON audit_log (user_id)
+            CREATE INDEX idx_audit_log_user ON erp24.audit_log (user_id)
         SQL)->execute();
 
         $this->db->createCommand(<<<SQL
-            CREATE INDEX idx_audit_log_created ON audit_log (created_at)
+            CREATE INDEX idx_audit_log_created ON erp24.audit_log (created_at)
         SQL)->execute();
     }
 
     public function safeDown(): void
     {
         // Партиции удаляются каскадно вместе с родительской таблицей
-        $this->db->createCommand('DROP TABLE IF EXISTS audit_log CASCADE')->execute();
+        $this->db->createCommand('DROP TABLE IF EXISTS erp24.audit_log CASCADE')->execute();
     }
 }
index 7307dc5b52fdde9baa319eb22c896121f2bbf3ba..3a781b9ac5f9f6434b8dd411234f1c17236f26e6 100644 (file)
@@ -8,8 +8,8 @@ use yii\db\Migration;
  */
 class m260420_130000_create_assortment_tables extends Migration
 {
-    private const LABELS_TABLE     = 'assortment_labels';
-    private const ASSORTMENT_TABLE = 'product_assortment';
+    private const LABELS_TABLE     = 'erp24.assortment_labels';
+    private const ASSORTMENT_TABLE = 'erp24.product_assortment';
 
     public function safeUp(): void
     {
index 973656d48fb9c682c12dae9c96ee4558c2c85a6d..88c37fc6a6987b2e127a8ec3fc8aa088408eee13 100644 (file)
@@ -8,7 +8,7 @@ use yii\db\Migration;
  */
 class m260420_140000_create_product_scores_table extends Migration
 {
-    private const TABLE = 'product_scores';
+    private const TABLE = 'erp24.product_scores';
 
     public function safeUp(): void
     {
index 93a57e7d34918f11da7e7ef152495ad82561d421..2b3e6cac0651c059aa68ebda9f01f8a053638cf7 100644 (file)
@@ -8,7 +8,7 @@ use yii\db\Migration;
  */
 class m260420_150000_create_store_product_ratings_table extends Migration
 {
-    private const TABLE = 'store_product_ratings';
+    private const TABLE = 'erp24.store_product_ratings';
 
     public function safeUp(): void
     {
index a07587eddcc98b5e823f144acf6b24d1107aced9..1409b5464a991a90f69bee7bbee03fff44ee390f 100644 (file)
@@ -9,7 +9,7 @@ use yii\db\Migration;
  */
 class m260422_100000_add_classification_fields_to_nomenclature extends Migration
 {
-    private const TABLE = 'products_1c_nomenclature';
+    private const TABLE = 'erp24.products_1c_nomenclature';
     private const INDEX = 'idx_nomenclature_classification_status';
 
     public function safeUp(): void
index cc52f8ff6c4c37347697f9961d3fc3e21ba5c672..57fe5f5f8029908f9a5cf9e5020ba45aee449464 100644 (file)
@@ -38,12 +38,12 @@ class m260422_110000_add_catmanager_rbac extends Migration
     public function safeDown(): void
     {
         $toRemove = [self::PERM_VIEW, self::PERM_MANAGE];
-        $rows     = $this->db->createCommand('SELECT id, config FROM admin_group_rbac_config')->queryAll();
+        $rows     = $this->db->createCommand('SELECT id, config FROM erp24.admin_group_rbac_config')->queryAll();
 
         foreach ($rows as $row) {
             $perms   = array_filter(array_map('trim', explode(',', (string)$row['config'])));
             $cleaned = array_values(array_diff($perms, $toRemove));
-            $this->update('admin_group_rbac_config', ['config' => implode(',', $cleaned)], ['id' => $row['id']]);
+            $this->update('erp24.admin_group_rbac_config', ['config' => implode(',', $cleaned)], ['id' => $row['id']]);
         }
 
         \Yii::$app->cache->set('dirtyAuthSettings', true);
@@ -52,12 +52,12 @@ class m260422_110000_add_catmanager_rbac extends Migration
     private function upsertGroupPermissions(int $groupId, array $permissions): void
     {
         $existing = $this->db->createCommand(
-            'SELECT config FROM admin_group_rbac_config WHERE admin_group_id = :gid',
+            'SELECT config FROM erp24.admin_group_rbac_config WHERE admin_group_id = :gid',
             [':gid' => $groupId]
         )->queryScalar();
 
         if ($existing === false) {
-            $this->insert('admin_group_rbac_config', [
+            $this->insert('erp24.admin_group_rbac_config', [
                 'admin_group_id' => $groupId,
                 'config'         => implode(',', $permissions),
             ]);
@@ -65,7 +65,7 @@ class m260422_110000_add_catmanager_rbac extends Migration
             $current = array_filter(array_map('trim', explode(',', (string)$existing)));
             $merged  = array_values(array_unique(array_merge($current, $permissions)));
             $this->update(
-                'admin_group_rbac_config',
+                'erp24.admin_group_rbac_config',
                 ['config' => implode(',', $merged)],
                 ['admin_group_id' => $groupId]
             );
index 6ad898b7670fae88792615179df44d7b5f9352c9..097ba9bfc568bff8dbc255a142117794fb251fdb 100644 (file)
@@ -16,7 +16,7 @@ use yii\db\Migration;
  */
 class m260422_120000_create_product_concepts_table extends Migration
 {
-    private const TABLE = 'product_concepts';
+    private const TABLE = 'erp24.product_concepts';
 
     public function safeUp(): void
     {
index 4826414748a416cad9f3533701a6dc5cf986620e..94ca93929263b6c347a9d2cdfaa44e3c71b0d728 100644 (file)
@@ -28,7 +28,8 @@ class m260506_120000_add_automark_rbac_permissions extends Migration
         AdminGroup::GROUP_KIK_MANAGER, // 82
     ];
 
-    private const AUTOMARK_TABLE  = 'erp24.products_1c_automark_predictions';
+    private const RBAC_CONFIG_TABLE = 'erp24.admin_group_rbac_config';
+    private const AUTOMARK_TABLE    = 'erp24.products_1c_automark_predictions';
     private const COMPOUND_INDEX  = 'idx_automark_status_llm_verdict';
 
     public function safeUp(): void
@@ -64,7 +65,7 @@ class m260506_120000_add_automark_rbac_permissions extends Migration
     {
         foreach (self::TARGET_GROUP_IDS as $groupId) {
             $row = (new \yii\db\Query())
-                ->from('admin_group_rbac_config')
+                ->from(self::RBAC_CONFIG_TABLE)
                 ->where(['admin_group_id' => $groupId])
                 ->one();
 
@@ -76,13 +77,13 @@ class m260506_120000_add_automark_rbac_permissions extends Migration
                 }
                 $existing[] = self::PERMISSION;
                 $this->update(
-                    'admin_group_rbac_config',
+                    self::RBAC_CONFIG_TABLE,
                     ['config' => implode(',', $existing)],
                     ['admin_group_id' => $groupId]
                 );
                 echo "  Группа {$groupId}: добавлено разрешение " . self::PERMISSION . "\n";
             } else {
-                $this->insert('admin_group_rbac_config', [
+                $this->insert(self::RBAC_CONFIG_TABLE, [
                     'admin_group_id' => $groupId,
                     'config'         => self::PERMISSION,
                 ]);
@@ -95,7 +96,7 @@ class m260506_120000_add_automark_rbac_permissions extends Migration
     {
         foreach (self::TARGET_GROUP_IDS as $groupId) {
             $row = (new \yii\db\Query())
-                ->from('admin_group_rbac_config')
+                ->from(self::RBAC_CONFIG_TABLE)
                 ->where(['admin_group_id' => $groupId])
                 ->one();
 
@@ -109,10 +110,10 @@ class m260506_120000_add_automark_rbac_permissions extends Migration
             ));
 
             if ($filtered === []) {
-                $this->delete('admin_group_rbac_config', ['admin_group_id' => $groupId]);
+                $this->delete(self::RBAC_CONFIG_TABLE, ['admin_group_id' => $groupId]);
             } else {
                 $this->update(
-                    'admin_group_rbac_config',
+                    self::RBAC_CONFIG_TABLE,
                     ['config' => implode(',', $filtered)],
                     ['admin_group_id' => $groupId]
                 );