Empire resources in XML dumps
* Added dump view for empire resources * Added empire resource information storage class and associated row mapper * Integrated empire resource information into the summary generator
This commit is contained in:
parent
ce6d86d344
commit
9b346a80c2
9 changed files with 542 additions and 15 deletions
legacyworlds-server-data/db-structure
parts/040-functions
tests
admin/040-functions/200-bugs
user/040-functions/200-bugs
|
@ -1205,6 +1205,30 @@ CREATE VIEW bugs.dump_research_view
|
|||
GRANT SELECT ON bugs.dump_research_view TO :dbuser;
|
||||
|
||||
|
||||
/*
|
||||
* Empire resources view
|
||||
* ----------------------
|
||||
*
|
||||
* This view contains the details about empires' resources as they are needed
|
||||
* by the XML dump generator.
|
||||
*
|
||||
* Columns:
|
||||
* empire_id Identifier of the empire
|
||||
* resource_name Text-based identifier of the resource type
|
||||
* empres_possessed Amount of resources possessed by the empire
|
||||
* empres_owed Amount of resources owed by the empire
|
||||
*/
|
||||
DROP VIEW IF EXISTS bugs.dump_emp_resources_view CASCADE;
|
||||
CREATE VIEW bugs.dump_emp_resources_view
|
||||
AS SELECT empire_id , name AS resource_name , empres_possessed , empres_owed
|
||||
FROM emp.resources
|
||||
INNER JOIN defs.strings ON id = resource_name_id;
|
||||
|
||||
GRANT SELECT
|
||||
ON bugs.dump_emp_resources_view
|
||||
TO :dbuser;
|
||||
|
||||
|
||||
CREATE VIEW bugs.dump_planets_view
|
||||
AS SELECT ep.empire_id , ep.planet_id , p.population ,
|
||||
( ph.current / p.population )::REAL AS current_happiness , ph.target AS target_happiness ,
|
||||
|
@ -1248,6 +1272,7 @@ GRANT SELECT ON bugs.dump_planets_view TO :dbuser;
|
|||
* if there is no resource provider of that
|
||||
* type on the planet
|
||||
*/
|
||||
DROP VIEW IF EXISTS bugs.dump_planet_resources_view CASCADE;
|
||||
CREATE VIEW bugs.dump_planet_resources_view
|
||||
AS SELECT empire_id , planet_id ,
|
||||
name AS resource_name ,
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Tests for bugs.dump_emp_resources_view
|
||||
*/
|
||||
BEGIN;
|
||||
/*
|
||||
* We need a resource type, an empire and the associated resource record.
|
||||
*/
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
\i utils/universe.sql
|
||||
SELECT _create_resources( 1 , 'resource' );
|
||||
SELECT _create_emp_names( 1 , 'empire' );
|
||||
INSERT INTO emp.empires( name_id , cash )
|
||||
VALUES ( _get_emp_name( 'empire1' ) , 0 );
|
||||
INSERT INTO emp.resources(
|
||||
empire_id , resource_name_id , empres_possessed , empres_owed
|
||||
) VALUES (
|
||||
_get_emp_name( 'empire1' ) , _get_string( 'resource1' ) , 1 , 2
|
||||
);
|
||||
|
||||
|
||||
/***** TESTS BEGIN HERE *****/
|
||||
SELECT plan( 1 );
|
||||
|
||||
SELECT diag_test_name( 'bugs.dump_emp_resources_view - Contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT empire_id , resource_name , empres_possessed , empres_owed
|
||||
FROM bugs.dump_emp_resources_view
|
||||
$$ , $$ VALUES (
|
||||
_get_emp_name( 'empire1' ) , 'resource1' , 1 , 2
|
||||
) $$ );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Test privileges on bugs.dump_emp_resources_view
|
||||
*/
|
||||
BEGIN;
|
||||
SELECT plan( 1 );
|
||||
|
||||
SELECT diag_test_name( 'bugs.dump_emp_resources_view - Privileges' );
|
||||
SELECT lives_ok( 'SELECT * FROM bugs.dump_emp_resources_view' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
Reference in a new issue