From 89f2aae40f954acb5f7b7c7162a5e71468096128 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tim.dijen@minbzk.nl>
Date: Mon, 22 Jul 2019 13:24:08 +0200
Subject: [PATCH] Use ALTER TABLE, or CREATE INDEX for SQLite instead (#1169)

---
 lib/SimpleSAML/Store/SQL.php | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/SimpleSAML/Store/SQL.php b/lib/SimpleSAML/Store/SQL.php
index 2be40ef89..82d68f66e 100644
--- a/lib/SimpleSAML/Store/SQL.php
+++ b/lib/SimpleSAML/Store/SQL.php
@@ -124,7 +124,9 @@ class SQL extends Store
                 'CREATE TABLE '.$this->prefix.
                 '_kvstore (_type VARCHAR(30) NOT NULL, _key VARCHAR(50) NOT NULL, _value '.$text_t.
                 ' NOT NULL, _expire TIMESTAMP, PRIMARY KEY (_key, _type))',
-                'CREATE INDEX '.$this->prefix.'_kvstore_expire ON '.$this->prefix.'_kvstore (_expire)'
+                $this->driver === 'sqlite' ?
+                'CREATE INDEX '.$this->prefix.'_kvstore_expire ON '.$this->prefix.'_kvstore (_expire)' :
+                'ALTER TABLE '.$this->prefix.'_kvstore ADD INDEX '.$this->prefix.'_kvstore_expire (_expire)'                 
             ],
             /**
              * This upgrade removes the default NOT NULL constraint on the _expire field in MySQL.
@@ -142,7 +144,9 @@ class SQL extends Store
                 'INSERT INTO '.$this->prefix.'_kvstore_new SELECT * FROM '.$this->prefix.'_kvstore',
                 'DROP TABLE '.$this->prefix.'_kvstore',
                 'ALTER TABLE '.$this->prefix.'_kvstore_new RENAME TO '.$this->prefix.'_kvstore',
-                'CREATE INDEX '.$this->prefix.'_kvstore_expire ON '.$this->prefix.'_kvstore (_expire)'
+                $this->driver === 'sqlite' ?
+                'CREATE INDEX '.$this->prefix.'_kvstore_expire ON '.$this->prefix.'_kvstore (_expire)' :
+                'ALTER TABLE '.$this->prefix.'_kvstore ADD INDEX '.$this->prefix.'_kvstore_expire (_expire)'                
             ]
         ];
 
-- 
GitLab