Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7163835
D1096.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D1096.diff
View Options
diff --git a/sql/upgrades/120.sql b/sql/upgrades/120.sql
new file mode 100644
--- /dev/null
+++ b/sql/upgrades/120.sql
@@ -0,0 +1,61 @@
+-- SWH Indexer DB schema upgrade
+-- from_version: 119
+-- to_version: 120
+-- description: fix updates of the 'mappings' column in metadata tables
+
+insert into dbversion(version, release, description)
+values(120, now(), 'Work In Progress');
+
+create or replace function swh_revision_metadata_add(conflict_update boolean)
+ returns void
+ language plpgsql
+as $$
+begin
+ if conflict_update then
+ insert into revision_metadata (id, translated_metadata, mappings, indexer_configuration_id)
+ select id, translated_metadata, mappings, indexer_configuration_id
+ from tmp_revision_metadata tcm
+ on conflict(id, indexer_configuration_id)
+ do update set
+ translated_metadata = excluded.translated_metadata,
+ mappings = excluded.mappings;
+
+ else
+ insert into revision_metadata (id, translated_metadata, mappings, indexer_configuration_id)
+ select id, translated_metadata, mappings, indexer_configuration_id
+ from tmp_revision_metadata tcm
+ on conflict(id, indexer_configuration_id)
+ do nothing;
+ end if;
+ return;
+end
+$$;
+
+create or replace function swh_origin_intrinsic_metadata_add(
+ conflict_update boolean)
+ returns void
+ language plpgsql
+as $$
+begin
+ perform swh_origin_intrinsic_metadata_compute_tsvector();
+ if conflict_update then
+ insert into origin_intrinsic_metadata (origin_id, metadata, indexer_configuration_id, from_revision, metadata_tsvector, mappings)
+ select origin_id, metadata, indexer_configuration_id, from_revision,
+ metadata_tsvector, mappings
+ from tmp_origin_intrinsic_metadata
+ on conflict(origin_id, indexer_configuration_id)
+ do update set
+ metadata = excluded.metadata,
+ mappings = excluded.mappings;
+
+ else
+ insert into origin_intrinsic_metadata (origin_id, metadata, indexer_configuration_id, from_revision, metadata_tsvector, mappings)
+ select origin_id, metadata, indexer_configuration_id, from_revision,
+ metadata_tsvector, mappings
+ from tmp_origin_intrinsic_metadata
+ on conflict(origin_id, indexer_configuration_id)
+ do nothing;
+ end if;
+ return;
+end
+$$;
diff --git a/swh/indexer/sql/40-swh-func.sql b/swh/indexer/sql/40-swh-func.sql
--- a/swh/indexer/sql/40-swh-func.sql
+++ b/swh/indexer/sql/40-swh-func.sql
@@ -319,7 +319,9 @@
select id, translated_metadata, mappings, indexer_configuration_id
from tmp_revision_metadata tcm
on conflict(id, indexer_configuration_id)
- do update set translated_metadata = excluded.translated_metadata;
+ do update set
+ translated_metadata = excluded.translated_metadata,
+ mappings = excluded.mappings;
else
insert into revision_metadata (id, translated_metadata, mappings, indexer_configuration_id)
@@ -415,7 +417,9 @@
metadata_tsvector, mappings
from tmp_origin_intrinsic_metadata
on conflict(origin_id, indexer_configuration_id)
- do update set metadata = excluded.metadata;
+ do update set
+ metadata = excluded.metadata,
+ mappings = excluded.mappings;
else
insert into origin_intrinsic_metadata (origin_id, metadata, indexer_configuration_id, from_revision, metadata_tsvector, mappings)
diff --git a/swh/indexer/tests/storage/test_storage.py b/swh/indexer/tests/storage/test_storage.py
--- a/swh/indexer/tests/storage/test_storage.py
+++ b/swh/indexer/tests/storage/test_storage.py
@@ -1295,7 +1295,7 @@
'softwareRequirements': None,
'identifier': None
},
- 'mappings': [],
+ 'mappings': ['mapping1'],
'indexer_configuration_id': tool_id,
}
@@ -1309,7 +1309,7 @@
expected_metadata_v1 = [{
'id': self.revision_id_1,
'translated_metadata': metadata_v1['translated_metadata'],
- 'mappings': [],
+ 'mappings': ['mapping1'],
'tool': self.tools['swh-metadata-detector']
}]
@@ -1322,6 +1322,7 @@
'name': 'test_metadata',
'author': 'MG',
},
+ 'mappings': ['mapping2'],
})
self.storage.revision_metadata_add([metadata_v2])
@@ -1356,7 +1357,7 @@
'softwareRequirements': None,
'identifier': None
},
- 'mappings': [],
+ 'mappings': ['mapping1'],
'indexer_configuration_id': tool_id,
}
@@ -1371,7 +1372,7 @@
expected_metadata_v1 = [{
'id': self.revision_id_2,
'translated_metadata': metadata_v1['translated_metadata'],
- 'mappings': [],
+ 'mappings': ['mapping1'],
'tool': self.tools['swh-metadata-detector']
}]
self.assertEqual(actual_metadata, expected_metadata_v1)
@@ -1383,6 +1384,7 @@
'name': 'test_update_duplicated_metadata',
'author': 'MG'
},
+ 'mappings': ['mapping2'],
})
self.storage.revision_metadata_add([metadata_v2], conflict_update=True)
@@ -1392,7 +1394,7 @@
expected_metadata_v2 = [{
'id': self.revision_id_2,
'translated_metadata': metadata_v2['translated_metadata'],
- 'mappings': [],
+ 'mappings': ['mapping2'],
'tool': self.tools['swh-metadata-detector']
}]
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 30, 4:33 PM (6 d, 21 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3225827
Attached To
D1096: Update mapping column when updating existing metadata.
Event Timeline
Log In to Comment