diff PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 266:cc7af42d4f23

Store revisions for metadata and attachments in PostgreSQL
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Apr 2021 17:41:44 +0200
parents 29d2b76516f6
children 3a52e27a2d80
line wrap: on
line diff
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Tue Apr 20 16:14:04 2021 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Tue Apr 20 17:41:44 2021 +0200
@@ -276,6 +276,24 @@
                                                        "property INTEGER, value TEXT, PRIMARY KEY(server, property))");
         }
 
+        /**
+         * PostgreSQL 9.5: "Adding a column with a default requires
+         * updating each row of the table (to store the new column
+         * value). However, if no default is specified, PostgreSQL is
+         * able to avoid the physical update." => We set no default
+         * for performance (older entries will be NULL)
+         * https://www.postgresql.org/docs/9.5/ddl-alter.html
+         **/
+        if (!db.DoesColumnExist("Metadata", "revision"))
+        {
+          t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE Metadata ADD COLUMN revision INTEGER");
+        }
+
+        if (!db.DoesColumnExist("AttachedFiles", "revision"))
+        {
+          t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE AttachedFiles ADD COLUMN revision INTEGER");
+        }
+
         t.Commit();
       }
     }