mirror of
https://github.com/correl/mtgsqlive.git
synced 2024-11-22 03:00:10 +00:00
MySQL Schema tweaking and isBuyABox added. (#46)
This commit is contained in:
parent
17461375b3
commit
2deb975e89
1 changed files with 33 additions and 27 deletions
|
@ -10,7 +10,7 @@ import time
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
version = "v4.6.0" # need to automate this
|
version = "v4.6.2" # need to automate this
|
||||||
|
|
||||||
|
|
||||||
def execute(input_file, output_file) -> None:
|
def execute(input_file, output_file) -> None:
|
||||||
|
@ -31,6 +31,7 @@ def execute(input_file, output_file) -> None:
|
||||||
"-- MTGJSON Version: {}".format(version),
|
"-- MTGJSON Version: {}".format(version),
|
||||||
"",
|
"",
|
||||||
"START TRANSACTION;",
|
"START TRANSACTION;",
|
||||||
|
"SET names 'utf8';",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
@ -118,11 +119,11 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"mtgoCode TEXT,",
|
"mtgoCode TEXT,",
|
||||||
"name TEXT,",
|
"name TEXT,",
|
||||||
"parentCode TEXT,",
|
"parentCode TEXT,",
|
||||||
"releaseDate TEXT,",
|
"releaseDate DATE NOT NULL,",
|
||||||
"tcgplayerGroupId INTEGER,",
|
"tcgplayerGroupId INTEGER,",
|
||||||
"totalSetSize INTEGER,",
|
"totalSetSize INTEGER,",
|
||||||
"type TEXT",
|
"type TEXT",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -148,6 +149,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isBuyABox INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isDateStamped INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isDateStamped INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
@ -202,7 +204,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"uuid VARCHAR(36) UNIQUE NOT NULL,",
|
"uuid VARCHAR(36) UNIQUE NOT NULL,",
|
||||||
"variations TEXT,",
|
"variations TEXT,",
|
||||||
"watermark TEXT",
|
"watermark TEXT",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -238,7 +240,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"types TEXT,",
|
"types TEXT,",
|
||||||
"uuid VARCHAR(36) NOT NULL,",
|
"uuid VARCHAR(36) NOT NULL,",
|
||||||
"watermark TEXT",
|
"watermark TEXT",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -250,7 +252,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"INDEX(setCode),",
|
"INDEX(setCode),",
|
||||||
"FOREIGN KEY (setCode) REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
"FOREIGN KEY (setCode) REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
"translation TEXT",
|
"translation TEXT",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -259,14 +261,14 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
"flavorText TEXT,",
|
"flavorText TEXT,",
|
||||||
"language TEXT,",
|
"language TEXT,",
|
||||||
"multiverseId TEXT,",
|
"multiverseId INTEGER,",
|
||||||
"name TEXT,",
|
"name TEXT,",
|
||||||
"text TEXT,",
|
"text TEXT,",
|
||||||
"type TEXT,",
|
"type TEXT,",
|
||||||
"uuid VARCHAR(36),",
|
"uuid VARCHAR(36),",
|
||||||
"INDEX(uuid),",
|
"INDEX(uuid),",
|
||||||
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -278,7 +280,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"uuid VARCHAR(36),",
|
"uuid VARCHAR(36),",
|
||||||
"INDEX(uuid),",
|
"INDEX(uuid),",
|
||||||
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -290,7 +292,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"uuid VARCHAR(36),",
|
"uuid VARCHAR(36),",
|
||||||
"INDEX(uuid),",
|
"INDEX(uuid),",
|
||||||
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -303,7 +305,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"uuid VARCHAR(36),",
|
"uuid VARCHAR(36),",
|
||||||
"INDEX(uuid),",
|
"INDEX(uuid),",
|
||||||
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
@ -321,7 +323,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"mainBoard TEXT NOT NULL,",
|
"mainBoard TEXT NOT NULL,",
|
||||||
"sideBoard TEXT,",
|
"sideBoard TEXT,",
|
||||||
"type TEXT",
|
"type TEXT",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
]
|
]
|
||||||
|
@ -331,7 +333,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
"word TEXT UNIQUE NOT NULL,",
|
"word TEXT UNIQUE NOT NULL,",
|
||||||
"type TEXT NOT NULL",
|
"type TEXT NOT NULL",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
]
|
]
|
||||||
|
@ -342,13 +344,13 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"type TEXT UNIQUE NOT NULL,",
|
"type TEXT UNIQUE NOT NULL,",
|
||||||
"subTypes TEXT,",
|
"subTypes TEXT,",
|
||||||
"superTypes TEXT",
|
"superTypes TEXT",
|
||||||
");",
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
]
|
]
|
||||||
for q in schema.values():
|
for q in schema.values():
|
||||||
output_file["handle"].write("\n".join(q))
|
output_file["handle"].write("\n".join(q))
|
||||||
output_file["handle"].write("COMMIT;\n\nSTART TRANSACTION;\n")
|
output_file["handle"].write("COMMIT;\n\n")
|
||||||
else:
|
else:
|
||||||
schema = {
|
schema = {
|
||||||
"sets": [
|
"sets": [
|
||||||
|
@ -400,6 +402,7 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isBuyABox INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isDateStamped INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isDateStamped INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
@ -813,7 +816,7 @@ def handle_foreign_rows(
|
||||||
"uuid": card_uuid,
|
"uuid": card_uuid,
|
||||||
"flavorText": entry.get("flavorText", ""),
|
"flavorText": entry.get("flavorText", ""),
|
||||||
"language": entry.get("language", ""),
|
"language": entry.get("language", ""),
|
||||||
"multiverseId": entry.get("multiverseId", ""),
|
"multiverseId": entry.get("multiverseId", None),
|
||||||
"name": entry.get("name", ""),
|
"name": entry.get("name", ""),
|
||||||
"text": entry.get("text", ""),
|
"text": entry.get("text", ""),
|
||||||
"type": entry.get("type", ""),
|
"type": entry.get("type", ""),
|
||||||
|
@ -995,6 +998,19 @@ def modify_for_sql_insert(data: Any) -> Union[str, int, float, None]:
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def modify_for_sql_file(data: Any) -> Union[str, int, float, None]:
|
||||||
|
for key in data.keys():
|
||||||
|
if isinstance(data[key], str):
|
||||||
|
data[key] = (
|
||||||
|
"'" + data[key].replace("'", "''") + "'"
|
||||||
|
)
|
||||||
|
if str(data[key]) == "False":
|
||||||
|
data[key] = 0
|
||||||
|
if str(data[key]) == "True":
|
||||||
|
data[key] = 1
|
||||||
|
if data[key] is None:
|
||||||
|
data[key] = "NULL"
|
||||||
|
return data
|
||||||
|
|
||||||
def sql_dict_insert(data: Dict[str, Any], table: str, output_file: Dict) -> None:
|
def sql_dict_insert(data: Dict[str, Any], table: str, output_file: Dict) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -1005,17 +1021,7 @@ def sql_dict_insert(data: Dict[str, Any], table: str, output_file: Dict) -> None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if output_file["path"].suffix == ".sql":
|
if output_file["path"].suffix == ".sql":
|
||||||
for key in data.keys():
|
data = modify_for_sql_file(data)
|
||||||
if isinstance(data[key], str):
|
|
||||||
data[key] = (
|
|
||||||
"'" + data[key].replace("'", "''").replace('"', '""') + "'"
|
|
||||||
)
|
|
||||||
if str(data[key]) == "False":
|
|
||||||
data[key] = 0
|
|
||||||
if str(data[key]) == "True":
|
|
||||||
data[key] = 1
|
|
||||||
if data[key] is None:
|
|
||||||
data[key] = "NULL"
|
|
||||||
query = (
|
query = (
|
||||||
"INSERT INTO "
|
"INSERT INTO "
|
||||||
+ table
|
+ table
|
||||||
|
|
Loading…
Reference in a new issue