From 32fc2eff9b55e31a467ee3d8754352183cbb326b Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Wed, 18 Dec 2024 14:31:27 +0100 Subject: [PATCH] database:upgrade:upgrade_4to4_1 - recreate views based on `files_master` table --- acacore/database/upgrade.py | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/acacore/database/upgrade.py b/acacore/database/upgrade.py index e902f4f..e015204 100644 --- a/acacore/database/upgrade.py +++ b/acacore/database/upgrade.py @@ -67,12 +67,63 @@ def upgrade_4to4_1(con: Connection) -> Version: con.execute("update files_master_tmp set processed = processed - 4 where processed != 0") + con.execute("drop view files_all") + con.execute("drop view log_paths") con.execute("drop table files_master") - con.execute("alter table files_master_tmp rename to files_master") - con.execute("vacuum") - + con.execute("alter table files_master_tmp rename to 'files_master'") + con.execute(""" + create view files_all as + select uuid, + checksum, + relative_path, + is_binary, + size, + puid, + signature, + warning + from files_original + union + select uuid, + checksum, + relative_path, + is_binary, + size, + puid, + signature, + warning + from files_master + union + select uuid, + checksum, + relative_path, + is_binary, + size, + puid, + signature, + warning + from files_access + union + select uuid, + checksum, + relative_path, + is_binary, + size, + puid, + signature, + warning + from files_statutory + """) + con.execute(""" + create view log_paths as + select coalesce(fo.relative_path, fm.relative_path) as file_relative_path, l.* + from log l + left join files_original fo on l.file_type = 'original' and fo.uuid = l.file_uuid + left join files_master fm on l.file_type = 'master' and fm.uuid = l.file_uuid + """) con.commit() + con.execute("vacuum") + return set_db_version(con, Version("4.1.0"))