diff --git a/sql/upgrades/131.sql b/sql/upgrades/131.sql new file mode 100644 --- /dev/null +++ b/sql/upgrades/131.sql @@ -0,0 +1,10 @@ +-- SWH DB schema upgrade +-- from_version: 130 +-- to_version: 131 +-- description: Use sha1 instead of bigint as FK from origin_visit to snapshot (part 1: add new column) + +insert into dbversion(version, release, description) + values(131, now(), 'Work In Progress'); + +alter table origin_visit add column snapshot sha1_git; +comment on column origin_visit.snapshot is 'Origin snapshot at visit time'; diff --git a/swh/storage/db.py b/swh/storage/db.py --- a/swh/storage/db.py +++ b/swh/storage/db.py @@ -311,6 +311,11 @@ update_cols.append('metadata=%s') values.append(jsonize(updates.pop('metadata'))) if 'snapshot' in updates: + # New 'snapshot' column + update_cols.append('snapshot=%s') + values.append(updates['snapshot']) + + # Old 'snapshot_id' column update_cols.append('snapshot_id=snapshot.object_id') from_ = 'FROM snapshot' where.append('snapshot.id=%s') diff --git a/swh/storage/sql/30-swh-schema.sql b/swh/storage/sql/30-swh-schema.sql --- a/swh/storage/sql/30-swh-schema.sql +++ b/swh/storage/sql/30-swh-schema.sql @@ -211,7 +211,8 @@ date timestamptz not null, status origin_visit_status not null, metadata jsonb, - snapshot_id bigint + snapshot_id bigint, + snapshot sha1_git ); comment on column origin_visit.origin is 'Visited origin'; @@ -220,6 +221,7 @@ comment on column origin_visit.status is 'Visit result'; comment on column origin_visit.metadata is 'Origin metadata at visit time'; comment on column origin_visit.snapshot_id is 'Origin snapshot at visit time'; +comment on column origin_visit.snapshot is 'Origin snapshot at visit time'; -- A snapshot represents the entire state of a software origin as crawled by