Emmanuel BENOîT
4f083830f2
* Added table that will contain the cached technology dependencies. * Implemented trigger functions that update the cache and make sure there are no cycles or redundancies in the technology graph. * The following SQL files need to be (re-)executed: -> 030-data/080-techs.sql (for the defs.techdep_cache table) -> 040-functions/026-technology-dependencies.sql (new file)
49 lines
No EOL
2 KiB
PL/PgSQL
49 lines
No EOL
2 KiB
PL/PgSQL
/*
|
|
* Make sure that it is not possible to create cycles in dependencies.
|
|
*/
|
|
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( 3 , 'tech' );
|
|
|
|
-- Insert the technologies
|
|
INSERT INTO defs.technologies ( technology_name_id )
|
|
VALUES ( _get_string( 'tech1' ) ) ,
|
|
( _get_string( 'tech2' ) ) ,
|
|
( _get_string( 'tech3' ) );
|
|
|
|
-- ***** TESTS BEGIN HERE *****
|
|
SELECT plan( 3 );
|
|
|
|
SELECT diag_test_name( 'defs.technology_dependencies - Dependency from A to A is rejected' );
|
|
SELECT throws_ok( $$
|
|
INSERT INTO defs.technology_dependencies ( technology_name_id , technology_name_id_depends )
|
|
VALUES ( _get_string( 'tech1' ) , _get_string( 'tech1' ) );
|
|
$$ , 23514 );
|
|
|
|
SELECT diag_test_name( 'defs.technology_dependencies - Direct dependency from A to B to A is rejected' );
|
|
INSERT INTO defs.technology_dependencies ( technology_name_id , technology_name_id_depends )
|
|
VALUES ( _get_string( 'tech2' ) , _get_string( 'tech1' ) );
|
|
SELECT throws_ok( $$
|
|
INSERT INTO defs.technology_dependencies ( technology_name_id , technology_name_id_depends )
|
|
VALUES ( _get_string( 'tech1' ) , _get_string( 'tech2' ) );
|
|
$$ , 23514 );
|
|
|
|
SELECT diag_test_name( 'defs.technology_dependencies - Indirect dependency from A to B to A is rejected' );
|
|
INSERT INTO defs.technology_dependencies ( technology_name_id , technology_name_id_depends )
|
|
VALUES ( _get_string( 'tech3' ) , _get_string( 'tech2' ) );
|
|
SELECT throws_ok( $$
|
|
INSERT INTO defs.technology_dependencies ( technology_name_id , technology_name_id_depends )
|
|
VALUES ( _get_string( 'tech1' ) , _get_string( 'tech3' ) );
|
|
$$ , 23514 );
|
|
|
|
SELECT * FROM finish( );
|
|
ROLLBACK; |