Skip to content

Commit

Permalink
pushlog: add basic models (bug 1940610)
Browse files Browse the repository at this point in the history
  • Loading branch information
shtrom committed Jan 16, 2025
1 parent 07c2ef0 commit f930ab3
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ testpaths = [
"src/lando/api",
"src/lando/dockerflow",
"src/lando/main/tests",
"src/lando/pushlog/tests",
"src/lando/tests",
"src/lando/ui/tests",
]
85 changes: 85 additions & 0 deletions src/lando/pushlog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Generated by Django 5.1.4 on 2025-01-16 06:02

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
("main", "0013_alter_repo_scm_type_alter_worker_scm"),
]

operations = [
migrations.CreateModel(
name="File",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name="Commit",
fields=[
("push_id", models.AutoField(primary_key=True, serialize=False)),
("author", models.CharField(max_length=512)),
("branch", models.CharField(max_length=255)),
("desc", models.TextField()),
("commit", models.CharField(max_length=160)),
("parents", models.ManyToManyField(blank=True, to="pushlog.commit")),
("files", models.ManyToManyField(to="pushlog.file")),
],
),
migrations.CreateModel(
name="Push",
fields=[
("push_id", models.AutoField(primary_key=True, serialize=False)),
(
"type",
models.CharField(
choices=[("git", "git")], default="git", max_length=3
),
),
("date", models.DateField(auto_now_add=True)),
("user", models.EmailField(max_length=320)),
("commits", models.ManyToManyField(to="pushlog.commit")),
(
"repo",
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING, to="main.repo"
),
),
],
),
migrations.CreateModel(
name="Tag",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
(
"commit",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="pushlog.commit"
),
),
],
),
]
Empty file.
9 changes: 9 additions & 0 deletions src/lando/pushlog/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .commit import Commit, File, Tag
from .push import Push

__all__ = [
"Commit",
"File",
"Push",
"Tag",
]
35 changes: 35 additions & 0 deletions src/lando/pushlog/models/commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.db import models

MAX_FILENAME_LENGTH = 255


class File(models.Model):
name = models.CharField(max_length=MAX_FILENAME_LENGTH)


class Commit(models.Model):
push_id = models.AutoField(primary_key=True)

# Assuming a max email address length (see Push model), and then some space for a long name.
author = models.CharField(max_length=512)

# Branch names are limited by how long a filename the filesystem support. This is
# generally 255 bytes.
branch = models.CharField(max_length=MAX_FILENAME_LENGTH)

desc = models.TextField()

files = models.ManyToManyField(File)
# "files": [
# "other-licenses/android/res_init.c"
# ],

commit = models.CharField(max_length=160)

parents = models.ManyToManyField("self", blank=True)

class Tag(models.Model):
# Tag names are limited by how long a filename the filesystem support. This is
# generally 255 bytes.
name = models.CharField(max_length=MAX_FILENAME_LENGTH)
commit = models.ForeignKey(Commit, on_delete=models.CASCADE)
34 changes: 34 additions & 0 deletions src/lando/pushlog/models/push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.db import models

from lando.main.models import Repo

from .commit import Commit

PUSH_SCM_TYPE_GIT = "git"
PUSH_SCM_TYPES = [PUSH_SCM_TYPE_GIT]


class Push(models.Model):
push_id = models.AutoField(primary_key=True)

type = models.CharField(
max_length=3, choices={v: v for v in PUSH_SCM_TYPES}, default=PUSH_SCM_TYPE_GIT
)

date = models.DateField(
auto_now=False,
auto_now_add=True,
)
# Maximum total lengths are defined in RFC-5321 [0]: 64 for the local-part, and 255
# for the domain.
# [0] https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.3.1.1
user = models.EmailField(max_length=64 + 1 + 255)

commits = models.ManyToManyField(Commit)

repo = models.ForeignKey(
Repo,
# We don't want to delete the PushLog, even if we were to delete the repo
# object.
on_delete=models.DO_NOTHING,
)
9 changes: 9 additions & 0 deletions src/lando/pushlog/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from lando.pushlog.models import Commit


@pytest.mark.django_db()
def test__pushlog__models__Commit():
c = Commit()
assert c
1 change: 1 addition & 0 deletions src/lando/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"compressor",
"mozilla_django_oidc",
"lando.main",
"lando.pushlog",
"lando.utils",
"lando.api",
"lando.dockerflow",
Expand Down

0 comments on commit f930ab3

Please sign in to comment.