Advertisement
Guest User

ej log rd

a guest
Oct 25th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 5.40 KB | None | 0 0
  1. CREATE TABLE Kerbal (
  2.   Id INT NOT NULL AUTO_INCREMENT,   -- every table needs an id field.  auto increment means it increases by one on every insert, so each row is unique
  3.   Name VARCHAR(50),
  4.   Gender VARCHAR(10),
  5.   Career VARCHAR(20),
  6.   Status VARCHAR(20),
  7.   Stupidity DECIMAL(2,3),
  8.   Bravery DECIMAL(2,3),
  9.   Badass TINYINT(1), -- i know KSP uses it, but not sure we need this
  10.   DefaultRoleId INT,
  11.   IsActive TINYINT(1) DEFAULT 1,                   -- these next 3 fields are what we call in the industry "audit" fields and will be on all tables
  12.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,  
  13.   CreatedBy VARCHAR(30),
  14.   PRIMARY KEY (Id)
  15. )
  16.  
  17. -- Having a roles table lets you manage roles and it lets Kerbals have different roles for different missions
  18. CREATE TABLE KerbalRole (
  19.   Id INT NOT NULL AUTO_INCREMENT,
  20.   Role VARCHAR(75),  -- Pilot, Commander, Payload specialist, whatever you want
  21.   IsActive TINYINT(1) DEFAULT 1,
  22.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  23.   CreatedBy VARCHAR(30),
  24.   PRIMARY KEY (Id)
  25. )
  26.  
  27. -- Entries are added for every mission.
  28. CREATE TABLE KerbalMission (
  29.   Id INT NOT NULL AUTO_INCREMENT,
  30.   KerbalId INT, -- points to kerbal
  31.   MissionId INT, -- points to mission
  32.   RoleId INT, -- points to whatever role that kerbal had for that mission
  33.   IsActive TINYINT(1) DEFAULT 1,
  34.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  35.   CreatedBy VARCHAR(30),
  36.   PRIMARY KEY (Id)
  37. )
  38.  
  39. -- add to this table every time a new vehicle or a revision is made
  40. CREATE TABLE Vehicle (
  41.   Id INT NOT NULL AUTO_INCREMENT,
  42.   Name VARCHAR(50),
  43.   Version VARCHAR(10),
  44.   DryMass DECIMAL(6,3),
  45.   WetMass DECIMAL(6,3),
  46.   PayloadCapacity DECIMAL(6,3),
  47.   BaseCost DECIMAL(12,3),
  48.   IsActive TINYINT(1) DEFAULT 1,
  49.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  50.   CreatedBy VARCHAR(30),
  51.   PRIMARY KEY (Id)
  52. )
  53.  
  54. -- A header table that is used to group Kerbals, Lifters/Vehicles, Launches
  55. CREATE TABLE Mission (
  56.   Id INT NOT NULL AUTO_INCREMENT,
  57.   MissionCategoryId INT, -- points to MissionCategory
  58.   FacilityId INT, -- points to Facility
  59.   VehicleId INT, -- points to Vehicle
  60.   Name VARCHAR(100),
  61.   METStart VARCHAR(50), -- tentative
  62.   METEnd VARCHAR(50), -- tentative
  63.   PayloadMass DECIMAL(6,3),
  64.   MissionOutcome VARCHAR(100),
  65.   GameTime DATETIME,
  66.   StreamTime DATETIME,
  67.   Notes VARCHAR(5000),
  68.   IsActive TINYINT(1) DEFAULT 1,
  69.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  70.   CreatedBy VARCHAR(30),
  71.   PRIMARY KEY (Id)
  72. )
  73.  
  74. -- A small list of categories.  Will be useful for users wanting to see all "rescue missions" or all "crew transfers"
  75. CREATE TABLE MissionCategory (
  76.   Id INT NOT NULL AUTO_INCREMENT,
  77.   Category VARCHAR(100), -- i.e. Rescue Mission, Resource Reconnaissance, Station Assembly,
  78.   IsActive TINYINT(1) DEFAULT 1,
  79.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  80.   CreatedBy VARCHAR(30),
  81.   PRIMARY KEY (Id)
  82. )
  83.  
  84. -- Will hold a growing list of facilities.  I.E: Crippen Station, Mun Base, Minmus Refinery, etc...
  85. CREATE TABLE Facility (
  86.   Id INT NOT NULL AUTO_INCREMENT,
  87.   Name VARCHAR(100),
  88.   PartCount INT, -- should be updated after every mission, or at least once complete
  89.   Location VARCHAR(50),  -- either orbital params or physical location
  90.   CompletionDate DATETIME, -- null if not complete.  Also, we'd know the start of the construction based on the gametime of the first mission to work on assembly
  91.   IsActive TINYINT(1) DEFAULT 1,
  92.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  93.   CreatedBy VARCHAR(30),
  94.   PRIMARY KEY (Id)
  95. )
  96.  
  97. -- holds Launch info for the mission.  Some missions may not have a launch and won't need an entry here (i.e. rover exploratory mission)
  98. CREATE TABLE Launch (
  99.   Id INT NOT NULL AUTO_INCREMENT,
  100.   MissionId INT NOT NULL, -- points to the mission
  101.   Apoapsis DECIMAL(9,3), -- in KM
  102.   Periapsis DECIMAL(9,3), -- in KM
  103.   Inclination DECIMAL(6,2), -- in degrees
  104.   Parameters VARCHAR(50), -- if user wants to provide a string instead of orbial params, i.e: Direct Duna Transfer
  105.   IsActive TINYINT(1) DEFAULT 1,
  106.   CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
  107.   CreatedBy VARCHAR(30),
  108.   PRIMARY KEY (Id)
  109. )
  110.  
  111.  
  112.  
  113. -- All that is pretty extensive, and right out the gate we probably won't utilize most of the functionality that
  114. -- this highly normalized table structure provides.  But setting it up like this now allows us to do some pretty
  115. -- cool future features to let the users slice and dice the data.
  116.  
  117. -- it's late and the syntax probably won't be akin to MySQL, but here are some examples
  118.  
  119. -- Want to know stats and mission count of all the Kerbals?
  120. SELECT
  121. k1.Name,
  122. k1.Gender,
  123. k1.Career,
  124. k1.Status,
  125. k1.Stupidity,
  126. k1.Bravery,
  127. K2.TotalMissionCount
  128. FROM Kerbals K1
  129. LEFT OUTER JOIN (SELECT COUNT(*) AS TotalMissionCount, KerbalId
  130.                 FROM KerbalMisson GROUP BY KerbalId
  131.                 WHERE IsActive = 1) K2 ON K2.KerbalId = K1.Id
  132.  
  133.                
  134.                
  135. -- Want to know all Kerbals involved in Crippen Station Construction and how many missions they were on?
  136. SELECT K.Name, COUNT(*) AS MissionCount,
  137. FROM Mission
  138. JOIN KerbalMission KM ON KM.MissionId = M.Id
  139. JOIN Kerbal K ON K.Id = KM.KerbalId
  140. WHERE MissionCategoryId = 5 -- assuming 5 = Construction
  141. AND FacilityId = 1 -- assuming 1 = Crippen station
  142. AND IsActive = 1
  143.  
  144.  
  145. -- Want to know every Mission Voyager has been on?
  146. SELECT M.Name, MC.Category, F.Name, M.GameTime
  147. FROM Mission M,
  148. LEFT OUTER JOIN MissionCategory MC ON MC.Id = M.MissionCategoryId
  149. LEFT OUTER JOIN Facilty F ON F.Id = M.FacilityId
  150. WHERE M.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement