CREATE TABLE moty_maestro (
	MaestroID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	Name CHAR(50) NOT NULL,
	Password CHAR(50) NOT NULL,
	Email CHAR(50) NOT NULL,
	AccountType INT UNSIGNED NOT NULL,
	AccountStatus INT UNSIGNED NOT NULL,
	UserCount INT UNSIGNED NOT NULL,
	AcceptClausesDateTime DATETIME NOT NULL,
	MaestroTestID INT UNSIGNED
);

CREATE TABLE moty_player (
	PlayerID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	Name CHAR(50) NOT NULL,
	EnterCode CHAR(6) NOT NULL,
	AccountType INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID)
);



CREATE TABLE moty_app (
	AppID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	AppName CHAR(40) NOT NULL,
	KoreanName CHAR(40) NOT NULL,
	AppType INT UNSIGNED NOT NULL,
	HowToPlay TEXT NOT NULL
);

CREATE TABLE moty_active_app (
	ActiveAppID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES moty_app(AppID)
);



CREATE TABLE moty_best_record (
	BestRecordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,
	PlayerID INT UNSIGNED NOT NULL,
	BestRecord FLOAT NOT NULL,
	RecordDateTime DATETIME NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES moty_app(AppID),
	FOREIGN KEY (UserID) REFERENCES moty_user(UserID)
);

CREATE TABLE moty_ranking (
	RankingID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,
	RankingType INT UNSIGNED NOT NULL,
	Rank INT UNSIGNED NOT NULL,
	PlayerID INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES moty_app(AppID),
	FOREIGN KEY (UserID) REFERENCES moty_user(UserID)
);
