diff --git a/src/ahriman/core/database/migrations/m006_packages_architecture_required.py b/src/ahriman/core/database/migrations/m006_packages_architecture_required.py new file mode 100644 index 00000000..a5438286 --- /dev/null +++ b/src/ahriman/core/database/migrations/m006_packages_architecture_required.py @@ -0,0 +1,53 @@ +# +# Copyright (c) 2021-2023 ahriman team. +# +# This file is part of ahriman +# (see https://github.com/arcan1s/ahriman). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +__all__ = ["steps"] + + +steps = [ + """ + alter table packages rename to packages_ + """, + """ + create table packages ( + package text not null, + package_base text not null, + architecture text not null, + archive_size integer, + build_date integer, + depends json, + description text, + filename text, + "groups" json, + installed_size integer, + licenses json, + provides json, + url text, + make_depends json, + opt_depends json, + unique (package, architecture) + ) + """, + """ + insert into packages select * from packages_ where architecture is not null; + """, + """ + drop table packages_; + """, +] diff --git a/src/ahriman/core/database/operations/package_operations.py b/src/ahriman/core/database/operations/package_operations.py index 595522b3..789816c9 100644 --- a/src/ahriman/core/database/operations/package_operations.py +++ b/src/ahriman/core/database/operations/package_operations.py @@ -104,6 +104,8 @@ class PackageOperations(Operations): """ package_list = [] for name, description in package.packages.items(): + if description.architecture is None: + continue # architecture is required package_list.append(dict(package=name, package_base=package.base, **description.view())) connection.executemany( """ diff --git a/tests/ahriman/core/database/migrations/test_m006_packages_architecture_required.py b/tests/ahriman/core/database/migrations/test_m006_packages_architecture_required.py new file mode 100644 index 00000000..f3929af6 --- /dev/null +++ b/tests/ahriman/core/database/migrations/test_m006_packages_architecture_required.py @@ -0,0 +1,8 @@ +from ahriman.core.database.migrations.m006_packages_architecture_required import steps + + +def test_migration_logs() -> None: + """ + migration must not be empty + """ + assert steps diff --git a/tests/ahriman/core/database/operations/test_package_operations.py b/tests/ahriman/core/database/operations/test_package_operations.py index 1306e4c2..5e7309c3 100644 --- a/tests/ahriman/core/database/operations/test_package_operations.py +++ b/tests/ahriman/core/database/operations/test_package_operations.py @@ -48,6 +48,16 @@ def test_package_update_insert_packages(database: SQLite, connection: Connection connection.executemany(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)) +def test_package_update_insert_packages_no_arch(database: SQLite, connection: Connection, + package_ahriman: Package) -> None: + """ + must skip package insertion if no package architecture set + """ + package_ahriman.packages[package_ahriman.base].architecture = None + database._package_update_insert_packages(connection, package_ahriman) + connection.executemany(pytest.helpers.anyvar(str, strict=True), []) + + def test_package_update_insert_status(database: SQLite, connection: Connection, package_ahriman: Package) -> None: """ must insert single package status