MT#56231 gri: creatiion and mofication datetimes

in order to be able to detect not cleaned PPA, lets keep
a mofified field to track last time a package was added
to the repository

Change-Id: I7f5d58cbc28d9c9ef54d90b69850fbedb80e4379
master
Victor Seva 2 years ago
parent 9383016f3d
commit c352eae108

@ -0,0 +1,30 @@
# Generated by Django 3.2.17 on 2023-03-02 07:22
import datetime
import django_extensions.db.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("repoapi", "0014_fix_jbi_gerrit"),
]
operations = [
migrations.AddField(
model_name="gerritrepoinfo",
name="created",
field=django_extensions.db.fields.CreationDateTimeField(
auto_now_add=True, default=datetime.datetime(1977, 1, 1, 0, 0)
),
preserve_default=False,
),
migrations.AddField(
model_name="gerritrepoinfo",
name="modified",
field=django_extensions.db.fields.ModificationDateTimeField(
auto_now=True
),
),
]

@ -1,4 +1,4 @@
# Copyright (C) 2015-2020 The Sipwise Team - http://sipwise.com # Copyright (C) 2015-2023 The Sipwise Team - http://sipwise.com
# #
# This program is free software: you can redistribute it and/or modify it # 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 # under the terms of the GNU General Public License as published by the Free
@ -13,12 +13,16 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
from django.db import models from django.db import models
from django_extensions.db.fields import CreationDateTimeField
from django_extensions.db.fields import ModificationDateTimeField
class GerritRepoInfo(models.Model): class GerritRepoInfo(models.Model):
param_ppa = models.CharField(max_length=50, null=False) param_ppa = models.CharField(max_length=50, null=False)
gerrit_change = models.CharField(max_length=50, null=False) gerrit_change = models.CharField(max_length=50, null=False)
projectname = models.CharField(max_length=100) projectname = models.CharField(max_length=100)
created = CreationDateTimeField()
modified = ModificationDateTimeField()
class Meta: class Meta:
unique_together = ["param_ppa", "gerrit_change"] unique_together = ["param_ppa", "gerrit_change"]

@ -50,12 +50,22 @@ def gerrit_repo_add(instance):
gerrit_change=instance.gerrit_change, gerrit_change=instance.gerrit_change,
defaults={"projectname": instance.projectname}, defaults={"projectname": instance.projectname},
) )
structlog.contextvars.bind_contextvars(
instance=str(instance),
branch=instance.param_branch,
ppa=str(ppa),
last_activity=ppa.modified,
gerrit_change=instance.gerrit_change,
)
if created: if created:
logger.info("ppa created", ppa=str(ppa)) logger.info("ppa created")
elif ppa.projectname == "unknown": elif ppa.projectname == "unknown":
ppa.projectname = instance.projectname ppa.projectname = instance.projectname
ppa.save() ppa.save()
logger.info("ppa projectname updated") logger.info("ppa projectname updated")
else:
ppa.save()
logger.info("ppa last activity datetime saved")
def gerrit_repo_del(instance): def gerrit_repo_del(instance):

Loading…
Cancel
Save