Technology definitions loader

* Added "dummy" data file for technologies (for now it simply copies the
old, line-based technologies) and corresponding XML schema

* Added missing SQL stored procedure to clear all dependencies and
reverse dependencies from a technology

* Added import classes, loader and import tool for the technology graph

* Added tech graph import tool to post-build tests
This commit is contained in:
Emmanuel BENOîT 2012-02-27 20:04:02 +01:00
parent c5464212bc
commit 1f3c7a9202
24 changed files with 1731 additions and 43 deletions
legacyworlds-server-data/db-structure
parts/040-functions
tests
admin/040-functions/030-tech
user/040-functions/030-tech

View file

@ -324,6 +324,47 @@ GRANT EXECUTE
/*
* Remove all dependencies for a technology
* -----------------------------------------
*
* This stored procedure removes all dependencies and reverse dependencies for
* some technology.
*
* Parameters:
* _technology The name of the technology
*/
DROP FUNCTION IF EXISTS defs.techdep_clear( TEXT );
CREATE FUNCTION defs.techdep_clear( _technology TEXT )
RETURNS VOID
LANGUAGE SQL
STRICT VOLATILE
SECURITY DEFINER
AS $techdep_clear$
DELETE FROM defs.technology_dependencies
WHERE technology_name_id = (
SELECT id FROM defs.strings
WHERE name = $1
);
DELETE FROM defs.technology_dependencies
WHERE technology_name_id_depends = (
SELECT id FROM defs.strings
WHERE name = $1
);
$techdep_clear$;
REVOKE EXECUTE
ON FUNCTION defs.techdep_clear( TEXT )
FROM PUBLIC;
GRANT EXECUTE
ON FUNCTION defs.techdep_clear( TEXT )
TO :dbuser;
-- ********************************************************
-- OLD CODE BELOW
-- ********************************************************

View file

@ -0,0 +1,58 @@
/*
* Test the defs.techdep_clear() function
*/
BEGIN;
\i utils/strings.sql
-- Make the columns we don't use in the technology definition table NULL-able
ALTER TABLE defs.technologies
ALTER technology_category_id DROP NOT NULL ,
ALTER technology_discovery_id DROP NOT NULL ,
ALTER technology_description_id DROP NOT NULL ,
ALTER technology_price DROP NOT NULL ,
ALTER technology_points DROP NOT NULL;
-- Create strings to use as the technologies' names
SELECT _create_test_strings( 4 , 'tech' );
-- Insert the technologies
INSERT INTO defs.technologies ( technology_name_id )
VALUES ( _get_string( 'tech1' ) ) ,
( _get_string( 'tech2' ) ) ,
( _get_string( 'tech3' ) ) ,
( _get_string( 'tech4' ) );
-- Add a chain of dependencies
INSERT INTO defs.technology_dependencies(
technology_name_id , technology_name_id_depends
) VALUES ( _get_string( 'tech2' ) , _get_string( 'tech1' ) ) ,
( _get_string( 'tech3' ) , _get_string( 'tech2' ) ) ,
( _get_string( 'tech4' ) , _get_string( 'tech3' ) );
-- ***** TESTS BEGIN HERE *****
SELECT plan( 4 );
SELECT diag_test_name( 'defs.techdep_clear() - No failure on invalid technology name' );
SELECT lives_ok( $$
SELECT defs.techdep_clear( 'does not exist' )
$$ );
SELECT diag_test_name( 'defs.techdep_clear() - Successful call' );
SELECT lives_ok( $$
SELECT defs.techdep_clear( 'tech2' )
$$ );
SELECT diag_test_name( 'defs.techdep_clear() - Cleared technology has no dependencies' );
SELECT is_empty( $$
SELECT * FROM defs.technology_dependencies
WHERE technology_name_id = _get_string( 'tech2' );
$$ );
SELECT diag_test_name( 'defs.techdep_clear() - Cleared technology has no reverse dependencies' );
SELECT is_empty( $$
SELECT * FROM defs.technology_dependencies
WHERE technology_name_id_depends = _get_string( 'tech2' );
$$ );
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,13 @@
/*
* Test privileges on defs.techdep_remove()
*/
BEGIN;
SELECT plan( 1 );
SELECT diag_test_name( 'defs.techdep_clear() - EXECUTE privilege' );
SELECT lives_ok( $$
SELECT defs.techdep_clear( '' );
$$ );
SELECT * FROM finish( );
ROLLBACK;