mirror of
https://github.com/correl/mtgsqlive.git
synced 2024-11-24 19:19:53 +00:00
Added MySQL schema and isDateStamped column. (#44)
This commit is contained in:
parent
8eb31aa752
commit
17461375b3
1 changed files with 482 additions and 236 deletions
|
@ -30,7 +30,7 @@ def execute(input_file, output_file) -> None:
|
||||||
"-- ({})".format(str(time.strftime("%Y-%m-%d %H:%M:%S"))),
|
"-- ({})".format(str(time.strftime("%Y-%m-%d %H:%M:%S"))),
|
||||||
"-- MTGJSON Version: {}".format(version),
|
"-- MTGJSON Version: {}".format(version),
|
||||||
"",
|
"",
|
||||||
"BEGIN TRANSACTION;",
|
"START TRANSACTION;",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
@ -97,245 +97,491 @@ def build_sql_schema(output_file: Dict) -> None:
|
||||||
:param output_file: Output info dict
|
:param output_file: Output info dict
|
||||||
"""
|
"""
|
||||||
LOGGER.info("Building SQLite Schema")
|
LOGGER.info("Building SQLite Schema")
|
||||||
|
|
||||||
schema = {
|
|
||||||
"sets": [
|
|
||||||
"CREATE TABLE `sets` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"baseSetSize INTEGER,",
|
|
||||||
"block TEXT,",
|
|
||||||
"boosterV3 TEXT,",
|
|
||||||
"code TEXT UNIQUE NOT NULL,",
|
|
||||||
"codeV3 TEXT,",
|
|
||||||
"isFoilOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isForeignOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isPartialPreview INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"keyruneCode TEXT,",
|
|
||||||
"mcmId INTEGER,",
|
|
||||||
"mcmName TEXT,",
|
|
||||||
"meta TEXT,",
|
|
||||||
"mtgoCode TEXT,",
|
|
||||||
"name TEXT,",
|
|
||||||
"parentCode TEXT,",
|
|
||||||
"releaseDate TEXT,",
|
|
||||||
"tcgplayerGroupId INTEGER,",
|
|
||||||
"totalSetSize INTEGER,",
|
|
||||||
"type TEXT",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"cards": [
|
|
||||||
"CREATE TABLE `cards` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"artist TEXT,",
|
|
||||||
"borderColor TEXT,",
|
|
||||||
"colorIdentity TEXT,",
|
|
||||||
"colorIndicator TEXT,",
|
|
||||||
"colors TEXT,",
|
|
||||||
"convertedManaCost FLOAT,",
|
|
||||||
"duelDeck TEXT(1),",
|
|
||||||
"edhrecRank TEXT,",
|
|
||||||
"faceConvertedManaCost FLOAT,",
|
|
||||||
"flavorText TEXT,",
|
|
||||||
"frameEffect TEXT,",
|
|
||||||
"frameEffects TEXT,",
|
|
||||||
"frameVersion TEXT,",
|
|
||||||
"hand TEXT,",
|
|
||||||
"hasFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"hasNoDeckLimit INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isOversized INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isPaper INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isPromo INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isReprint INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isReserved INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isStarter INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isStorySpotlight INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isTextless INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"isTimeshifted INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"layout TEXT,",
|
|
||||||
"leadershipSkills TEXT,",
|
|
||||||
"life TEXT,",
|
|
||||||
"loyalty TEXT,",
|
|
||||||
"manaCost TEXT,",
|
|
||||||
"mcmId INTEGER,",
|
|
||||||
"mcmMetaId INTEGER,",
|
|
||||||
"mcmName TEXT,",
|
|
||||||
"mtgArenaId INTEGER,",
|
|
||||||
"mtgoFoilId INTEGER,",
|
|
||||||
"mtgoId INTEGER,",
|
|
||||||
"mtgstocksId INTEGER,",
|
|
||||||
"multiverseId INTEGER,",
|
|
||||||
"name TEXT,",
|
|
||||||
"names TEXT,",
|
|
||||||
"number TEXT,",
|
|
||||||
"originalText TEXT,",
|
|
||||||
"originalType TEXT,",
|
|
||||||
"otherFaceIds TEXT,",
|
|
||||||
"power TEXT,",
|
|
||||||
"printings TEXT,",
|
|
||||||
"purchaseUrls TEXT,",
|
|
||||||
"rarity TEXT,",
|
|
||||||
"scryfallId TEXT(36),",
|
|
||||||
"scryfallIllustrationId TEXT(36),",
|
|
||||||
"scryfallOracleId TEXT(36),",
|
|
||||||
"setCode TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
|
||||||
"side TEXT,",
|
|
||||||
"subtypes TEXT,",
|
|
||||||
"supertypes TEXT,",
|
|
||||||
"tcgplayerProductId INTEGER,",
|
|
||||||
"tcgplayerPurchaseUrl TEXT,",
|
|
||||||
"text TEXT,",
|
|
||||||
"toughness TEXT,",
|
|
||||||
"type TEXT,",
|
|
||||||
"types TEXT,",
|
|
||||||
"uuid TEXT(36) UNIQUE NOT NULL,",
|
|
||||||
"variations TEXT,",
|
|
||||||
"watermark TEXT",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"tokens": [
|
|
||||||
"CREATE TABLE `tokens` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"artist TEXT,",
|
|
||||||
"borderColor TEXT,",
|
|
||||||
"colorIdentity TEXT,",
|
|
||||||
"colorIndicator TEXT,",
|
|
||||||
"colors TEXT,",
|
|
||||||
"duelDeck TEXT(1),",
|
|
||||||
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
|
||||||
"layout TEXT,",
|
|
||||||
"loyalty TEXT,",
|
|
||||||
"name TEXT,",
|
|
||||||
"names TEXT,",
|
|
||||||
"number TEXT,",
|
|
||||||
"power TEXT,",
|
|
||||||
"reverseRelated TEXT,",
|
|
||||||
"scryfallId TEXT(36),",
|
|
||||||
"scryfallIllustrationId TEXT(36),",
|
|
||||||
"scryfallOracleId TEXT(36),",
|
|
||||||
"setCode TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
|
||||||
"side TEXT,",
|
|
||||||
"subtypes TEXT,",
|
|
||||||
"supertypes TEXT,",
|
|
||||||
"text TEXT,",
|
|
||||||
"toughness TEXT,",
|
|
||||||
"type TEXT,",
|
|
||||||
"types TEXT,",
|
|
||||||
"uuid TEXT(36) NOT NULL,",
|
|
||||||
"watermark TEXT",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"set_translations": [
|
|
||||||
"CREATE TABLE `set_translations` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"language TEXT,",
|
|
||||||
"setCode TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
|
||||||
"translation TEXT",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"foreign_data": [
|
|
||||||
"CREATE TABLE `foreign_data` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"flavorText TEXT,",
|
|
||||||
"language TEXT,",
|
|
||||||
"multiverseId INTEGER,",
|
|
||||||
"name TEXT,",
|
|
||||||
"text TEXT,",
|
|
||||||
"type TEXT,",
|
|
||||||
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"legalities": [
|
|
||||||
"CREATE TABLE `legalities` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"format TEXT,",
|
|
||||||
"status TEXT,",
|
|
||||||
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"rulings": [
|
|
||||||
"CREATE TABLE `rulings` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"date TEXT,",
|
|
||||||
"text TEXT,",
|
|
||||||
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
"prices": [
|
|
||||||
"CREATE TABLE `prices` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"date TEXT,",
|
|
||||||
"price REAL,",
|
|
||||||
"type TEXT,",
|
|
||||||
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
if output_file["useAllDeckFiles"]:
|
|
||||||
schema["decks"] = [
|
|
||||||
"CREATE TABLE `decks` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"code TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
|
||||||
"fileName TEXT UNIQUE NOT NULL,",
|
|
||||||
"name TEXT NOT NULL,",
|
|
||||||
"releaseDate TEXT,",
|
|
||||||
"mainBoard TEXT NOT NULL,",
|
|
||||||
"sideBoard TEXT,",
|
|
||||||
"type TEXT",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
]
|
|
||||||
if output_file["useKeywords"]:
|
|
||||||
schema["keywords"] = [
|
|
||||||
"CREATE TABLE `keywords` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"word TEXT UNIQUE NOT NULL,",
|
|
||||||
"type TEXT NOT NULL",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
]
|
|
||||||
if output_file["useCardTypes"]:
|
|
||||||
schema["types"] = [
|
|
||||||
"CREATE TABLE `types` (",
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
||||||
"type TEXT UNIQUE NOT NULL,",
|
|
||||||
"subTypes TEXT,",
|
|
||||||
"superTypes TEXT",
|
|
||||||
");",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Execute the commands
|
|
||||||
if output_file["path"].suffix == ".sql":
|
if output_file["path"].suffix == ".sql":
|
||||||
|
schema = {
|
||||||
|
"sets": [
|
||||||
|
"CREATE TABLE `sets` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"baseSetSize INTEGER,",
|
||||||
|
"block TEXT,",
|
||||||
|
"boosterV3 TEXT,",
|
||||||
|
"code VARCHAR(8) UNIQUE NOT NULL,",
|
||||||
|
"codeV3 TEXT,",
|
||||||
|
"isFoilOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isForeignOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isPartialPreview INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"keyruneCode TEXT,",
|
||||||
|
"mcmId INTEGER,",
|
||||||
|
"mcmName TEXT,",
|
||||||
|
"meta TEXT,",
|
||||||
|
"mtgoCode TEXT,",
|
||||||
|
"name TEXT,",
|
||||||
|
"parentCode TEXT,",
|
||||||
|
"releaseDate TEXT,",
|
||||||
|
"tcgplayerGroupId INTEGER,",
|
||||||
|
"totalSetSize INTEGER,",
|
||||||
|
"type TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"cards": [
|
||||||
|
"CREATE TABLE `cards` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"artist TEXT,",
|
||||||
|
"borderColor TEXT,",
|
||||||
|
"colorIdentity TEXT,",
|
||||||
|
"colorIndicator TEXT,",
|
||||||
|
"colors TEXT,",
|
||||||
|
"convertedManaCost FLOAT,",
|
||||||
|
"duelDeck TEXT(1),",
|
||||||
|
"edhrecRank TEXT,",
|
||||||
|
"faceConvertedManaCost FLOAT,",
|
||||||
|
"flavorText TEXT,",
|
||||||
|
"frameEffect TEXT,",
|
||||||
|
"frameEffects TEXT,",
|
||||||
|
"frameVersion TEXT,",
|
||||||
|
"hand TEXT,",
|
||||||
|
"hasFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"hasNoDeckLimit INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isDateStamped INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isOversized INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isPaper INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isPromo INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isReprint INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isReserved INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isStarter INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isStorySpotlight INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isTextless INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isTimeshifted INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"layout TEXT,",
|
||||||
|
"leadershipSkills TEXT,",
|
||||||
|
"life TEXT,",
|
||||||
|
"loyalty TEXT,",
|
||||||
|
"manaCost TEXT,",
|
||||||
|
"mcmId INTEGER,",
|
||||||
|
"mcmMetaId INTEGER,",
|
||||||
|
"mcmName TEXT,",
|
||||||
|
"mtgArenaId INTEGER,",
|
||||||
|
"mtgoFoilId INTEGER,",
|
||||||
|
"mtgoId INTEGER,",
|
||||||
|
"mtgstocksId INTEGER,",
|
||||||
|
"multiverseId INTEGER,",
|
||||||
|
"name TEXT,",
|
||||||
|
"names TEXT,",
|
||||||
|
"number TEXT,",
|
||||||
|
"originalText TEXT,",
|
||||||
|
"originalType TEXT,",
|
||||||
|
"otherFaceIds TEXT,",
|
||||||
|
"power TEXT,",
|
||||||
|
"printings TEXT,",
|
||||||
|
"purchaseUrls TEXT,",
|
||||||
|
"rarity TEXT,",
|
||||||
|
"scryfallId VARCHAR(36),",
|
||||||
|
"scryfallIllustrationId VARCHAR(36),",
|
||||||
|
"scryfallOracleId VARCHAR(36),",
|
||||||
|
"setCode VARCHAR(8),"
|
||||||
|
"INDEX(setCode),"
|
||||||
|
"FOREIGN KEY (setCode) REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"side TEXT,",
|
||||||
|
"subtypes TEXT,",
|
||||||
|
"supertypes TEXT,",
|
||||||
|
"tcgplayerProductId INTEGER,",
|
||||||
|
"tcgplayerPurchaseUrl TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"toughness TEXT,",
|
||||||
|
"type TEXT,",
|
||||||
|
"types TEXT,",
|
||||||
|
"uuid VARCHAR(36) UNIQUE NOT NULL,",
|
||||||
|
"variations TEXT,",
|
||||||
|
"watermark TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"tokens": [
|
||||||
|
"CREATE TABLE `tokens` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"artist TEXT,",
|
||||||
|
"borderColor TEXT,",
|
||||||
|
"colorIdentity TEXT,",
|
||||||
|
"colorIndicator TEXT,",
|
||||||
|
"colors TEXT,",
|
||||||
|
"duelDeck TEXT(1),",
|
||||||
|
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"layout TEXT,",
|
||||||
|
"loyalty TEXT,",
|
||||||
|
"name TEXT,",
|
||||||
|
"names TEXT,",
|
||||||
|
"number TEXT,",
|
||||||
|
"power TEXT,",
|
||||||
|
"reverseRelated TEXT,",
|
||||||
|
"scryfallId VARCHAR(36),",
|
||||||
|
"scryfallIllustrationId VARCHAR(36),",
|
||||||
|
"scryfallOracleId VARCHAR(36),",
|
||||||
|
"setCode VARCHAR(8),",
|
||||||
|
"INDEX(setCode),",
|
||||||
|
"FOREIGN KEY (setCode) REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"side TEXT,",
|
||||||
|
"subtypes TEXT,",
|
||||||
|
"supertypes TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"toughness TEXT,",
|
||||||
|
"type TEXT,",
|
||||||
|
"types TEXT,",
|
||||||
|
"uuid VARCHAR(36) NOT NULL,",
|
||||||
|
"watermark TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"set_translations": [
|
||||||
|
"CREATE TABLE `set_translations` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"language TEXT,",
|
||||||
|
"setCode VARCHAR(8),",
|
||||||
|
"INDEX(setCode),",
|
||||||
|
"FOREIGN KEY (setCode) REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"translation TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"foreign_data": [
|
||||||
|
"CREATE TABLE `foreign_data` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"flavorText TEXT,",
|
||||||
|
"language TEXT,",
|
||||||
|
"multiverseId TEXT,",
|
||||||
|
"name TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"type TEXT,",
|
||||||
|
"uuid VARCHAR(36),",
|
||||||
|
"INDEX(uuid),",
|
||||||
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"legalities": [
|
||||||
|
"CREATE TABLE `legalities` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"format TEXT,",
|
||||||
|
"status TEXT,",
|
||||||
|
"uuid VARCHAR(36),",
|
||||||
|
"INDEX(uuid),",
|
||||||
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"rulings": [
|
||||||
|
"CREATE TABLE `rulings` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"date TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"uuid VARCHAR(36),",
|
||||||
|
"INDEX(uuid),",
|
||||||
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"prices": [
|
||||||
|
"CREATE TABLE `prices` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"date TEXT,",
|
||||||
|
"price REAL,",
|
||||||
|
"type TEXT,",
|
||||||
|
"uuid VARCHAR(36),",
|
||||||
|
"INDEX(uuid),",
|
||||||
|
"FOREIGN KEY (uuid) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
if output_file["useAllDeckFiles"]:
|
||||||
|
schema["decks"] = [
|
||||||
|
"CREATE TABLE `decks` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"code VARCHAR(8),",
|
||||||
|
"INDEX(code),",
|
||||||
|
"FOREIGN KEY (code) REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"fileName TEXT UNIQUE NOT NULL,",
|
||||||
|
"name TEXT NOT NULL,",
|
||||||
|
"releaseDate TEXT,",
|
||||||
|
"mainBoard TEXT NOT NULL,",
|
||||||
|
"sideBoard TEXT,",
|
||||||
|
"type TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
if output_file["useKeywords"]:
|
||||||
|
schema["keywords"] = [
|
||||||
|
"CREATE TABLE `keywords` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"word TEXT UNIQUE NOT NULL,",
|
||||||
|
"type TEXT NOT NULL",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
if output_file["useCardTypes"]:
|
||||||
|
schema["types"] = [
|
||||||
|
"CREATE TABLE `types` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT,",
|
||||||
|
"type TEXT UNIQUE NOT NULL,",
|
||||||
|
"subTypes TEXT,",
|
||||||
|
"superTypes TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
]
|
||||||
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\nBEGIN TRANSACTION;\n")
|
output_file["handle"].write("COMMIT;\n\nSTART TRANSACTION;\n")
|
||||||
else:
|
else:
|
||||||
|
schema = {
|
||||||
|
"sets": [
|
||||||
|
"CREATE TABLE `sets` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"baseSetSize INTEGER,",
|
||||||
|
"block TEXT,",
|
||||||
|
"boosterV3 TEXT,",
|
||||||
|
"code TEXT UNIQUE NOT NULL,",
|
||||||
|
"codeV3 TEXT,",
|
||||||
|
"isFoilOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isForeignOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isPartialPreview INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"keyruneCode TEXT,",
|
||||||
|
"mcmId INTEGER,",
|
||||||
|
"mcmName TEXT,",
|
||||||
|
"meta TEXT,",
|
||||||
|
"mtgoCode TEXT,",
|
||||||
|
"name TEXT,",
|
||||||
|
"parentCode TEXT,",
|
||||||
|
"releaseDate TEXT,",
|
||||||
|
"tcgplayerGroupId INTEGER,",
|
||||||
|
"totalSetSize INTEGER,",
|
||||||
|
"type TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"cards": [
|
||||||
|
"CREATE TABLE `cards` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"artist TEXT,",
|
||||||
|
"borderColor TEXT,",
|
||||||
|
"colorIdentity TEXT,",
|
||||||
|
"colorIndicator TEXT,",
|
||||||
|
"colors TEXT,",
|
||||||
|
"convertedManaCost FLOAT,",
|
||||||
|
"duelDeck TEXT(1),",
|
||||||
|
"edhrecRank TEXT,",
|
||||||
|
"faceConvertedManaCost FLOAT,",
|
||||||
|
"flavorText TEXT,",
|
||||||
|
"frameEffect TEXT,",
|
||||||
|
"frameEffects TEXT,",
|
||||||
|
"frameVersion TEXT,",
|
||||||
|
"hand TEXT,",
|
||||||
|
"hasFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"hasNoDeckLimit INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"hasNonFoil INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isAlternative INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isArena INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isDateStamped INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isFullArt INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isMtgo INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isOversized INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isPaper INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isPromo INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isReprint INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isReserved INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isStarter INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isStorySpotlight INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isTextless INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"isTimeshifted INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"layout TEXT,",
|
||||||
|
"leadershipSkills TEXT,",
|
||||||
|
"life TEXT,",
|
||||||
|
"loyalty TEXT,",
|
||||||
|
"manaCost TEXT,",
|
||||||
|
"mcmId INTEGER,",
|
||||||
|
"mcmMetaId INTEGER,",
|
||||||
|
"mcmName TEXT,",
|
||||||
|
"mtgArenaId INTEGER,",
|
||||||
|
"mtgoFoilId INTEGER,",
|
||||||
|
"mtgoId INTEGER,",
|
||||||
|
"mtgstocksId INTEGER,",
|
||||||
|
"multiverseId INTEGER,",
|
||||||
|
"name TEXT,",
|
||||||
|
"names TEXT,",
|
||||||
|
"number TEXT,",
|
||||||
|
"originalText TEXT,",
|
||||||
|
"originalType TEXT,",
|
||||||
|
"otherFaceIds TEXT,",
|
||||||
|
"power TEXT,",
|
||||||
|
"printings TEXT,",
|
||||||
|
"purchaseUrls TEXT,",
|
||||||
|
"rarity TEXT,",
|
||||||
|
"scryfallId TEXT(36),",
|
||||||
|
"scryfallIllustrationId TEXT(36),",
|
||||||
|
"scryfallOracleId TEXT(36),",
|
||||||
|
"setCode TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"side TEXT,",
|
||||||
|
"subtypes TEXT,",
|
||||||
|
"supertypes TEXT,",
|
||||||
|
"tcgplayerProductId INTEGER,",
|
||||||
|
"tcgplayerPurchaseUrl TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"toughness TEXT,",
|
||||||
|
"type TEXT,",
|
||||||
|
"types TEXT,",
|
||||||
|
"uuid TEXT(36) UNIQUE NOT NULL,",
|
||||||
|
"variations TEXT,",
|
||||||
|
"watermark TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"tokens": [
|
||||||
|
"CREATE TABLE `tokens` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"artist TEXT,",
|
||||||
|
"borderColor TEXT,",
|
||||||
|
"colorIdentity TEXT,",
|
||||||
|
"colorIndicator TEXT,",
|
||||||
|
"colors TEXT,",
|
||||||
|
"duelDeck TEXT(1),",
|
||||||
|
"isOnlineOnly INTEGER NOT NULL DEFAULT 0,", # boolean
|
||||||
|
"layout TEXT,",
|
||||||
|
"loyalty TEXT,",
|
||||||
|
"name TEXT,",
|
||||||
|
"names TEXT,",
|
||||||
|
"number TEXT,",
|
||||||
|
"power TEXT,",
|
||||||
|
"reverseRelated TEXT,",
|
||||||
|
"scryfallId TEXT(36),",
|
||||||
|
"scryfallIllustrationId TEXT(36),",
|
||||||
|
"scryfallOracleId TEXT(36),",
|
||||||
|
"setCode TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"side TEXT,",
|
||||||
|
"subtypes TEXT,",
|
||||||
|
"supertypes TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"toughness TEXT,",
|
||||||
|
"type TEXT,",
|
||||||
|
"types TEXT,",
|
||||||
|
"uuid TEXT(36) NOT NULL,",
|
||||||
|
"watermark TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"set_translations": [
|
||||||
|
"CREATE TABLE `set_translations` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"language TEXT,",
|
||||||
|
"setCode TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"translation TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"foreign_data": [
|
||||||
|
"CREATE TABLE `foreign_data` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"flavorText TEXT,",
|
||||||
|
"language TEXT,",
|
||||||
|
"multiverseId INTEGER,",
|
||||||
|
"name TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"type TEXT,",
|
||||||
|
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"legalities": [
|
||||||
|
"CREATE TABLE `legalities` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"format TEXT,",
|
||||||
|
"status TEXT,",
|
||||||
|
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"rulings": [
|
||||||
|
"CREATE TABLE `rulings` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"date TEXT,",
|
||||||
|
"text TEXT,",
|
||||||
|
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
"prices": [
|
||||||
|
"CREATE TABLE `prices` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"date TEXT,",
|
||||||
|
"price REAL,",
|
||||||
|
"type TEXT,",
|
||||||
|
"uuid TEXT(36) REFERENCES cards(uuid) ON UPDATE CASCADE ON DELETE CASCADE",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
if output_file["useAllDeckFiles"]:
|
||||||
|
schema["decks"] = [
|
||||||
|
"CREATE TABLE `decks` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"code TEXT REFERENCES sets(code) ON UPDATE CASCADE ON DELETE CASCADE,",
|
||||||
|
"fileName TEXT UNIQUE NOT NULL,",
|
||||||
|
"name TEXT NOT NULL,",
|
||||||
|
"releaseDate TEXT,",
|
||||||
|
"mainBoard TEXT NOT NULL,",
|
||||||
|
"sideBoard TEXT,",
|
||||||
|
"type TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
if output_file["useKeywords"]:
|
||||||
|
schema["keywords"] = [
|
||||||
|
"CREATE TABLE `keywords` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"word TEXT UNIQUE NOT NULL,",
|
||||||
|
"type TEXT NOT NULL",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
if output_file["useCardTypes"]:
|
||||||
|
schema["types"] = [
|
||||||
|
"CREATE TABLE `types` (",
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
||||||
|
"type TEXT UNIQUE NOT NULL,",
|
||||||
|
"subTypes TEXT,",
|
||||||
|
"superTypes TEXT",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
]
|
||||||
cursor = output_file["handle"].cursor()
|
cursor = output_file["handle"].cursor()
|
||||||
for q in schema.values():
|
for q in schema.values():
|
||||||
cursor.execute("".join(q))
|
cursor.execute("".join(q))
|
||||||
|
|
Loading…
Reference in a new issue