Skip to content

Commit

Permalink
🍱 Add a migration
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Oct 18, 2024
1 parent 1d6cd13 commit b62e8b5
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 23 deletions.
4 changes: 2 additions & 2 deletions ourprojects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.. autosummary::
:toctree: .
Reference
Project
"""

__version__ = "0.0.1" # denote a pre-release for 0.1.0 with 0.1rc1
Expand All @@ -30,4 +30,4 @@ def __getattr__(name):

if _check_instance_setup():
del __getattr__ # delete so that imports work out
from .models import Reference
from .models import Project
139 changes: 139 additions & 0 deletions ourprojects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Generated by Django 5.1.1 on 2024-10-18 23:40

import django.db.models.deletion
import lnschema_core.ids
import lnschema_core.models
import lnschema_core.users
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = [
("lnschema_core", "0068_alter_artifactulabel_unique_together_and_more"),
]

operations = [
migrations.CreateModel(
name="ArtifactProject",
fields=[
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("id", models.BigAutoField(primary_key=True, serialize=False)),
("label_ref_is_name", models.BooleanField(default=None, null=True)),
("feature_ref_is_name", models.BooleanField(default=None, null=True)),
(
"artifact",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="links_project",
to="lnschema_core.artifact",
),
),
(
"created_by",
models.ForeignKey(
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"feature",
models.ForeignKey(
default=None,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifactproject",
to="lnschema_core.feature",
),
),
(
"run",
models.ForeignKey(
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
bases=(lnschema_core.models.LinkORM, models.Model),
),
migrations.CreateModel(
name="Project",
fields=[
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
("id", models.AutoField(primary_key=True, serialize=False)),
(
"uid",
models.CharField(
default=lnschema_core.ids.base62_12, max_length=12, unique=True
),
),
("name", models.CharField(db_index=True, default=None, max_length=255)),
(
"abbr",
models.CharField(
db_index=True,
default=None,
max_length=32,
null=True,
unique=True,
),
),
("url", models.URLField(default=None, max_length=255, null=True)),
(
"_previous_runs",
models.ManyToManyField(related_name="+", to="lnschema_core.run"),
),
(
"artifacts",
models.ManyToManyField(
related_name="Projects",
through="ourprojects.ArtifactProject",
to="lnschema_core.artifact",
),
),
(
"created_by",
models.ForeignKey(
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"run",
models.ForeignKey(
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
options={
"abstract": False,
},
bases=(lnschema_core.models.CanValidate, models.Model),
),
migrations.AddField(
model_name="artifactproject",
name="project",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifact",
to="ourprojects.project",
),
),
migrations.AlterUniqueTogether(
name="artifactproject",
unique_together={("artifact", "project", "feature")},
),
]
38 changes: 17 additions & 21 deletions ourprojects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
)


class Reference(Record, CanValidate, TracksRun, TracksUpdates):
"""References.
class Project(Record, CanValidate, TracksRun, TracksUpdates):
"""Projects.
Example:
>>> reference = Reference(
... name="A paper title",
... doi="A doi",
>>> Project = Project(
... name="My project name",
... ).save()
"""

Expand All @@ -32,41 +31,38 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
uid: str = models.CharField(unique=True, max_length=12, default=ids.base62_12)
"""Universal id, valid across DB instances."""
name: str = models.CharField(max_length=255, default=None, db_index=True)
"""Title or name of the reference."""
"""Title or name of the Project."""
abbr: str | None = models.CharField(
max_length=32, db_index=True, unique=True, null=True, default=None
)
"""A unique abbreviation."""
url: str | None = models.URLField(max_length=255, null=True, default=None)
"""A URL to view."""
pubmed_id: int | None = models.BigIntegerField(null=True, default=None)
"""A pudbmed ID."""
doi: int | None = models.CharField(
max_length=255, null=True, default=None, db_index=True
)
"""A DOI."""
text: str | None = models.TextField(null=True, default=None)
"""Text of the reference included in search, e.g. the abstract or the full-text."""
artifacts: Artifact = models.ManyToManyField(
Artifact, through="ArtifactReference", related_name="references"
Artifact, through="ArtifactProject", related_name="Projects"
)
"""Artifacts labeled with this reference."""
"""Artifacts labeled with this Project."""


class ArtifactReference(Record, LinkORM, TracksRun):
class ArtifactProject(Record, LinkORM, TracksRun):
id: int = models.BigAutoField(primary_key=True)
artifact: Artifact = models.ForeignKey(
Artifact, CASCADE, related_name="links_reference"
Artifact, CASCADE, related_name="links_project"
)
reference: Reference = models.ForeignKey(
Reference, PROTECT, related_name="links_artifact"
project: Project = models.ForeignKey(
Project, PROTECT, related_name="links_artifact"
)
feature: Feature = models.ForeignKey(
Feature,
PROTECT,
null=True,
default=None,
related_name="links_artifactreference",
related_name="links_artifactproject",
)
label_ref_is_name: bool | None = models.BooleanField(null=True, default=None)
feature_ref_is_name: bool | None = models.BooleanField(null=True, default=None)

class Meta:
# can have the same label linked to the same artifact if the feature is
# different
unique_together = ("artifact", "project", "feature")

0 comments on commit b62e8b5

Please sign in to comment.