Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-mysqlbackend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-mysqlbackend
Commits
6a3883be
Verified
Commit
6a3883be
authored
1 year ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: String IDs
parent
fd2317dd
No related branches found
No related tags found
3 merge requests
!17
Release 6.0
,
!15
External String IDs
,
!11
DRAFT: file system cleanup
Pipeline
#41298
failed
1 year ago
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_entity_versioning.sql
+73
-66
73 additions, 66 deletions
tests/test_entity_versioning.sql
tests/test_insert_update_delete.sql
+18
-15
18 additions, 15 deletions
tests/test_insert_update_delete.sql
tests/test_issues.sql
+12
-14
12 additions, 14 deletions
tests/test_issues.sql
with
103 additions
and
95 deletions
tests/test_entity_versioning.sql
+
73
−
66
View file @
6a3883be
...
@@ -34,6 +34,13 @@ CALL tap.no_plan();
...
@@ -34,6 +34,13 @@ CALL tap.no_plan();
-- SETUP
-- SETUP
SET
@
EntityID1
=
10001
;
SET
@
EntityID2
=
10002
;
SET
@
EntityID3
=
10003
;
SET
@
EntityID4
=
10004
;
SET
@
EntityID5
=
10005
;
SET
@
EntityID6
=
10006
;
-- Disable versioning because we want to test `insert_single_child_version`
-- Disable versioning because we want to test `insert_single_child_version`
-- separately from `insertEntity` but the former is called inside the latter
-- separately from `insertEntity` but the former is called inside the latter
-- when versioning is enabled.
-- when versioning is enabled.
...
@@ -46,22 +53,22 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
...
@@ -46,22 +53,22 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
(
"SRIDblieb"
,
3456
,
4576
,
"you"
,
"home"
);
(
"SRIDblieb"
,
3456
,
4576
,
"you"
,
"home"
);
DELETE
FROM
entities
WHERE
id
>
99
;
DELETE
FROM
entities
WHERE
id
>
99
;
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
insertEntity
(
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID1
,
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
SELECT
entity_id
INTO
@
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
SELECT
entity_id
INTO
@
Internal
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
-- TEST insert_single_child_version
-- TEST insert_single_child_version
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
tap
.
eq
(
@
x
,
0
,
"no versions there yet"
);
SELECT
tap
.
eq
(
@
x
,
0
,
"no versions there yet"
);
CALL
insert_single_child_version
(
@
EntityID
,
"hashbla"
,
"versionbla"
,
NULL
,
"SRIDbla"
);
CALL
insert_single_child_version
(
@
Internal
EntityID
,
"hashbla"
,
"versionbla"
,
NULL
,
"SRIDbla"
);
SELECT
_ipparent
INTO
@
x
from
entity_version
WHERE
version
=
"versionbla"
;
SELECT
_ipparent
INTO
@
x
from
entity_version
WHERE
version
=
"versionbla"
;
SELECT
tap
.
eq
(
@
x
,
NULL
,
"no parent for the first version"
);
SELECT
tap
.
eq
(
@
x
,
NULL
,
"no parent for the first version"
);
-- add a second version
-- add a second version
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
tap
.
eq
(
@
x
,
1
,
"one version there already"
);
SELECT
tap
.
eq
(
@
x
,
1
,
"one version there already"
);
CALL
insert_single_child_version
(
@
EntityID
,
"hashblub"
,
"versionblub"
,
"versionbla"
,
"SRIDblub"
);
CALL
insert_single_child_version
(
@
Internal
EntityID
,
"hashblub"
,
"versionblub"
,
"versionbla"
,
"SRIDblub"
);
SELECT
_ipparent
INTO
@
x
from
entity_version
WHERE
version
=
"versionblub"
;
SELECT
_ipparent
INTO
@
x
from
entity_version
WHERE
version
=
"versionblub"
;
SELECT
tap
.
eq
(
@
x
,
1
,
"the original entity is the parent"
);
SELECT
tap
.
eq
(
@
x
,
1
,
"the original entity is the parent"
);
...
@@ -72,7 +79,7 @@ SELECT tap.eq(@x, 2, "two versions there already");
...
@@ -72,7 +79,7 @@ SELECT tap.eq(@x, 2, "two versions there already");
CALL
tap
.
_assert_throws
(
CALL
tap
.
_assert_throws
(
concat
(
"CALL insert_single_child_version("
,
concat
(
"CALL insert_single_child_version("
,
@
EntityID
,
', "hashblieb", "versionblieb", "non-existing-parent", "SRIDBlieb")'
),
@
Internal
EntityID
,
', "hashblieb", "versionblieb", "non-existing-parent", "SRIDBlieb")'
),
"non existing parent throws"
);
"non existing parent throws"
);
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
...
@@ -80,15 +87,15 @@ SELECT tap.eq(@x, 2, "still two versions there");
...
@@ -80,15 +87,15 @@ SELECT tap.eq(@x, 2, "still two versions there");
-- TEST get_primary_parent_version
-- TEST get_primary_parent_version
SELECT
tap
.
eq
(
get_primary_parent_version
(
@
EntityID
,
"versionblub"
),
"versionbla"
,
"returns correct parent for versionblub"
);
SELECT
tap
.
eq
(
get_primary_parent_version
(
@
EntityID
1
,
"versionblub"
),
"versionbla"
,
"returns correct parent for versionblub"
);
SELECT
tap
.
eq
(
get_primary_parent_version
(
@
EntityID
,
"versionbla"
),
NULL
,
"versionbla has no parent"
);
SELECT
tap
.
eq
(
get_primary_parent_version
(
@
EntityID
1
,
"versionbla"
),
NULL
,
"versionbla has no parent"
);
-- TEST delete_all_entity_versions
-- TEST delete_all_entity_versions
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
tap
.
ok
(
@
x
>
0
,
"several versions in the table"
);
SELECT
tap
.
ok
(
@
x
>
0
,
"several versions in the table"
);
CALL
delete_all_entity_versions
(
@
EntityID
);
CALL
delete_all_entity_versions
(
@
EntityID
1
);
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
;
SELECT
tap
.
eq
(
@
x
,
0
,
"no versions there any more"
);
SELECT
tap
.
eq
(
@
x
,
0
,
"no versions there any more"
);
...
@@ -109,20 +116,20 @@ SELECT tap.eq(@x, 0, "before insertEntity, no versions there");
...
@@ -109,20 +116,20 @@ SELECT tap.eq(@x, 0, "before insertEntity, no versions there");
-- TEST insertEntity - should produce a version w/o parent
-- TEST insertEntity - should produce a version w/o parent
SET
@
SRID
=
"SRIDbla"
;
SET
@
SRID
=
"SRIDbla"
;
CALL
insertEntity
(
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID2
,
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
SELECT
entity_id
INTO
@
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
SELECT
entity_id
INTO
@
Internal
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
CALL
insertEntity
(
"ParentName"
,
"ParentDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID3
,
"ParentName"
,
"ParentDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
SELECT
entity_id
INTO
@
ParentID
FROM
name_data
WHERE
value
=
"ParentName"
;
SELECT
entity_id
INTO
@
ParentID
FROM
name_data
WHERE
value
=
"ParentName"
;
CALL
insertIsa
(
@
EntityID
,
@
Parent
ID
);
CALL
insertIsa
(
@
EntityID
2
,
@
Entity
ID
3
);
CALL
insertEntityProperty
(
0
,
@
EntityID
,
17
,
"null_data"
,
NULL
,
NULL
,
CALL
insertEntityProperty
(
0
,
@
EntityID
2
,
17
,
"null_data"
,
NULL
,
NULL
,
"RECOMMENDED"
,
NULL
,
"DescOverride"
,
NULL
,
NULL
,
0
);
"RECOMMENDED"
,
NULL
,
"DescOverride"
,
NULL
,
NULL
,
0
);
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
EntityID
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
;
SELECT
tap
.
eq
(
@
x
,
1
,
"after insertEntity, a version is there."
);
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
;
SELECT
_iversion
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
and
_ipparent
is
NULL
;
SELECT
tap
.
eq
(
@
x
,
1
,
"after insertEntity, the _iversion number is 1."
);
SELECT
tap
.
eq
(
@
x
,
1
,
"after insertEntity, the _iversion number is 1."
);
SELECT
_ipparent
INTO
@
x
from
entity_version
WHERE
entity_id
=
@
EntityID
;
SELECT
_ipparent
INTO
@
x
from
entity_version
WHERE
entity_id
=
@
Internal
EntityID
;
SELECT
tap
.
eq
(
@
x
,
NULL
,
"no parent for the freshly inserted entity"
);
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"
)
SELECT
tap
.
eq
(
count
(
*
),
0
,
"no entity in archive_entities before first update"
)
FROM
archive_entities
;
FROM
archive_entities
;
...
@@ -130,14 +137,14 @@ SELECT tap.eq(count(*), 0, "no entity in archive_entities before first update")
...
@@ -130,14 +137,14 @@ SELECT tap.eq(count(*), 0, "no entity in archive_entities before first update")
-- TEST updateEntity - should produce a version with a parent
-- TEST updateEntity - should produce a version with a parent
SET
@
SRID
=
"SRIDblub"
;
SET
@
SRID
=
"SRIDblub"
;
CALL
deleteEntityProperties
(
@
EntityID
);
CALL
deleteEntityProperties
(
@
EntityID
2
);
CALL
updateEntity
(
@
EntityID
,
"NewEntityName"
,
"NewEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl1}"
);
CALL
updateEntity
(
@
EntityID
2
,
"NewEntityName"
,
"NewEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl1}"
);
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
EntityID
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
;
SELECT
tap
.
eq
(
@
x
,
2
,
"after updateEntity, a second version is there."
);
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
;
SELECT
_iversion
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
and
_ipparent
=
1
;
SELECT
tap
.
eq
(
@
x
,
2
,
"after updateEntity, the _iversion number incremented."
);
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
;
SELECT
_ipparent
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
and
_ipparent
=
1
;
SELECT
tap
.
eq
(
@
x
,
1
,
"after updateEntity, the _pparent points to the first version"
);
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"
)
SELECT
tap
.
eq
(
count
(
*
),
1
,
"after updateEntity, one entity in archive_entities"
)
...
@@ -145,60 +152,60 @@ SELECT tap.eq(count(*), 1, "after updateEntity, one entity in archive_entities")
...
@@ -145,60 +152,60 @@ SELECT tap.eq(count(*), 1, "after updateEntity, one entity in archive_entities")
-- TEST get_version_history
-- TEST get_version_history
CALL
get_version_history
(
@
EntityID
);
CALL
get_version_history
(
@
EntityID
2
);
-- TEST retrieveEntity
-- TEST retrieveEntity
SELECT
version
INTO
@
x
FROM
entity_version
SELECT
version
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
EntityID
WHERE
entity_id
=
@
Internal
EntityID
AND
_iversion
=
2
;
AND
_iversion
=
2
;
CALL
retrieveEntity
(
@
EntityID
,
NULL
);
CALL
retrieveEntity
(
@
EntityID
2
,
NULL
);
CALL
retrieveEntity
(
@
EntityID
,
"non-existing-version"
);
CALL
retrieveEntity
(
@
EntityID
2
,
"non-existing-version"
);
CALL
retrieveEntity
(
@
EntityID
,
get_head_version
(
@
EntityID
));
CALL
retrieveEntity
(
@
EntityID
2
,
get_head_version
(
@
EntityID
2
));
CALL
retrieveEntity
(
@
EntityID
,
@
x
);
CALL
retrieveEntity
(
@
EntityID
2
,
@
x
);
-- TEST retrieveEntityParents
-- TEST retrieveEntityParents
CALL
retrieveEntityParents
(
@
EntityID
,
NULL
);
CALL
retrieveEntityParents
(
@
EntityID
2
,
NULL
);
CALL
retrieveEntityParents
(
@
EntityID
,
"non-existing-version"
);
CALL
retrieveEntityParents
(
@
EntityID
2
,
"non-existing-version"
);
CALL
retrieveEntityParents
(
@
EntityID
,
get_head_version
(
@
EntityID
));
CALL
retrieveEntityParents
(
@
EntityID
2
,
get_head_version
(
@
EntityID
2
));
CALL
retrieveEntityParents
(
@
EntityID
,
@
x
);
CALL
retrieveEntityParents
(
@
EntityID
2
,
@
x
);
-- TEST retrieveEntityProperties
-- TEST retrieveEntityProperties
CALL
retrieveEntityProperties
(
0
,
@
EntityID
,
NULL
);
CALL
retrieveEntityProperties
(
0
,
@
EntityID
2
,
NULL
);
CALL
retrieveEntityProperties
(
0
,
@
EntityID
,
"non-existing-version"
);
CALL
retrieveEntityProperties
(
0
,
@
EntityID
2
,
"non-existing-version"
);
CALL
retrieveEntityProperties
(
0
,
@
EntityID
,
get_head_version
(
@
EntityID
));
CALL
retrieveEntityProperties
(
0
,
@
EntityID
2
,
get_head_version
(
@
EntityID
2
));
CALL
retrieveEntityProperties
(
0
,
@
EntityID
,
@
x
);
CALL
retrieveEntityProperties
(
0
,
@
EntityID
2
,
@
x
);
-- TEST retrieveOverrides
-- TEST retrieveOverrides
CALL
retrieveOverrides
(
0
,
@
EntityID
,
NULL
);
CALL
retrieveOverrides
(
0
,
@
EntityID
2
,
NULL
);
CALL
retrieveOverrides
(
0
,
@
EntityID
,
"non-existing-version"
);
CALL
retrieveOverrides
(
0
,
@
EntityID
2
,
"non-existing-version"
);
CALL
retrieveOverrides
(
0
,
@
EntityID
,
get_head_version
(
@
EntityID
));
CALL
retrieveOverrides
(
0
,
@
EntityID
2
,
get_head_version
(
@
EntityID
2
));
CALL
retrieveOverrides
(
0
,
@
EntityID
,
@
x
);
CALL
retrieveOverrides
(
0
,
@
EntityID
2
,
@
x
);
-- and 2nd updateEntity
-- and 2nd updateEntity
SET
@
SRID
=
"SRIDblieb"
;
SET
@
SRID
=
"SRIDblieb"
;
CALL
updateEntity
(
@
EntityID
,
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
NULL
,
NULL
,
"{acl1}"
);
CALL
updateEntity
(
@
EntityID
2
,
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
NULL
,
NULL
,
"{acl1}"
);
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
EntityID
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
;
SELECT
tap
.
eq
(
@
x
,
3
,
"after 2nd updateEntity, a 3rd version is there."
);
SELECT
tap
.
eq
(
@
x
,
3
,
"after 2nd updateEntity, a 3rd version is there."
);
SELECT
_iversion
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
EntityID
and
_ipparent
=
2
;
SELECT
_iversion
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
and
_ipparent
=
2
;
SELECT
tap
.
eq
(
@
x
,
3
,
"after 2nd updateEntity, the _iversion number incremented again."
);
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
;
SELECT
_ipparent
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
and
_iversion
=
3
;
SELECT
tap
.
eq
(
@
x
,
2
,
"after 2nd updateEntity, the _pparent points to the 2nd version"
);
SELECT
tap
.
eq
(
@
x
,
2
,
"after 2nd updateEntity, the _pparent points to the 2nd version"
);
SELECT
tap
.
eq
(
"SRIDblieb"
,
srid
,
"correct transaction was stored"
)
FROM
entity_version
WHERE
entity_id
=
@
EntityID
AND
_ipparent
=
2
;
SELECT
tap
.
eq
(
"SRIDblieb"
,
srid
,
"correct transaction was stored"
)
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
AND
_ipparent
=
2
;
-- TEST deleteEntity - should remove all versions
-- TEST deleteEntity - should remove all versions
CALL
deleteIsa
(
@
EntityID
);
CALL
deleteIsa
(
@
EntityID
3
);
CALL
deleteEntity
(
@
EntityID
);
CALL
deleteEntity
(
@
EntityID
2
);
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
EntityID
;
SELECT
count
(
*
)
INTO
@
x
FROM
entity_version
WHERE
entity_id
=
@
Internal
EntityID
;
SELECT
tap
.
eq
(
@
x
,
0
,
"no versions there any more"
);
SELECT
tap
.
eq
(
@
x
,
0
,
"no versions there any more"
);
CALL
deleteEntity
(
@
Parent
ID
);
CALL
deleteEntity
(
@
Entity
ID
3
);
CALL
tap
.
finish
();
CALL
tap
.
finish
();
ROLLBACK
;
ROLLBACK
;
...
@@ -218,21 +225,21 @@ DELETE FROM transactions;
...
@@ -218,21 +225,21 @@ DELETE FROM transactions;
-- insert entity without versioning
-- insert entity without versioning
DELETE
FROM
feature_config
WHERE
_key
=
"ENTITY_VERSIONING"
;
DELETE
FROM
feature_config
WHERE
_key
=
"ENTITY_VERSIONING"
;
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
insertEntity
(
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID4
,
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
SELECT
count
(
*
)
INTO
@
NumOfEntities
FROM
entities
;
SELECT
count
(
*
)
INTO
@
NumOfEntities
FROM
entities
;
SELECT
entity_id
INTO
@
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
SELECT
entity_id
INTO
@
Internal
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
SET
@
TheUser
=
"TheUser"
;
-- used to identify the matching entry in transaction_log
SET
@
TheUser
=
"TheUser"
;
-- used to identify the matching entry in transaction_log
-- fill transaction_log: one entity with two updates (and one insert) and another entity with insert and delete.
-- fill transaction_log: one entity with two updates (and one insert) and another entity with insert and delete.
INSERT
INTO
transaction_log
(
transaction
,
entity_id
,
username
,
realm
,
seconds
,
nanos
)
INSERT
INTO
transaction_log
(
transaction
,
entity_id
,
username
,
realm
,
seconds
,
nanos
)
-- the first entry is the one which is be found by _fix_unversioned
-- the first entry is the one which is be found by _fix_unversioned
VALUES
VALUES
(
"Update"
,
@
EntityID
,
@
TheUser
,
"CaosDB"
,
23458
,
254
),
(
"Update"
,
@
Internal
EntityID
,
@
TheUser
,
"CaosDB"
,
23458
,
254
),
-- the rest is dummy data
-- the rest is dummy data
(
"Update"
,
@
EntityID
,
"OtherUser"
,
"CaosDB"
,
2345
,
633
),
-- not the latest transaction
(
"Update"
,
@
Internal
EntityID
,
"OtherUser"
,
"CaosDB"
,
2345
,
633
),
-- not the latest transaction
(
"Insert"
,
@
EntityID
,
"OtherUser"
,
"CaosDB"
,
245
,
633
),
-- not the latest transaction
(
"Insert"
,
@
Internal
EntityID
,
"OtherUser"
,
"CaosDB"
,
245
,
633
),
-- not the latest transaction
(
"Insert"
,
@
EntityID
+
1
,
@
TheUser
,
"CaosDB"
,
2325
,
653
),
-- not the right entity, inserted before our target
(
"Insert"
,
@
Internal
EntityID
+
1
,
@
TheUser
,
"CaosDB"
,
2325
,
653
),
-- not the right entity, inserted before our target
(
"Delete"
,
@
EntityID
+
1
,
@
TheUser
,
"CaosDB"
,
232526
,
653
);
-- not the right entity, deleted after our target
(
"Delete"
,
@
Internal
EntityID
+
1
,
@
TheUser
,
"CaosDB"
,
232526
,
653
);
-- not the right entity, deleted after our target
SELECT
tap
.
eq
(
COUNT
(
*
),
5
,
"five entries in transaction_log"
)
FROM
transaction_log
;
SELECT
tap
.
eq
(
COUNT
(
*
),
5
,
"five entries in transaction_log"
)
FROM
transaction_log
;
...
@@ -252,11 +259,11 @@ SELECT tap.eq(COUNT(*), 2,
...
@@ -252,11 +259,11 @@ SELECT tap.eq(COUNT(*), 2,
"after _fix_unversioned, one entry for our test entity in transactions, one for the standard entities."
)
"after _fix_unversioned, one entry for our test entity in transactions, one for the standard entities."
)
FROM
transactions
;
FROM
transactions
;
SELECT
tap
.
eq
(
entity_id
,
@
EntityID
,
"versioned entity has correct id"
)
FROM
entity_version
WHERE
entity_id
>
99
;
SELECT
tap
.
eq
(
entity_id
,
@
Internal
EntityID
,
"versioned entity has correct id"
)
FROM
entity_version
WHERE
entity_id
>
99
;
SELECT
tap
.
ok
(
srid
IS
NOT
NULL
,
"srid was generated and user/time matches entries from transaction_log"
)
SELECT
tap
.
ok
(
srid
IS
NOT
NULL
,
"srid was generated and user/time matches entries from transaction_log"
)
FROM
transactions
AS
t
JOIN
transaction_log
AS
l
FROM
transactions
AS
t
JOIN
transaction_log
AS
l
ON
(
l
.
seconds
=
t
.
seconds
AND
l
.
nanos
=
t
.
nanos
AND
l
.
username
=
t
.
username
AND
l
.
realm
=
t
.
realm
)
ON
(
l
.
seconds
=
t
.
seconds
AND
l
.
nanos
=
t
.
nanos
AND
l
.
username
=
t
.
username
AND
l
.
realm
=
t
.
realm
)
WHERE
l
.
entity_id
=
@
EntityID
AND
l
.
username
=
@
TheUser
;
WHERE
l
.
entity_id
=
@
Internal
EntityID
AND
l
.
username
=
@
TheUser
;
CALL
tap
.
finish
();
CALL
tap
.
finish
();
ROLLBACK
;
ROLLBACK
;
...
@@ -276,18 +283,18 @@ DELETE FROM transactions;
...
@@ -276,18 +283,18 @@ DELETE FROM transactions;
DELETE
FROM
feature_config
WHERE
_key
=
"ENTITY_VERSIONING"
;
DELETE
FROM
feature_config
WHERE
_key
=
"ENTITY_VERSIONING"
;
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
insertEntity
(
"EntityName1"
,
"EntityDesc1"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID5
,
"EntityName1"
,
"EntityDesc1"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
"EntityName2"
,
"EntityDesc2"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID6
,
"EntityName2"
,
"EntityDesc2"
,
"RECORDTYPE"
,
"{acl1}"
);
SELECT
count
(
*
)
INTO
@
NumOfEntities
FROM
entities
;
SELECT
count
(
*
)
INTO
@
NumOfEntities
FROM
entities
;
SELECT
entity_id
INTO
@
EntityID1
FROM
name_data
WHERE
value
=
"EntityName1"
;
SELECT
entity_id
INTO
@
Internal
EntityID1
FROM
name_data
WHERE
value
=
"EntityName1"
;
SELECT
entity_id
INTO
@
EntityID2
FROM
name_data
WHERE
value
=
"EntityName2"
;
SELECT
entity_id
INTO
@
Internal
EntityID2
FROM
name_data
WHERE
value
=
"EntityName2"
;
INSERT
INTO
transaction_log
(
transaction
,
entity_id
,
username
,
realm
,
seconds
,
INSERT
INTO
transaction_log
(
transaction
,
entity_id
,
username
,
realm
,
seconds
,
nanos
)
nanos
)
-- the first entry is the one which will be found by _fix_unversioned
-- the first entry is the one which will be found by _fix_unversioned
VALUES
(
"INSERT"
,
@
EntityID1
,
"User"
,
"CaosDB"
,
10000
,
250
),
VALUES
(
"INSERT"
,
@
Internal
EntityID1
,
"User"
,
"CaosDB"
,
10000
,
250
),
(
"INSERT"
,
@
EntityID2
,
"User"
,
"CaosDB"
,
10000
,
250
),
(
"INSERT"
,
@
Internal
EntityID2
,
"User"
,
"CaosDB"
,
10000
,
250
),
(
"UPDATE"
,
@
EntityID2
,
"User"
,
"CaosDB"
,
20000
,
250
);
(
"UPDATE"
,
@
Internal
EntityID2
,
"User"
,
"CaosDB"
,
20000
,
250
);
SELECT
tap
.
eq
(
COUNT
(
*
),
3
,
"three entries in transaction_log"
)
FROM
transaction_log
;
SELECT
tap
.
eq
(
COUNT
(
*
),
3
,
"three entries in transaction_log"
)
FROM
transaction_log
;
...
@@ -310,10 +317,10 @@ SELECT tap.eq(COUNT(*), 3,
...
@@ -310,10 +317,10 @@ SELECT tap.eq(COUNT(*), 3,
SELECT
tap
.
eq
(
seconds
,
10000
,
"version seconds of entity 1 is correct"
)
SELECT
tap
.
eq
(
seconds
,
10000
,
"version seconds of entity 1 is correct"
)
FROM
entity_version
AS
v
JOIN
transactions
AS
t
FROM
entity_version
AS
v
JOIN
transactions
AS
t
ON
(
v
.
srid
=
t
.
srid
)
WHERE
v
.
entity_id
=
@
EntityID1
;
ON
(
v
.
srid
=
t
.
srid
)
WHERE
v
.
entity_id
=
@
Internal
EntityID1
;
SELECT
tap
.
eq
(
seconds
,
20000
,
"version seconds of entity 2 is correct"
)
SELECT
tap
.
eq
(
seconds
,
20000
,
"version seconds of entity 2 is correct"
)
FROM
entity_version
AS
v
JOIN
transactions
AS
t
FROM
entity_version
AS
v
JOIN
transactions
AS
t
ON
(
v
.
srid
=
t
.
srid
)
WHERE
v
.
entity_id
=
@
EntityID2
;
ON
(
v
.
srid
=
t
.
srid
)
WHERE
v
.
entity_id
=
@
Internal
EntityID2
;
CALL
tap
.
finish
();
CALL
tap
.
finish
();
ROLLBACK
;
ROLLBACK
;
This diff is collapsed.
Click to expand it.
tests/test_insert_update_delete.sql
+
18
−
15
View file @
6a3883be
...
@@ -4,6 +4,9 @@ CALL tap.no_plan();
...
@@ -4,6 +4,9 @@ CALL tap.no_plan();
-- SETUP
-- SETUP
SET
@
EntityID1
=
10001
;
SET
@
EntityID2
=
10002
;
-- Disable versioning and only test the non-versioning behavior
-- Disable versioning and only test the non-versioning behavior
DELETE
FROM
feature_config
WHERE
_key
=
"ENTITY_VERSIONING"
;
DELETE
FROM
feature_config
WHERE
_key
=
"ENTITY_VERSIONING"
;
...
@@ -16,31 +19,31 @@ SELECT entity_id into @TextDatatypeID FROM name_data WHERE value ="TEXT";
...
@@ -16,31 +19,31 @@ SELECT entity_id into @TextDatatypeID FROM name_data WHERE value ="TEXT";
-- TEST insertEntity
-- TEST insertEntity
SELECT
tap
.
eq
(
COUNT
(
id
),
0
,
"No entities"
)
SELECT
tap
.
eq
(
COUNT
(
id
),
0
,
"No entities"
)
FROM
entities
WHERE
id
>=
100
;
FROM
entities
WHERE
id
>=
100
;
CALL
insertEntity
(
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID1
,
"EntityName"
,
"EntityDesc"
,
"RECORDTYPE"
,
"{acl1}"
);
SELECT
tap
.
eq
(
COUNT
(
entity_id
),
1
,
"Entity has been inserted"
)
SELECT
tap
.
eq
(
COUNT
(
entity_id
),
1
,
"Entity has been inserted"
)
FROM
name_data
WHERE
value
=
"EntityName"
;
FROM
name_data
WHERE
value
=
"EntityName"
;
SELECT
entity_id
INTO
@
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
SELECT
entity_id
INTO
@
Internal
EntityID
FROM
name_data
WHERE
value
=
"EntityName"
;
SELECT
tap
.
ok
(
@
EntityID
>=
100
,
"EntityID greater 99"
);
SELECT
tap
.
ok
(
@
Internal
EntityID
>=
100
,
"EntityID greater 99"
);
SELECT
tap
.
eq
(
acl
,
@
ACLID1
,
"correct acl id had been assigned"
)
SELECT
tap
.
eq
(
acl
,
@
ACLID1
,
"correct acl id had been assigned"
)
FROM
entities
WHERE
id
=@
EntityID
;
FROM
entities
WHERE
id
=@
Internal
EntityID
;
-- TEST insertEntityProperty
-- TEST insertEntityProperty
CALL
insertEntity
(
"AProperty"
,
"APropDesc"
,
"PROPERTY"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID2
,
"AProperty"
,
"APropDesc"
,
"PROPERTY"
,
"{acl1}"
);
SELECT
entity_id
INTO
@
Prop
ID
FROM
name_data
WHERE
value
=
"AProperty"
;
SELECT
entity_id
INTO
@
InternalProperty
ID
FROM
name_data
WHERE
value
=
"AProperty"
;
INSERT
INTO
data_type
(
domain_id
,
entity_id
,
property_id
,
datatype
)
VALUES
(
0
,
0
,
@
Prop
ID
,
@
TextDatatypeID
);
INSERT
INTO
data_type
(
domain_id
,
entity_id
,
property_id
,
datatype
)
VALUES
(
0
,
0
,
@
InternalProperty
ID
,
@
TextDatatypeID
);
SELECT
COUNT
(
*
)
INTO
@
x
FROM
null_data
;
SELECT
COUNT
(
*
)
INTO
@
x
FROM
null_data
;
SELECT
tap
.
eq
(
@
x
,
0
,
"No data in null_data table"
);
SELECT
tap
.
eq
(
@
x
,
0
,
"No data in null_data table"
);
CALL
insertEntityProperty
(
0
,
@
EntityID
,
@
Prop
ID
,
"null_data"
,
NULL
,
NULL
,
"RECOMMENDED"
,
NULL
,
NULL
,
NULL
,
NULL
,
0
);
CALL
insertEntityProperty
(
0
,
@
EntityID
1
,
@
Entity
ID
2
,
"null_data"
,
NULL
,
NULL
,
"RECOMMENDED"
,
NULL
,
NULL
,
NULL
,
NULL
,
0
);
SELECT
COUNT
(
*
)
INTO
@
x
FROM
null_data
;
SELECT
COUNT
(
*
)
INTO
@
x
FROM
null_data
;
SELECT
tap
.
eq
(
@
x
,
1
,
"One row in null_data table"
);
SELECT
tap
.
eq
(
@
x
,
1
,
"One row in null_data table"
);
-- TEST updateEntity
-- TEST updateEntity
CALL
updateEntity
(
@
EntityID
,
"NewEntityName"
,
"NewEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl2}"
);
CALL
updateEntity
(
@
EntityID
1
,
"NewEntityName"
,
"NewEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl2}"
);
SELECT
tap
.
eq
(
COUNT
(
entity_id
),
0
,
"Old Entity name not present"
)
SELECT
tap
.
eq
(
COUNT
(
entity_id
),
0
,
"Old Entity name not present"
)
FROM
name_data
WHERE
value
=
"EntityName"
;
FROM
name_data
WHERE
value
=
"EntityName"
;
...
@@ -48,21 +51,21 @@ SELECT tap.eq(COUNT(entity_id), 1, "Entity name has been updated")
...
@@ -48,21 +51,21 @@ SELECT tap.eq(COUNT(entity_id), 1, "Entity name has been updated")
FROM
name_data
WHERE
value
=
"NewEntityName"
;
FROM
name_data
WHERE
value
=
"NewEntityName"
;
SELECT
tap
.
eq
(
acl
,
@
ACLID2
,
"acl has been updated"
)
SELECT
tap
.
eq
(
acl
,
@
ACLID2
,
"acl has been updated"
)
FROM
entities
WHERE
id
=@
EntityID
;
FROM
entities
WHERE
id
=@
Internal
EntityID
;
-- CALL updateEntity again an update the Name
-- CALL updateEntity again an update the Name
CALL
updateEntity
(
@
EntityID
,
"NewerEntityName"
,
"NewerEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl2}"
);
CALL
updateEntity
(
@
EntityID
2
,
"NewerEntityName"
,
"NewerEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl2}"
);
CALL
updateEntity
(
@
EntityID
,
"NewEntityName"
,
"NewEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl2}"
);
CALL
updateEntity
(
@
EntityID
2
,
"NewEntityName"
,
"NewEntityDesc"
,
"RECORD"
,
NULL
,
NULL
,
"{acl2}"
);
-- TEST deleteEntityProperties
-- TEST deleteEntityProperties
CALL
deleteEntityProperties
(
@
EntityID
);
CALL
deleteEntityProperties
(
@
EntityID
1
);
SELECT
COUNT
(
*
)
INTO
@
x
FROM
null_data
;
SELECT
COUNT
(
*
)
INTO
@
x
FROM
null_data
;
SELECT
tap
.
eq
(
@
x
,
0
,
"data removed from null_data table"
);
SELECT
tap
.
eq
(
@
x
,
0
,
"data removed from null_data table"
);
-- TEST deleteEntity
-- TEST deleteEntity
CALL
deleteEntity
(
@
EntityID
);
CALL
deleteEntity
(
@
EntityID
1
);
CALL
deleteEntity
(
@
Prop
ID
);
CALL
deleteEntity
(
@
Entity
ID
2
);
SELECT
COUNT
(
id
)
INTO
@
x
FROM
entities
WHERE
id
>
100
;
SELECT
COUNT
(
id
)
INTO
@
x
FROM
entities
WHERE
id
>
100
;
SELECT
tap
.
eq
(
@
x
,
0
,
"entity deleted"
);
SELECT
tap
.
eq
(
@
x
,
0
,
"entity deleted"
);
...
...
This diff is collapsed.
Click to expand it.
tests/test_issues.sql
+
12
−
14
View file @
6a3883be
/**
/**
* ** header v3.0
* This file is a part of the CaosDB Project.
* This file is a part of the CaosDB Project.
*
*
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
...
@@ -25,6 +24,10 @@ USE _caosdb_schema_unit_tests;
...
@@ -25,6 +24,10 @@ USE _caosdb_schema_unit_tests;
BEGIN
;
BEGIN
;
CALL
tap
.
no_plan
();
CALL
tap
.
no_plan
();
SET
@
EntityID1
=
10001
;
SET
@
EntityID2
=
10002
;
SET
@
EntityID3
=
10003
;
SET
@
EntityID4
=
10004
;
-- ########################################################################
-- ########################################################################
-- TEST Issues from https://gitlab.com/caosdb/caosdb-mysqlbackend/-/issues
-- TEST Issues from https://gitlab.com/caosdb/caosdb-mysqlbackend/-/issues
...
@@ -42,23 +45,18 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
...
@@ -42,23 +45,18 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
CALL
entityACL
(
@
ACLID1
,
"{acl1}"
);
-- Insert entities and obtain IDs
-- Insert entities and obtain IDs
CALL
insertEntity
(
"A"
,
"Desc A"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID1
,
"A"
,
"Desc A"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
"B"
,
"Desc B"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID2
,
"B"
,
"Desc B"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
"C"
,
"Desc C"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID3
,
"C"
,
"Desc C"
,
"RECORDTYPE"
,
"{acl1}"
);
CALL
insertEntity
(
"rec"
,
"Desc rec"
,
"RECORD"
,
"{acl1}"
);
CALL
insertEntity
(
@
EntityID4
,
"rec"
,
"Desc rec"
,
"RECORD"
,
"{acl1}"
);
SELECT
entity_id
INTO
@
ID_A
FROM
name_data
WHERE
value
=
"A"
;
SELECT
entity_id
INTO
@
ID_B
FROM
name_data
WHERE
value
=
"B"
;
SELECT
entity_id
INTO
@
ID_C
FROM
name_data
WHERE
value
=
"C"
;
SELECT
entity_id
INTO
@
ID_rec
FROM
name_data
WHERE
value
=
"rec"
;
-- Insert is-a relationships
-- Insert is-a relationships
CALL
insertIsA
(
@
ID_A
,
@
ID_B
);
CALL
insertIsA
(
@
EntityID1
,
@
EntityID2
);
CALL
insertIsA
(
@
ID_B
,
@
ID_C
);
CALL
insertIsA
(
@
EntityID2
,
@
EntityID3
);
CALL
insertIsA
(
@
ID_rec
,
@
ID_A
);
CALL
insertIsA
(
@
EntityID4
,
@
EntityID1
);
-- Try to delete last child
-- Try to delete last child
-- leads to failure in issue #21
-- leads to failure in issue #21
CALL
deleteIsa
(
@
ID_rec
);
CALL
deleteIsa
(
@
EntityID4
);
ROLLBACK
;
ROLLBACK
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment