diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index f907fe83762..6793a5043df 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -368,17 +368,22 @@ DROP TABLE IF EXISTS `library`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `library` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `author` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL, - `title` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL, - `content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL, - `category` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL, - `ckey` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, - `flagged` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `ckey` (`ckey`), - KEY `flagged` (`flagged`) -) ENGINE=InnoDB AUTO_INCREMENT=4537 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + `id` INT(11) NOT NULL AUTO_INCREMENT, + `author` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci', + `title` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci', + `content` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci', + `ckey` VARCHAR(32) NOT NULL COLLATE 'utf8mb4_unicode_ci', + `reports` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci', + `summary` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci', + `rating` DOUBLE NULL DEFAULT '0', + `raters` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci', + `primary_category` INT(11) NULL DEFAULT '0', + `secondary_category` INT(11) NOT NULL DEFAULT '0', + `tertiary_category` INT(11) NULL DEFAULT '0', + PRIMARY KEY (`id`) USING BTREE, + INDEX `ckey` (`ckey`) USING BTREE, + INDEX `flagged` (`reports`(1024)) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- diff --git a/SQL/updates/37-38.sql b/SQL/updates/37-38.sql index 1e9da93ad3f..645c1234a36 100644 --- a/SQL/updates/37-38.sql +++ b/SQL/updates/37-38.sql @@ -1,5 +1,26 @@ -# Updating DB from 37-38 -# Adds player.keybindings (longtext) ~dearmochi +# Updates DB from 37 to 38 -Sirryan2002 +# Creates new tables in preparation for library table conversion -# Add column to player -ALTER TABLE `player` ADD COLUMN `keybindings` LONGTEXT COLLATE 'utf8mb4_unicode_ci' DEFAULT NULL AFTER `colourblind_mode`; +#Renames old table +ALTER TABLE library RENAME TO library_old; + +# Create new table to track library books +CREATE TABLE `library` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `author` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci', + `title` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci', + `content` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci', + `ckey` VARCHAR(32) NULL DEFAULT '' COLLATE 'utf8mb4_unicode_ci', + `reports` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci', + `summary` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci', + `rating` DOUBLE NULL DEFAULT '0', + `raters` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci', + `primary_category` INT(11) NULL DEFAULT '0', + `secondary_category` INT(11) NOT NULL DEFAULT '0', + `tertiary_category` INT(11) NULL DEFAULT '0', + PRIMARY KEY (`id`) USING BTREE, + INDEX `ckey` (`ckey`) USING BTREE, + INDEX `flagged` (`reports`(1024)) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +# YOU MUST NOW RUN 38-39.py diff --git a/SQL/updates/38-39.py b/SQL/updates/38-39.py new file mode 100644 index 00000000000..3b8edbf2154 --- /dev/null +++ b/SQL/updates/38-39.py @@ -0,0 +1,130 @@ +# :wave: hello fellow contributors, this script is brought to you ad-free by -sirryan2002- +# In order to run this script on Windows, you need to make sure you have Python **3** installed. Tested on 3.10.4 +# In addition you must have the mysql-connector-python module installed (can be done through pip :D) +# if you do not have that module installed, you cannot run this script + +# To run this, supply the following args in a command shell +# python 38-39.py address username password database +# Example: +# python 38-39.py 127.0.0.1 sirryan2002 myubersecretdbpassword paradise_gamedb + +import json +import mysql.connector, argparse + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("address", help="MySQL server address (use localhost for the current computer)") + parser.add_argument("username", help="MySQL login username") + parser.add_argument("password", help="MySQL login password") + parser.add_argument("database", help="Database name") + + args = parser.parse_args() + db = mysql.connector.connect(host=args.address, user=args.username, passwd=args.password, db=args.database) + cursor = db.cursor() + print("Connected to {}".format(args.database)) + #A List of old categories names + the new id number they will be assigned + category_name_to_id_map = { + "Fiction": 1, + "Non-Fiction": 2, + "Adult": 0, #0 represents a "removed"/unused category that no longer will be included + "Reference": 16, + "Religion": 3, + } + + cursor.execute("SELECT id, author, title, content, category, ckey FROM library_old") + data = cursor.fetchall() + + print("Loaded {} rows from library table...".format(len(data))) + + new_rows = [] + print("Modifying Categories...") + for entry in data: + book_id = entry[0] + author = entry[1] + title = entry[2] + content = entry[3] + category = entry[4] + ckey = entry[5] + + update_entry = False + new_entry = [ + book_id, + author, + title, + content, + category, + ckey, + ] + if category not in category_name_to_id_map.keys(): + update_entry = True + new_entry[4] = 0 + print("Corrupted Category Detected: removing \"{}\"...".format(category)) + else: + for cat in category_name_to_id_map.keys(): + if cat == category: + update_entry = True + new_entry[4] = category_name_to_id_map[cat] + if update_entry: + new_rows.append(new_entry) + else: + print("ERROR: Book {} did not have its category changed".format(book_id)) + + print("Modifying Content...") + for entry in new_rows: + new_content = json.dumps([entry[3]]) + entry[3] = new_content + #here we're turning our content string into a JSON list + print("Modified Content...") + print("Vetting Book Titles & Contents...") + duplicate_books = 0 + programmatic_books = 0 + notitle_books = 0 + short_books = 0 + for entry in new_rows: + if "Print Job" in entry[2]: + print("Book {} had \"Print Job\" in title: removing record...".format(entry[0])) + notitle_books += 1 + new_rows.remove(entry) + continue + if "Standard Operating Procedure" in entry[2] or "