Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
dCache
cta
Commits
c25a468d
Commit
c25a468d
authored
2 years ago
by
Jorge Camarero Vera
Browse files
Options
Downloads
Patches
Plain Diff
Log warn the comparation of indexes between catalogue and schema
parent
daab0e0d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ReleaseNotes.md
+1
-0
1 addition, 0 deletions
ReleaseNotes.md
catalogue/SQLiteSchemaComparer.cpp
+29
-15
29 additions, 15 deletions
catalogue/SQLiteSchemaComparer.cpp
catalogue/SQLiteSchemaComparer.hpp
+6
-1
6 additions, 1 deletion
catalogue/SQLiteSchemaComparer.hpp
with
36 additions
and
16 deletions
ReleaseNotes.md
+
1
−
0
View file @
c25a468d
...
...
@@ -5,6 +5,7 @@
### Features
-
cta/CTA#1205 - Fail pipeline if cppcheck detects errors
-
cta/CTA#1206 - Change NULL for nullptr
-
cta/CTA#1217 - Schema verification should just issue an warning if there are extra indexes in the db that are not in the catalogue
### Bug fixes
### Building and Packaging
### Catalogue Schema
...
...
This diff is collapsed.
Click to expand it.
catalogue/SQLiteSchemaComparer.cpp
+
29
−
15
View file @
c25a468d
...
...
@@ -16,6 +16,7 @@
*/
#include
<algorithm>
#include
<functional>
#include
"SQLiteSchemaComparer.hpp"
#include
"SQLiteSchemaInserter.hpp"
...
...
@@ -83,25 +84,36 @@ void SQLiteSchemaComparer::insertSchemaInSQLite() {
m_isSchemaInserted
=
true
;
}
SchemaCheckerResult
SQLiteSchemaComparer
::
compareIndexes
(){
SchemaCheckerResult
SQLiteSchemaComparer
::
compareIndexes
()
{
insertSchemaInSQLite
();
std
::
list
<
std
::
string
>
catalogueIndexes
=
m_databaseMetadataGetter
.
getIndexNames
();
std
::
list
<
std
::
string
>
schemaIndexes
=
m_schemaMetadataGetter
->
getIndexNames
();
return
compareItems
(
"INDEX"
,
catalogueIndexes
,
schemaIndexes
);
const
Items
catalogueIndexes
=
m_databaseMetadataGetter
.
getIndexNames
();
const
Items
schemaIndexes
=
m_schemaMetadataGetter
->
getIndexNames
();
return
compareItems
(
"INDEX"
,
std
::
make_tuple
(
catalogueIndexes
,
Level
::
Warn
),
std
::
make_tuple
(
schemaIndexes
,
Level
::
Error
)
);
}
SchemaCheckerResult
SQLiteSchemaComparer
::
compareItems
(
const
std
::
string
&
itemType
,
const
std
::
list
<
std
::
string
>&
itemsFromDatabase
,
const
std
::
list
<
std
::
string
>&
itemsFromSQLite
){
SchemaCheckerResult
SQLiteSchemaComparer
::
compareItems
(
const
std
::
string
&
itemType
,
const
LoggedItems
&
fromDatabase
,
const
LoggedItems
&
fromSQLite
)
{
SchemaCheckerResult
result
;
for
(
auto
&
databaseItem
:
itemsFromDatabase
){
if
(
std
::
find
(
itemsFromSQLite
.
begin
(),
itemsFromSQLite
.
end
(),
databaseItem
)
==
itemsFromSQLite
.
end
()){
result
.
addError
(
itemType
+
" "
+
databaseItem
+
" is missing in the schema but defined in the "
+
m_databaseToCheckName
+
" database."
);
}
}
for
(
auto
&
sqliteItem
:
itemsFromSQLite
){
if
(
std
::
find
(
itemsFromDatabase
.
begin
(),
itemsFromDatabase
.
end
(),
sqliteItem
)
==
itemsFromDatabase
.
end
()){
result
.
addError
(
itemType
+
" "
+
sqliteItem
+
" is missing in the "
+
m_databaseToCheckName
+
" database but is defined in the schema."
);
const
auto
[
itemsFromDatabase
,
logFromDataBase
]
=
fromDatabase
;
const
auto
[
itemsFromSQLite
,
logFromSQLite
]
=
fromSQLite
;
auto
findMismatchs
=
[
&
result
,
&
itemType
](
const
Items
&
items
,
const
Items
&
itemsToCompare
,
const
std
::
string
&
message
,
const
Level
&
logLevel
)
->
void
{
std
::
function
<
void
(
const
std
::
string
&
)
>
addResult
;
if
(
logLevel
==
Level
::
Error
)
addResult
=
[
&
result
](
const
std
::
string
&
msg
)
{
result
.
addError
(
msg
);};
if
(
logLevel
==
Level
::
Warn
)
addResult
=
[
&
result
](
const
std
::
string
&
msg
)
{
result
.
addWarning
(
msg
);};
for
(
auto
&
item
:
items
)
{
if
(
std
::
find
(
itemsToCompare
.
begin
(),
itemsToCompare
.
end
(),
item
)
==
itemsToCompare
.
end
())
{
addResult
(
itemType
+
" "
+
item
+
message
);
}
}
}
};
std
::
string
logMsg
=
" is missing in the schema but defined in the "
+
m_databaseToCheckName
+
" database."
;
findMismatchs
(
itemsFromDatabase
,
itemsFromSQLite
,
logMsg
,
logFromDataBase
);
logMsg
=
" is missing in the "
+
m_databaseToCheckName
+
" database but is defined in the schema."
;
findMismatchs
(
itemsFromSQLite
,
itemsFromDatabase
,
logMsg
,
logFromSQLite
);
return
result
;
}
...
...
@@ -121,7 +133,9 @@ SchemaCheckerResult SQLiteSchemaComparer::compareTables(const std::list<std::str
schemaTableColumns
[
schemaTable
]
=
m_schemaMetadataGetter
->
getColumns
(
schemaTable
);
if
(
m_compareTableConstraints
)
{
schemaTableConstraints
[
schemaTable
]
=
m_schemaMetadataGetter
->
getConstraintNames
(
schemaTable
);
result
+=
compareItems
(
"IN TABLE "
+
schemaTable
+
", CONSTRAINT"
,
databaseTableConstraints
[
schemaTable
],
schemaTableConstraints
[
schemaTable
]);
const
LoggedItems
databaseConstrains
=
std
::
make_tuple
(
databaseTableConstraints
[
schemaTable
],
Level
::
Error
);
const
LoggedItems
schemaConstrains
=
std
::
make_tuple
(
schemaTableConstraints
[
schemaTable
],
Level
::
Error
);
result
+=
compareItems
(
"IN TABLE "
+
schemaTable
+
", CONSTRAINT"
,
databaseConstrains
,
schemaConstrains
);
}
}
...
...
This diff is collapsed.
Click to expand it.
catalogue/SQLiteSchemaComparer.hpp
+
6
−
1
View file @
c25a468d
...
...
@@ -16,6 +16,8 @@
*/
#pragma once
#include
<tuple>
#include
"SchemaComparer.hpp"
namespace
cta
{
...
...
@@ -46,7 +48,10 @@ public:
private:
void
insertSchemaInSQLite
();
SchemaCheckerResult
compareItems
(
const
std
::
string
&
itemType
,
const
std
::
list
<
std
::
string
>&
itemsFromDatabase
,
const
std
::
list
<
std
::
string
>&
itemsFromSQLite
);
enum
Level
{
Warn
,
Error
};
using
Items
=
std
::
list
<
std
::
string
>
;
using
LoggedItems
=
std
::
tuple
<
Items
,
Level
>
;
SchemaCheckerResult
compareItems
(
const
std
::
string
&
itemType
,
const
LoggedItems
&
fromDatabase
,
const
LoggedItems
&
fromSQLite
);
SchemaCheckerResult
compareTables
(
const
std
::
list
<
std
::
string
>
&
databaseTables
,
const
std
::
list
<
std
::
string
>
&
schemaTables
);
typedef
std
::
map
<
std
::
string
,
std
::
map
<
std
::
string
,
std
::
string
>>
TableColumns
;
SchemaCheckerResult
compareTableColumns
(
const
TableColumns
&
schema1TableColumns
,
const
std
::
string
&
schema1Type
,
const
TableColumns
&
schema2TableColumns
,
const
std
::
string
&
schema2Type
);
...
...
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