Browse Source

Colonnes user.login et configuration.key rendues uniques

Simounet 2 years ago
parent
commit
51c6912ed2
4 changed files with 40 additions and 1 deletions
  1. 6 1
      Configuration.class.php
  2. 5 0
      MysqlEntity.class.php
  3. 5 0
      User.class.php
  4. 24 0
      updates/00008-unique-20160124.sql

+ 6 - 1
Configuration.class.php

@@ -14,10 +14,15 @@ class Configuration extends MysqlEntity{
     protected $object_fields =
     array(
         'id'=>'key',
-        'key'=>'longstring',
+        'key'=>'string',
         'value'=>'longstring'
     );
 
+    protected $object_fields_uniques =
+    array(
+        'key'
+    );
+
     function __construct(){
         parent::__construct();
     }

+ 5 - 0
MysqlEntity.class.php

@@ -135,6 +135,11 @@ class MysqlEntity
                 $query .= ',KEY `index'.$field.'` (`'.$field.'`)';
             }
         }
+        if (isset($this->object_fields_uniques)){
+            foreach($this->object_fields_uniques as $field){
+                $query .= ',UNIQUE `unique'.$field.'` (`'.$field.'`)';
+            }
+        }
         $query .= ')
         ENGINE InnoDB,
         DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

+ 5 - 0
User.class.php

@@ -23,6 +23,11 @@ class User extends MysqlEntity{
         'otpSecret'=>'string',
     );
 
+    protected $object_fields_uniques =
+    array(
+        'login'
+    );
+
     function __construct(){
         parent::__construct();
     }

+ 24 - 0
updates/00008-unique-20160124.sql

@@ -0,0 +1,24 @@
+--######################################################################################################
+--#####
+--#####     MISE À JOUR Base de données de Leed
+--#####			Date : 24/01/2017
+--#####			Version Leed : v1.7
+--#####
+--##### 		Feature(s) :
+--#####			- Rend unique le login d'un utilisateur
+--#####			- Le champ `key` des configurations est maintenant un varchar 255
+--#####			- Rend unique la colonne `key` des paramètres de configuration
+--#####
+--######################################################################################################
+
+-- Mise à jour table user
+ALTER TABLE `##MYSQL_PREFIX##user` ADD CONSTRAINT `uniquelogin` UNIQUE (login);
+
+ALTER TABLE `##MYSQL_PREFIX##configuration` MODIFY `key` VARCHAR(255) NOT NULL;
+CREATE TABLE `##MYSQL_PREFIX##configuration_new` LIKE `##MYSQL_PREFIX##configuration`;
+ALTER TABLE `##MYSQL_PREFIX##configuration_new` ADD UNIQUE `uniquekey` (`key`);
+INSERT INTO `##MYSQL_PREFIX##configuration_new`
+    SELECT * FROM `##MYSQL_PREFIX##configuration`
+        GROUP BY (`key`);
+RENAME TABLE `##MYSQL_PREFIX##configuration` TO `##MYSQL_PREFIX##configuration_old`, `##MYSQL_PREFIX##configuration_new` to `##MYSQL_PREFIX##configuration`;
+-- DROP TABLE `##MYSQL_PREFIX##configuration_old`;