Advertisement
Guest User

Untitled

a guest
Jul 18th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 6.22 KB | None | 0 0
  1. -- Some game objects have UUIDs, like players and worlds.
  2. -- Based on my research I store them as BINARY(16).
  3. -- I would like to use MySQL's UUID_TO_BIN functions but
  4. -- MariaDB doesn't support that. So use HEX/UNHEX and
  5. -- do the rest java-side.
  6.  
  7. -- "actions" are descriptive words that describe an event I log. "block-break", "item-drop", etc.
  8. -- actions are stored here only once so we can FK them
  9. -- I expect < 100 total
  10. CREATE TABLE `prism_actions` (
  11.   `action_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  12.   `action` varchar(25) NOT NULL,
  13.   PRIMARY KEY (`action_id`),
  14.   UNIQUE KEY `action` (`action`)
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  16.  
  17. -- this is the big guy
  18. -- "activities" are the actual log of game events. a game event is when a player does
  19. -- anything the server owner wants to track. we do this so server owners can track abuse.
  20. -- 90% of this table is foreign keys
  21. -- NOTE: I have not yet added any indexes for queries. Server OPs can search this data in many ways
  22. -- so it's difficult to make good indexes
  23. -- depending on how our users configure logging and purges this could store tens of millions of rows
  24. CREATE TABLE `prism_activities` (
  25.   `activity_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  26.   `timestamp` int(10) unsigned NOT NULL,
  27.   `world_id` tinyint(3) unsigned NOT NULL,
  28.   `x` int(11) NOT NULL,
  29.   `y` int(11) NOT NULL,
  30.   `z` int(11) NOT NULL,
  31.   `action_id` tinyint(3) unsigned NOT NULL,
  32.   `material_id` smallint(5) unsigned DEFAULT NULL,
  33.   `old_material_id` smallint(5) unsigned DEFAULT NULL,
  34.   `entity_type_id` smallint(5) unsigned DEFAULT NULL,
  35.   `cause_id` int(10) unsigned NOT NULL,
  36.   `descriptor` varchar(255) DEFAULT NULL,
  37.   PRIMARY KEY (`activity_id`),
  38.   KEY `actionId_idx` (`action_id`),
  39.   KEY `causeId_idx` (`cause_id`),
  40.   KEY `entityTypeId_idx` (`entity_type_id`),
  41.   KEY `materialId_idx` (`material_id`),
  42.   KEY `oldMaterialId_idx` (`old_material_id`),
  43.   KEY `worldId_idx` (`world_id`),
  44.   CONSTRAINT `actionId` FOREIGN KEY (`action_id`) REFERENCES `prism_actions` (`action_id`),
  45.   CONSTRAINT `causeId` FOREIGN KEY (`cause_id`) REFERENCES `prism_causes` (`cause_id`),
  46.   CONSTRAINT `entityTypeId` FOREIGN KEY (`entity_type_id`) REFERENCES `prism_entity_types` (`entity_type_id`),
  47.   CONSTRAINT `materialId` FOREIGN KEY (`material_id`) REFERENCES `prism_materials` (`material_id`),
  48.   CONSTRAINT `oldMaterialId` FOREIGN KEY (`old_material_id`) REFERENCES `prism_materials` (`material_id`),
  49.   CONSTRAINT `worldId` FOREIGN KEY (`world_id`) REFERENCES `prism_worlds` (`world_id`)
  50. ) ENGINE=InnoDB CHARSET=utf8mb4;
  51.  
  52. -- this table tracks optional extra/custom data for activities. the data is a serialized string.
  53. -- we don't always know which format something will be serialized as so it might be JSON, but could be a custom json-like format.
  54. CREATE TABLE `prism_activities_custom_data` (
  55.   `extra_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  56.   `activity_id` int(10) unsigned NOT NULL,
  57.   `version` smallint(6) DEFAULT NULL,
  58.   `data` text,
  59.   PRIMARY KEY (`extra_id`),
  60.   KEY `activityId_idx` (`activity_id`),
  61.   CONSTRAINT `activityId` FOREIGN KEY (`activity_id`) REFERENCES `prism_activities` (`activity_id`) ON DELETE CASCADE
  62. ) ENGINE=InnoDB CHARSET=utf8mb4;
  63.  
  64. -- "causes" are either a player or a named game object like a creature, explosion, etc.
  65. -- this table will usually have < 1000 rows but for busy servers could be < 100,000
  66. CREATE TABLE `prism_causes` (
  67.   `cause_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  68.   `cause` varchar(25) DEFAULT NULL,
  69.   `player_id` int(10) unsigned DEFAULT NULL,
  70.   PRIMARY KEY (`cause_id`),
  71.   UNIQUE KEY `cause` (`cause`),
  72.   KEY `playerId_idx` (`player_id`),
  73.   CONSTRAINT `playerId` FOREIGN KEY (`player_id`) REFERENCES `prism_players` (`player_id`)
  74. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  75.  
  76. -- "entities" is what Minecraft calls creatures. cows, zombies, etc.
  77. -- entities are stored here only once so we can FK them
  78. -- this table will probably have < 100,000 records
  79. CREATE TABLE `prism_entity_types` (
  80.   `entity_type_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  81.   `entity_type` varchar(45) DEFAULT NULL,
  82.   PRIMARY KEY (`entity_type_id`),
  83.   UNIQUE KEY `entityType` (`entity_type`)
  84. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  85.  
  86. -- "materials" refer to items and blocks. "material" is a base type and "data" is extra for variations.
  87. -- I'm debating storing these together as other databases can't do compound indexes as well
  88. -- and I'm not sure there's a reason to keep them separate.
  89. -- materials are stored here only once so we can FK them
  90. -- this table will probably have < 100,000 records
  91. CREATE TABLE `prism_materials` (
  92.   `material_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  93.   `material` varchar(45) DEFAULT NULL,
  94.   `data` varchar(155) DEFAULT NULL,
  95.   PRIMARY KEY (`material_id`),
  96.   UNIQUE KEY `materialData` (`material`,`data`)
  97. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  98.  
  99. -- simple table to store random plugin-used data like schema versions etc
  100. -- this table will be tiny, likely having like 20 records
  101. CREATE TABLE `prism_meta` (
  102.   `meta_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  103.   `k` varchar(25) NOT NULL,
  104.   `v` varchar(155) NOT NULL,
  105.   PRIMARY KEY (`meta_id`),
  106.   UNIQUE KEY `k` (`k`)
  107. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  108.  
  109. -- "players" refer to Minecraft players.
  110. -- The game gives players a UUID. Maybe I should be using that as the PK too and drop a column?
  111. -- this table will usually have < 1000 rows but for busy servers could be < 100,000
  112. CREATE TABLE `prism_players` (
  113.   `player_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  114.   `player` varchar(16) NOT NULL,
  115.   `player_uuid` binary(16) NOT NULL,
  116.   PRIMARY KEY (`player_id`),
  117.   UNIQUE KEY `player_uuid` (`player_uuid`),
  118.   KEY `player` (`player`,`player_uuid`)
  119. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  120.  
  121. -- "worlds" refer to game worlds, dimensions that players play in.
  122. -- the game gives worlds a UUID. Same PK comment here
  123. -- this table will be tiny, usually having < 5 records but maybe < 20 lifetime
  124. CREATE TABLE `prism_worlds` (
  125.   `world_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  126.   `world` varchar(255) NOT NULL,
  127.   `world_uuid` binary(16) NOT NULL,
  128.   PRIMARY KEY (`world_id`),
  129.   UNIQUE KEY `world_uuid` (`world_uuid`,`world`)
  130. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement