filter empty packages from database

In some cases (e.g. during addition of the package to build queue) we don't have
full information about package inself; in these cases we produce lines
with empty architecture, which duplicates normal ones.

This commit changes architecture column type to required and also
filters packages which don't have architecture set yet.

Closes #83
This commit is contained in:
Evgenii Alekseev 2023-01-30 17:57:13 +02:00
parent 9d7f63e549
commit 0a2ba4ae07
4 changed files with 73 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
#
__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_;
""",
]

View File

@ -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(
"""

View File

@ -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

View File

@ -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