diff --git a/patches/patch20200426-3.0.0/versioning.sql b/patches/patch20200426-3.0.0/versioning.sql index af42e4d11ad8aaf34a5e500a07426ee782cd5d2b..17e359f597d0376c2450740a9398a629f0e46ff2 100644 --- a/patches/patch20200426-3.0.0/versioning.sql +++ b/patches/patch20200426-3.0.0/versioning.sql @@ -34,7 +34,6 @@ CREATE TABLE entity_version ( _iversion INT UNSIGNED NOT NULL, _ipparent INT UNSIGNED NULL, srid VARBINARY(255) NOT NULL, - _is_head BOOLEAN DEFAULT FALSE, PRIMARY KEY (`entity_id`, `_iversion`), FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`) ON DELETE CASCADE, FOREIGN KEY (`srid`) REFERENCES `transactions` (`srid`), diff --git a/procedures/entityVersioning.sql b/procedures/entityVersioning.sql index ff83084a3645390cc71dd5f60436373844f9934e..f6d4665bcf09bfdcbc00a78604f5055d4d3ebb6e 100644 --- a/procedures/entityVersioning.sql +++ b/procedures/entityVersioning.sql @@ -57,18 +57,10 @@ BEGIN SET newiversion = 1; END IF; - -- remove old HEAD marker - UPDATE entity_version - SET _is_head = FALSE - WHERE entity_id = EntityID - AND _is_head IS TRUE; - - - -- insert new version with HEAD marker INSERT INTO entity_version - (entity_id, hash, version, _iversion, _ipparent, srid, _is_head) + (entity_id, hash, version, _iversion, _ipparent, srid) VALUES - (EntityID, Hash, Version, newiversion, newipparent, Transaction, TRUE); + (EntityID, Hash, Version, newiversion, newipparent, Transaction); @@ -129,19 +121,10 @@ CREATE FUNCTION db_2_0.get_head_version( RETURNS VARBINARY(255) READS SQL DATA BEGIN - RETURN ( - SELECT e.version - FROM entity_version AS e - WHERE e.entity_id = EntityID - AND e._is_head IS TRUE - ); + RETURN get_head_relative(EntityID, 0); END; // --- This implementation assumes that the distance from the head equals the --- difference between the _iversion numbers. This will not be correct anymore, --- as soon as branches may split and merge. Then, an tree-walk will be --- necessary, traversing the primary parents (_pparent), will be necessary. DROP FUNCTION IF EXISTS db_2_0.get_head_relative // CREATE FUNCTION db_2_0.get_head_relative( EntityID INT UNSIGNED, @@ -173,9 +156,6 @@ BEGIN ON ( c.srid = t.srid ) WHERE c.entity_id = EntityID AND c._ipparent is Null - -- TODO This first SELECT statement is necessary because the second one - -- does not return the root. However, this should be doable in one go with - -- a left join. -- retrieve branches UNION SELECT c.version AS child, diff --git a/tests/test_autotap.sql b/tests/test_autotap.sql index 8493609cabd266e979de3be9c91414d168292526..2be5ec6c246aa2593fe0315c87cbea1a32cf74aa 100644 --- a/tests/test_autotap.sql +++ b/tests/test_autotap.sql @@ -2216,7 +2216,7 @@ SELECT tap.table_collation_is('_caosdb_schema_unit_tests','entity_version','utf8 SELECT tap.table_engine_is('_caosdb_schema_unit_tests','entity_version','InnoDB',''); -- COLUMNS -SELECT tap.columns_are('_caosdb_schema_unit_tests','entity_version','`entity_id`,`hash`,`version`,`_iversion`,`_ipparent`,`srid`,`_is_head`',''); +SELECT tap.columns_are('_caosdb_schema_unit_tests','entity_version','`entity_id`,`hash`,`version`,`_iversion`,`_ipparent`,`srid`',''); -- COLUMN entity_version.entity_id @@ -2272,15 +2272,6 @@ SELECT tap.col_default_is('_caosdb_schema_unit_tests','entity_version','srid',NU SELECT tap.col_charset_is('_caosdb_schema_unit_tests','entity_version','srid',NULL,''); SELECT tap.col_collation_is('_caosdb_schema_unit_tests','entity_version','srid',NULL,''); --- COLUMN entity_version._is_head - -SELECT tap.has_column('_caosdb_schema_unit_tests','entity_version','_is_head',''); -SELECT tap.col_column_type_is('_caosdb_schema_unit_tests','entity_version','_is_head','tinyint(1)',''); -SELECT tap.col_extra_is('_caosdb_schema_unit_tests','entity_version','_is_head','',''); -SELECT tap.col_default_is('_caosdb_schema_unit_tests','entity_version','_is_head','0',''); -SELECT tap.col_charset_is('_caosdb_schema_unit_tests','entity_version','_is_head',NULL,''); -SELECT tap.col_collation_is('_caosdb_schema_unit_tests','entity_version','_is_head',NULL,''); - -- CONSTRAINTS SELECT tap.constraints_are('_caosdb_schema_unit_tests','entity_version','`entity_id`,`PRIMARY`,`entity_version_ibfk_1`,`entity_version_ibfk_2`',''); diff --git a/tests/test_entity_versioning.sql b/tests/test_entity_versioning.sql index a8084c97278bb6f5ba9b65114b0d86fe76df38e6..3c7c96e7c76b05f62b86cbef68f4e9399747e62b 100644 --- a/tests/test_entity_versioning.sql +++ b/tests/test_entity_versioning.sql @@ -30,7 +30,7 @@ SELECT count(*) INTO @x FROM entity_version; SELECT tap.eq(@x, 0, "no versions there yet"); CALL insert_single_child_version(@EntityID, "hashbla", "versionbla", NULL, "SRIDbla"); -SELECT _ipparent INTO @x from entity_version WHERE version="versionbla" AND _is_head IS TRUE; +SELECT _ipparent INTO @x from entity_version WHERE version="versionbla"; SELECT tap.eq(@x, NULL, "no parent for the first version"); -- add a second version @@ -38,10 +38,10 @@ SELECT count(*) INTO @x FROM entity_version; SELECT tap.eq(@x, 1, "one version there yet"); CALL insert_single_child_version(@EntityID, "hashblub", "versionblub", "versionbla", "SRIDblub"); -SELECT _ipparent INTO @x from entity_version WHERE version="versionblub" AND _is_head IS TRUE; +SELECT _ipparent INTO @x from entity_version WHERE version="versionblub"; SELECT tap.eq(@x, 1, "the original entity is the parent"); --- test error: parent does not exist +-- error: parent does not exist SELECT count(*) INTO @x FROM entity_version; SELECT tap.eq(@x, 2, "two version there yet"); @@ -89,10 +89,10 @@ CALL insertEntityProperty(0, @EntityID, 17, "null_data", NULL, NULL, SELECT count(*) INTO @x FROM entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, 1, "after insertEntity, a version is there."); -SELECT _iversion INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent is NULL AND _is_head IS TRUE; +SELECT _iversion INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent is NULL; SELECT tap.eq(@x, 1, "after insertEntity, the _iversion number is 1."); -SELECT _ipparent INTO @x from entity_version WHERE entity_id = @EntityID AND _is_head IS TRUE; +SELECT _ipparent INTO @x from entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, NULL, "no parent for the freshly inserted entity"); SELECT tap.eq(count(*), 0, "no entity in archive_entities before first update") FROM archive_entities; @@ -105,9 +105,9 @@ CALL updateEntity(@EntityID, "NewEntityName", "NewEntityDesc", "RECORD", NULL, N SELECT count(*) INTO @x FROM entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, 2, "after updateEntity, a second version is there."); -SELECT _iversion INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent = 1 AND _is_head IS TRUE; +SELECT _iversion INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent = 1; SELECT tap.eq(@x, 2, "after updateEntity, the _iversion number incremented."); -SELECT _ipparent INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent = 1 AND _is_head IS TRUE; +SELECT _ipparent INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent = 1; SELECT tap.eq(@x, 1, "after updateEntity, the _pparent points to the first version"); SELECT tap.eq(count(*), 1, "after updateEntity, one entity in archive_entities") @@ -152,12 +152,6 @@ CALL updateEntity(@EntityID, "EntityName", "EntityDesc", "RECORDTYPE", NULL, NUL SELECT count(*) INTO @x FROM entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, 3, "after 2nd updateEntity, a 3rd version is there."); -SELECT tap.eq(count(*), 1, "after 2nd updateEntity, a single HEAD version is there.") - FROM entity_version WHERE entity_id = @EntityID AND _is_head IS TRUE; - -SELECT tap.eq(count(*), 2, "after 2nd updateEntity, two non-HEAD versions are there.") - FROM entity_version WHERE entity_id = @EntityID AND _is_head IS FALSE; - SELECT _iversion INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent = 2; SELECT tap.eq(@x, 3, "after 2nd updateEntity, the _iversion number incremented again."); SELECT _ipparent INTO @x FROM entity_version WHERE entity_id = @EntityID and _iversion = 3;