[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [FIX] Check if column already exist before update

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a7f23efa8b0_3819ff8c954e6@gitlab-sidekiq-low-urgency-cpu-bound-v2-7774c44f54-pxjq8.mail>

Victor Emanouilov pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
d07d74bc by ushindi bienvenu at 2026-08-14T14:10:39+00:00
[FIX] Check if column already exist before update
---
* [FIX] Check if column already exist before update

See merge request tikiwiki/tiki!10817

- - - - -


2 changed files:

- + installer/schema/20260525_increase_filename_len_in_pk_tiki.php
- − installer/schema/20260525_increase_filename_len_in_pk_tiki.sql


Changes:

=====================================
installer/schema/20260525_increase_filename_len_in_pk_tiki.php
=====================================
@@ -0,0 +1,52 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+use Tiki\Installer\Installer;
+
+/**
+ * Adds the filename_hash column to tiki_secdb and updates the primary key.
+ *
+ * Some instances may already contain this column if the migration was
+ * previously applied, so the schema change is performed only when needed.
+ *
+ * @param Installer $installer
+ *
+ * @return true
+ */
+function upgrade_20260525_increase_filename_len_in_pk_tiki(Installer $installer)
+{
+    global $dbs_tiki;
+
+    $exists = $installer->getOne(
+        "SELECT COUNT(*)
+        FROM INFORMATION_SCHEMA.COLUMNS
+        WHERE COLUMN_NAME = 'filename_hash'
+            AND TABLE_SCHEMA = '" . $dbs_tiki . "'
+            AND TABLE_NAME = 'tiki_secdb'"
+    );
+
+    if (! boolval($exists)) {
+        $installer->query("
+            ALTER TABLE `tiki_secdb`
+                ADD COLUMN `filename_hash` CHAR(32) NOT NULL DEFAULT '' AFTER `filename`
+        ");
+
+        $installer->query("
+            UPDATE `tiki_secdb`
+            SET `filename_hash` = MD5(`filename`)
+            WHERE `filename_hash` = ''
+        ");
+
+        $installer->query("
+            ALTER TABLE `tiki_secdb`
+                DROP PRIMARY KEY,
+                ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20))
+        ");
+    }
+
+    return true;
+}


=====================================
installer/schema/20260525_increase_filename_len_in_pk_tiki.sql deleted
=====================================
@@ -1,10 +0,0 @@
-ALTER TABLE `tiki_secdb`
-    ADD COLUMN `filename_hash` CHAR(32) NOT NULL DEFAULT '' AFTER `filename`;
-
-UPDATE `tiki_secdb`
-SET `filename_hash` = MD5(`filename`)
-WHERE `filename_hash` = '';
-
-ALTER TABLE `tiki_secdb`
-DROP PRIMARY KEY,
-ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20));
\ No newline at end of file



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d07d74bce0656818eba5d211cf0d7dc711190177

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d07d74bce0656818eba5d211cf0d7dc711190177
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.