From d96f01bc360ecde0e1c01b72bd8ad5899b4d5eb9 Mon Sep 17 00:00:00 2001
From: Sebastian Kehr <kehr@ub.uni-leipzig.de>
Date: Thu, 7 Nov 2019 09:52:06 +0100
Subject: [PATCH] refs #16234 [fid_adlr] changes in DB migration script

* drop column username_id after copying to username
* drop user_id_key unique key constraint
* set default values on columns firstname, lastname, cat_username
---
 .../migrateData_Vufind1ToVufind5_First_Adlr.sql  | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/module/fid_adlr/sql/migrations/mysql/migrateData_Vufind1ToVufind5_First_Adlr.sql b/module/fid_adlr/sql/migrations/mysql/migrateData_Vufind1ToVufind5_First_Adlr.sql
index 310d8c2e07d..d698e32089d 100644
--- a/module/fid_adlr/sql/migrations/mysql/migrateData_Vufind1ToVufind5_First_Adlr.sql
+++ b/module/fid_adlr/sql/migrations/mysql/migrateData_Vufind1ToVufind5_First_Adlr.sql
@@ -93,9 +93,21 @@ ALTER TABLE user
   MODIFY COLUMN expiry_date datetime NOT NULL DEFAULT '2000-01-01 00:00:00', 
   MODIFY COLUMN created datetime NOT NULL DEFAULT '2000-01-01 00:00:00';
 
+-- Drop unique key contraint involving columns "username" and "username_id"
+
+ALTER TABLE user DROP INDEX user_id_key;
+
+-- Fill column "username" with content of column "username_id" and set default values for columnls firstname, lastname, cat_username
+
+UPDATE user SET username=username_id,
+                firstname='',
+                lastname='',
+                cat_username=NULL;
+
 -- Drop columns which are not part of the vufind5 structure anymore
 
 ALTER TABLE user
+  DROP COLUMN username_id,
   DROP COLUMN liberoid,               
   DROP COLUMN attention,              
   DROP COLUMN business_phone,         
@@ -121,10 +133,6 @@ ALTER TABLE user
   DROP COLUMN bibid,                  
   DROP COLUMN updated;
 
--- Fill column "username" with content of column "id"
-
-UPDATE user SET username=id;
-
 -- Set the password columns to default values for all rows
 
 UPDATE user SET password='';
-- 
GitLab