Emmanuel BENOîT
e50775ec76
* The main loader script has been updated to generate the list of files it needs to load automatically. As a consequence, files that contained manually-maintained lists of scripts have been removed, and definition directories have been renamed accordingly. * PostgreSQL extension loading and configuration has been moved to a separate script to be loaded automatically in the main transaction. * Data and function definition scripts that had the -data or -functions suffix have been renamed (the suffix is unnecessary). * Unit tests have been reorganised to follow the definition's structure. * Documentation has been improved
75 lines
No EOL
1.8 KiB
SQL
75 lines
No EOL
1.8 KiB
SQL
-- LegacyWorlds Beta 6
|
|
-- PostgreSQL database scripts
|
|
--
|
|
-- Buildings/ships definitions
|
|
--
|
|
-- Copyright(C) 2004-2010, DeepClone Development
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- "Buildables"
|
|
--
|
|
CREATE TABLE tech.buildables(
|
|
name_id INT NOT NULL PRIMARY KEY ,
|
|
description_id INT NOT NULL ,
|
|
cost INT NOT NULL CHECK( cost > 0 ) ,
|
|
work INT NOT NULL CHECK( work > 0 ) ,
|
|
upkeep INT NOT NULL CHECK( upkeep >= 0 )
|
|
);
|
|
|
|
CREATE INDEX idx_buildables_description
|
|
ON tech.buildables (description_id);
|
|
|
|
ALTER TABLE tech.buildables
|
|
ADD CONSTRAINT fk_buildables_name
|
|
FOREIGN KEY (name_id) REFERENCES defs.strings ,
|
|
ADD CONSTRAINT fk_buildables_description
|
|
FOREIGN KEY (description_id) REFERENCES defs.strings;
|
|
|
|
|
|
--
|
|
-- Requirements
|
|
--
|
|
CREATE TABLE tech.buildable_requirements(
|
|
buildable_id INT NOT NULL ,
|
|
level_id INT NOT NULL ,
|
|
PRIMARY KEY( buildable_id , level_id )
|
|
);
|
|
|
|
CREATE INDEX idx_buildablereqs_level
|
|
ON tech.buildable_requirements( level_id );
|
|
|
|
ALTER TABLE tech.buildable_requirements
|
|
ADD CONSTRAINT fk_buildablereqs_buildable
|
|
FOREIGN KEY (buildable_id) REFERENCES tech.buildables ,
|
|
ADD CONSTRAINT fk_buildablereqs_level
|
|
FOREIGN KEY (level_id) REFERENCES tech.levels;
|
|
|
|
|
|
--
|
|
-- Buildings
|
|
--
|
|
CREATE TABLE tech.buildings(
|
|
buildable_id INT NOT NULL PRIMARY KEY ,
|
|
workers INT NOT NULL CHECK( workers >= 0 ) ,
|
|
output_type building_output_type ,
|
|
output INT NOT NULL CHECK( output > 0 )
|
|
);
|
|
|
|
ALTER TABLE tech.buildings
|
|
ADD CONSTRAINT fk_buildings_buildable
|
|
FOREIGN KEY (buildable_id) REFERENCES tech.buildables;
|
|
|
|
--
|
|
-- Ships
|
|
--
|
|
CREATE TABLE tech.ships(
|
|
buildable_id INT NOT NULL PRIMARY KEY ,
|
|
flight_time INT NOT NULL CHECK( flight_time > 0 ) ,
|
|
power INT NOT NULL CHECK( power > 0 )
|
|
);
|
|
|
|
|
|
ALTER TABLE tech.ships
|
|
ADD CONSTRAINT fk_buildings_buildable
|
|
FOREIGN KEY (buildable_id) REFERENCES tech.buildables; |