This repository has been archived on 2024-07-18. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server/legacyworlds-server-data/db-structure/parts/data/100-universe-data.sql

96 lines
2.2 KiB
MySQL
Raw Normal View History

2018-10-23 09:38:02 +02:00
-- LegacyWorlds Beta 6
-- PostgreSQL database scripts
--
-- Stellar systems and planets
--
-- Copyright(C) 2004-2010, DeepClone Development
-- --------------------------------------------------------
--
-- Stellar systems
--
CREATE TABLE verse.systems(
id SERIAL NOT NULL PRIMARY KEY ,
x INT NOT NULL ,
y INT NOT NULL
);
CREATE UNIQUE INDEX idx_systems_coordinates
ON verse.systems( x , y );
--
-- Planets
--
CREATE TABLE verse.planets(
name_id INT NOT NULL PRIMARY KEY ,
system_id INT NOT NULL ,
orbit INT NOT NULL
CHECK( orbit BETWEEN 1 AND 5 ) ,
picture INT NOT NULL ,
2018-10-23 09:43:42 +02:00
population DOUBLE PRECISION NOT NULL
2018-10-23 09:38:02 +02:00
CHECK( population >= 0 )
);
CREATE UNIQUE INDEX idx_planets_coordinates
ON verse.planets( system_id , orbit );
ALTER TABLE verse.planets
ADD CONSTRAINT fk_planets_name
FOREIGN KEY (name_id) REFERENCES naming.map_names ,
ADD CONSTRAINT fk_planets_system
FOREIGN KEY (system_id) REFERENCES verse.systems;
--
-- Happiness
--
CREATE TABLE verse.planet_happiness(
planet_id INT NOT NULL PRIMARY KEY ,
2018-10-23 09:43:42 +02:00
target DOUBLE PRECISION NOT NULL
2018-10-23 09:38:02 +02:00
CHECK( target BETWEEN 0.0 AND 1.0 ) ,
2018-10-23 09:43:42 +02:00
current DOUBLE PRECISION NOT NULL
2018-10-23 09:38:02 +02:00
CHECK( current > 0 )
);
ALTER TABLE verse.planet_happiness
ADD CONSTRAINT fk_planethappiness_planet
FOREIGN KEY (planet_id) REFERENCES verse.planets;
--
-- Money
--
CREATE TABLE verse.planet_money(
planet_id INT NOT NULL PRIMARY KEY ,
2018-10-23 09:43:42 +02:00
income DOUBLE PRECISION NOT NULL
2018-10-23 09:38:02 +02:00
CHECK( income >= 0 ) ,
2018-10-23 09:43:42 +02:00
upkeep DOUBLE PRECISION NOT NULL
2018-10-23 09:38:02 +02:00
CHECK( upkeep >= 0 )
);
ALTER TABLE verse.planet_money
ADD CONSTRAINT fk_planetmoney_planet
FOREIGN KEY (planet_id) REFERENCES verse.planets;
--
-- Buildings
--
CREATE TABLE verse.planet_buildings(
planet_id INT NOT NULL ,
building_id INT NOT NULL ,
amount INT NOT NULL CHECK( amount >= 0 ) ,
2018-10-23 09:43:42 +02:00
damage DOUBLE PRECISION NOT NULL CHECK( damage >= 0 ) ,
2018-10-23 09:38:02 +02:00
PRIMARY KEY( planet_id , building_id )
);
CREATE INDEX idx_planetbuildings_building
ON verse.planet_buildings (building_id);
ALTER TABLE verse.planet_buildings
ADD CONSTRAINT fk_planetbuildings_planet
FOREIGN KEY (planet_id) REFERENCES verse.planets ,
ADD CONSTRAINT fk_planetbuildings_building
FOREIGN KEY (building_id) REFERENCES tech.buildings;