-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbscheme.sql
93 lines (77 loc) · 2.72 KB
/
dbscheme.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
CREATE TABLE `armies` (
`ArmyID` mediumint(9) NOT NULL,
`OwnerID` mediumint(9) NOT NULL,
`Unit1qty` mediumint(9) NOT NULL,
`Unit2qty` mediumint(9) NOT NULL,
`Unit3qty` mediumint(9) NOT NULL,
`DestID` tinyint(4) NOT NULL,
`ETA` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `bases` (
`UserID` mediumint(9) NOT NULL,
`Level` tinyint(4) NOT NULL,
`BaseUnit1qty` mediumint(9) NOT NULL,
`BaseUnit2qty` mediumint(9) NOT NULL,
`BaseUnit3qty` mediumint(9) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `logs` (
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`EventID` smallint(6) NOT NULL,
`RelatedPlayers` varchar(3000) NOT NULL,
`RelatedPlanets` tinyint(4) NOT NULL,
`Description` varchar(3000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `planets` (
`PlanetID` tinyint(4) NOT NULL,
`OwnerID` mediumint(9) DEFAULT NULL,
`Unit1qty` mediumint(9) NOT NULL,
`Unit2qty` mediumint(9) NOT NULL,
`Unit3qty` mediumint(9) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `planets` (`PlanetID`, `OwnerID`, `Unit1qty`, `Unit2qty`, `Unit3qty`) VALUES
(1, NULL, 0, 0, 0),
(2, NULL, 0, 0, 0),
(3, NULL, 0, 0, 0),
(4, NULL, 0, 0, 0),
(5, NULL, 0, 0, 0),
(6, NULL, 0, 0, 0),
(7, NULL, 0, 0, 0),
(8, NULL, 0, 0, 0),
(9, NULL, 0, 0, 0),
(10, NULL, 0, 0, 0);
CREATE TABLE `users` (
`UserID` mediumint(9) NOT NULL,
`Username` varchar(30) NOT NULL,
`Password` char(128) NOT NULL,
`Email` varchar(60) NOT NULL,
`Gender` tinyint(1) NOT NULL,
`AvatarLoc` varchar(150) NOT NULL,
`Points` smallint(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `armies`
ADD PRIMARY KEY (`ArmyID`),
ADD KEY `OwnerID` (`OwnerID`);
ALTER TABLE `bases`
ADD KEY `UserID` (`UserID`);
ALTER TABLE `planets`
ADD PRIMARY KEY (`PlanetID`),
ADD KEY `OwnerID` (`OwnerID`);
ALTER TABLE `users`
ADD PRIMARY KEY (`UserID`);
ALTER TABLE `armies`
MODIFY `ArmyID` mediumint(9) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15;
ALTER TABLE `planets`
MODIFY `PlanetID` tinyint(4) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
ALTER TABLE `users`
MODIFY `UserID` mediumint(9) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=20;
ALTER TABLE `armies`
ADD CONSTRAINT `aownuser` FOREIGN KEY (`OwnerID`) REFERENCES `users` (`UserID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `bases`
ADD CONSTRAINT `bownuser` FOREIGN KEY (`UserID`) REFERENCES `users` (`UserID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `planets`
ADD CONSTRAINT `pownuser` FOREIGN KEY (`OwnerID`) REFERENCES `users` (`UserID`) ON DELETE SET NULL ON UPDATE CASCADE;
COMMIT;