diff --git a/sevenkeys/Makefile b/sevenkeys/Makefile index ca57fd2..837e265 100644 --- a/sevenkeys/Makefile +++ b/sevenkeys/Makefile @@ -5,13 +5,13 @@ dump: mysqldump --user=root --password=$(shell pass show sevenkeys/mysql) sevenkeys >sevenkeys.sql dev_create: - goose mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys_development?parseTime=true" up + goose -dir database/migrations/ mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys_development?parseTime=true&multiStatements=true" up dev_rollback: rm -rf cache/ - goose mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys_development?parseTime=true" reset + goose -dir database/migrations/ mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys_development?parseTime=true&multiStatements=true" reset prod_create: - goose mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys?parseTime=true" up + goose -dir database/migrations/ mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys?parseTime=true&multiStatements=true" up prod_rollback: rm -rf cache/ - goose mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys?parseTime=true" reset + goose -dir database/migrations/ mysql "root:$(shell pass show sevenkeys/mysql)@/sevenkeys?parseTime=true&multiStatements=true" reset diff --git a/sevenkeys/database/migrations/00001_add_cachetimestamp_table.sql b/sevenkeys/database/migrations/00001_add_cachetimestamp_table.sql new file mode 100644 index 0000000..7e2422c --- /dev/null +++ b/sevenkeys/database/migrations/00001_add_cachetimestamp_table.sql @@ -0,0 +1,12 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS CacheTimestamp ( + CacheType ENUM('AllCardsBulkData') PRIMARY KEY, + Stamp DATETIME NOT NULL +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS CacheTimestamp; +-- +goose StatementEnd diff --git a/sevenkeys/database/migrations/00002_add_expansionset_table.sql b/sevenkeys/database/migrations/00002_add_expansionset_table.sql new file mode 100644 index 0000000..a3b778d --- /dev/null +++ b/sevenkeys/database/migrations/00002_add_expansionset_table.sql @@ -0,0 +1,14 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS ExpansionSet ( + SetCode VARCHAR(6) PRIMARY KEY, + Name VARCHAR(60) NOT NULL, + CardCount INT NOT NULL, + IconSvgUri VARCHAR(60) NOT NULL +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS ExpansionSet; +-- +goose StatementEnd diff --git a/sevenkeys/database/migrations/00003_add_cardprinting_table.sql b/sevenkeys/database/migrations/00003_add_cardprinting_table.sql new file mode 100644 index 0000000..8c03e63 --- /dev/null +++ b/sevenkeys/database/migrations/00003_add_cardprinting_table.sql @@ -0,0 +1,19 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS CardPrinting ( + Id VARCHAR(37) PRIMARY KEY, -- GUID, plus one character for foil/nonfoil + Name VARCHAR(150) NOT NULL, + SetCode VARCHAR(6) NOT NULL, + FOREIGN KEY (SetCode) REFERENCES ExpansionSet(SetCode), + IsFoil BOOLEAN NOT NULL, + IsPromo BOOLEAN NOT NULL, + CollectorNumber VARCHAR(10) NOT NULL, + ImageUrl VARCHAR(100) NOT NULL, + Language VARCHAR(3) NOT NULL +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS CardPrinting; +-- +goose StatementEnd diff --git a/sevenkeys/database/migrations/00004_add_storagearea_table.sql b/sevenkeys/database/migrations/00004_add_storagearea_table.sql new file mode 100644 index 0000000..8ac053a --- /dev/null +++ b/sevenkeys/database/migrations/00004_add_storagearea_table.sql @@ -0,0 +1,13 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS StorageArea ( + Id INT AUTO_INCREMENT PRIMARY KEY, + Name VARCHAR(100) NOT NULL, + StorageType ENUM('Binder', 'Box') +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS StorageArea; +-- +goose StatementEnd diff --git a/sevenkeys/database/migrations/00005_add_cardlocation_table.sql b/sevenkeys/database/migrations/00005_add_cardlocation_table.sql new file mode 100644 index 0000000..12134d3 --- /dev/null +++ b/sevenkeys/database/migrations/00005_add_cardlocation_table.sql @@ -0,0 +1,17 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS CardLocation ( + Id INT AUTO_INCREMENT PRIMARY KEY, + CardPrintingId VARCHAR(37) NULL, + FOREIGN KEY (CardPrintingId) REFERENCES CardPrinting(Id), + StorageAreaId INT NOT NULL, + FOREIGN KEY (StorageAreaId) REFERENCES StorageArea(Id), + Position INT NULL, + CardtraderProductId INT NULL +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS CardLocation; +-- +goose StatementEnd diff --git a/sevenkeys/database/migrations/00006_add_cardscan_table.sql b/sevenkeys/database/migrations/00006_add_cardscan_table.sql new file mode 100644 index 0000000..c2a0fab --- /dev/null +++ b/sevenkeys/database/migrations/00006_add_cardscan_table.sql @@ -0,0 +1,13 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS CardScan ( + Id INT PRIMARY KEY AUTO_INCREMENT, + CardLocationId INT NOT NULL, + Filename VARCHAR(100) NOT NULL +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS CardScan; +-- +goose StatementEnd diff --git a/sevenkeys/database/migrations/00007_add_scanned_card_placeholder.sql b/sevenkeys/database/migrations/00007_add_scanned_card_placeholder.sql new file mode 100644 index 0000000..60cc44b --- /dev/null +++ b/sevenkeys/database/migrations/00007_add_scanned_card_placeholder.sql @@ -0,0 +1,39 @@ +-- +goose Up +-- +goose StatementBegin +INSERT INTO ExpansionSet ( + SetCode, + Name, + CardCount, + IconSvgUri +) VALUES ( + 'null', + 'None', + 0, + '' +); + +INSERT INTO CardPrinting ( + Id, + Name, + SetCode, + IsFoil, + IsPromo, + CollectorNumber, + ImageUrl, + Language +) VALUES ( + '00000000-0000-0000-0000-0000000000000', + 'Scanned Card Placeholder', + 'null', + 0, + 0, + 0, + '', + 'en' +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DELETE FROM CardPrinting WHERE Id = '00000000-0000-0000-0000-0000000000000'; +-- +goose StatementEnd diff --git a/sevenkeys/database/sql/createdb.sql b/sevenkeys/database/sql/createdb.sql deleted file mode 100644 index ca2093d..0000000 --- a/sevenkeys/database/sql/createdb.sql +++ /dev/null @@ -1,72 +0,0 @@ -CREATE DATABASE IF NOT EXISTS sevenkeys; - -USE sevenkeys; - -CREATE TABLE IF NOT EXISTS CacheTimestamp ( - CacheType ENUM('AllCardsBulkData') PRIMARY KEY, - Stamp DATETIME NOT NULL -); - -CREATE TABLE IF NOT EXISTS ExpansionSet ( - SetCode VARCHAR(6) PRIMARY KEY, - Name VARCHAR(60) NOT NULL, - CardCount INT NOT NULL, - IconSvgUri VARCHAR(60) NOT NULL -); - -CREATE TABLE IF NOT EXISTS CardPrinting ( - Id VARCHAR(37) PRIMARY KEY, -- GUID, plus one character for foil/nonfoil - Name VARCHAR(150) NOT NULL, - SetCode VARCHAR(6) NOT NULL, - FOREIGN KEY (SetCode) REFERENCES ExpansionSet(SetCode), - IsFoil BOOLEAN NOT NULL, - IsPromo BOOLEAN NOT NULL, - CollectorNumber VARCHAR(10) NOT NULL, - ImageUrl VARCHAR(100) NOT NULL, - Language VARCHAR(3) NOT NULL -); - -/* -INSERT INTO CardPrinting ( - Id, - Name, - SetCode, - IsFoil, - IsPromo, - CollectorNumber, - ImageUrl, - Language -) VALUES ( - '00000000-0000-0000-0000-0000000000000', - 'Scanned Card Placeholder', - 'lea', - 0, - 0, - 0, - '', - 'en' -); -*/ - -CREATE TABLE IF NOT EXISTS StorageArea ( - Id INT AUTO_INCREMENT PRIMARY KEY, - Name VARCHAR(100) NOT NULL, - StorageType ENUM('Binder', 'Box') -); - -CREATE TABLE IF NOT EXISTS CardLocation ( - Id INT AUTO_INCREMENT PRIMARY KEY, - CardPrintingId VARCHAR(37) NULL, - FOREIGN KEY (CardPrintingId) REFERENCES CardPrinting(Id), - StorageAreaId INT NOT NULL, - FOREIGN KEY (StorageAreaId) REFERENCES StorageArea(Id), - Position INT NULL -); - -ALTER TABLE CardLocation ADD CardtraderProductId INT NULL; - -CREATE TABLE IF NOT EXISTS CardScan ( - Id INT PRIMARY KEY AUTO_INCREMENT, - CardLocationId INT NOT NULL, - Filename VARCHAR(100) NOT NULL -); diff --git a/sevenkeys/database/sql/removedb.sql b/sevenkeys/database/sql/removedb.sql deleted file mode 100644 index 6f0384c..0000000 --- a/sevenkeys/database/sql/removedb.sql +++ /dev/null @@ -1 +0,0 @@ -DROP DATABASE IF EXISTS sevenkeys;