Convert database to use migrations

This commit is contained in:
The Magician 2024-11-25 17:13:50 +00:00
parent d2bc986506
commit cb78b86fa1
10 changed files with 131 additions and 77 deletions

View File

@ -5,13 +5,13 @@ dump:
mysqldump --user=root --password=$(shell pass show sevenkeys/mysql) sevenkeys >sevenkeys.sql mysqldump --user=root --password=$(shell pass show sevenkeys/mysql) sevenkeys >sevenkeys.sql
dev_create: 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: dev_rollback:
rm -rf cache/ 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: 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: prod_rollback:
rm -rf cache/ 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
);

View File

@ -1 +0,0 @@
DROP DATABASE IF EXISTS sevenkeys;