From 06ae05f4f290c3424fa270de697f367fe4917033 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 10 May 2022 17:12:52 -0400 Subject: [PATCH] Updated DB Schema to include the beginnings of asset, contact, vendor and software related data --- database_updates.php | 28 ++++++- database_version.php | 2 +- db.sql | 170 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 196 insertions(+), 4 deletions(-) diff --git a/database_updates.php b/database_updates.php index 35aba49c..6af4f33f 100644 --- a/database_updates.php +++ b/database_updates.php @@ -241,11 +241,35 @@ if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.1'"); } - //if(CURRENT_DATABASE_VERSION == '0.1.1'){ + if(CURRENT_DATABASE_VERSION == '0.1.1'){ // Insert queries here required to update to DB version 0.1.2 + // Create Many to Many Relationship tables for Assets, Contacts, Software and Vendors + + mysqli_query($mysqli, "CREATE TABLE `asset_documents` (`asset_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`document_id`))"); + mysqli_query($mysqli, "CREATE TABLE `asset_logins` (`asset_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`login_id`))"); + mysqli_query($mysqli, "CREATE TABLE `asset_files` (`asset_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`file_id`))"); + + mysqli_query($mysqli, "CREATE TABLE `contact_documents` (`contact_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`document_id`))"); + mysqli_query($mysqli, "CREATE TABLE `contact_logins` (`contact_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`login_id`))"); + mysqli_query($mysqli, "CREATE TABLE `contact_files` (`contact_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`file_id`))"); + + mysqli_query($mysqli, "CREATE TABLE `software_documents` (`software_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`document_id`))"); + mysqli_query($mysqli, "CREATE TABLE `software_logins` (`software_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`login_id`))"); + mysqli_query($mysqli, "CREATE TABLE `software_files` (`software_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`file_id`))"); + + mysqli_query($mysqli, "CREATE TABLE `vendor_documents` (`vendor_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`document_id`))"); + mysqli_query($mysqli, "CREATE TABLE `vendor_logins` (`vendor_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`login_id`))"); + mysqli_query($mysqli, "CREATE TABLE `vendor_files` (`vendor_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`file_id`))"); // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.2'"); + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.2'"); + } + + //if(CURRENT_DATABASE_VERSION == '0.1.2'){ + // Insert queries here required to update to DB version 0.1.3 + + // Then, update the database to the next sequential version + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.3'"); //} // etc diff --git a/database_version.php b/database_version.php index ef50731c..f7cdb508 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.1.1"); \ No newline at end of file +DEFINE("LATEST_DATABASE_VERSION", "0.1.2"); \ No newline at end of file diff --git a/db.sql b/db.sql index 2cf318b2..6642a626 100644 --- a/db.sql +++ b/db.sql @@ -55,6 +55,48 @@ CREATE TABLE `api_keys` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `asset_documents` +-- + +DROP TABLE IF EXISTS `asset_documents`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `asset_documents` ( + `asset_id` int(11) NOT NULL, + `document_id` int(11) NOT NULL, + PRIMARY KEY (`asset_id`,`document_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `asset_files` +-- + +DROP TABLE IF EXISTS `asset_files`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `asset_files` ( + `asset_id` int(11) NOT NULL, + `file_id` int(11) NOT NULL, + PRIMARY KEY (`asset_id`,`file_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `asset_logins` +-- + +DROP TABLE IF EXISTS `asset_logins`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `asset_logins` ( + `asset_id` int(11) NOT NULL, + `login_id` int(11) NOT NULL, + PRIMARY KEY (`asset_id`,`login_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `assets` -- @@ -275,6 +317,48 @@ CREATE TABLE `companies` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `contact_documents` +-- + +DROP TABLE IF EXISTS `contact_documents`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `contact_documents` ( + `contact_id` int(11) NOT NULL, + `document_id` int(11) NOT NULL, + PRIMARY KEY (`contact_id`,`document_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `contact_files` +-- + +DROP TABLE IF EXISTS `contact_files`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `contact_files` ( + `contact_id` int(11) NOT NULL, + `file_id` int(11) NOT NULL, + PRIMARY KEY (`contact_id`,`file_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `contact_logins` +-- + +DROP TABLE IF EXISTS `contact_logins`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `contact_logins` ( + `contact_id` int(11) NOT NULL, + `login_id` int(11) NOT NULL, + PRIMARY KEY (`contact_id`,`login_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `contacts` -- @@ -1106,6 +1190,48 @@ CREATE TABLE `software_contacts` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `software_documents` +-- + +DROP TABLE IF EXISTS `software_documents`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `software_documents` ( + `software_id` int(11) NOT NULL, + `document_id` int(11) NOT NULL, + PRIMARY KEY (`software_id`,`document_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `software_files` +-- + +DROP TABLE IF EXISTS `software_files`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `software_files` ( + `software_id` int(11) NOT NULL, + `file_id` int(11) NOT NULL, + PRIMARY KEY (`software_id`,`file_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `software_logins` +-- + +DROP TABLE IF EXISTS `software_logins`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `software_logins` ( + `software_id` int(11) NOT NULL, + `login_id` int(11) NOT NULL, + PRIMARY KEY (`software_id`,`login_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `tags` -- @@ -1333,6 +1459,48 @@ CREATE TABLE `users` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `vendor_documents` +-- + +DROP TABLE IF EXISTS `vendor_documents`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `vendor_documents` ( + `vendor_id` int(11) NOT NULL, + `document_id` int(11) NOT NULL, + PRIMARY KEY (`vendor_id`,`document_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `vendor_files` +-- + +DROP TABLE IF EXISTS `vendor_files`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `vendor_files` ( + `vendor_id` int(11) NOT NULL, + `file_id` int(11) NOT NULL, + PRIMARY KEY (`vendor_id`,`file_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `vendor_logins` +-- + +DROP TABLE IF EXISTS `vendor_logins`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `vendor_logins` ( + `vendor_id` int(11) NOT NULL, + `login_id` int(11) NOT NULL, + PRIMARY KEY (`vendor_id`,`login_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `vendors` -- @@ -1375,4 +1543,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-07 20:50:30 +-- Dump completed on 2022-05-10 17:11:18