Skip to content

♻️ Improve records schema #2886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 5.2 on 2025-07-03 19:59

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

import lamindb.base.fields


class Migration(migrations.Migration):
dependencies = [
("lamindb", "0108_remove_record_sheet_remove_sheetproject_sheet_and_more"),
]

operations = [
migrations.AddField(
model_name="record",
name="input_of_runs",
field=models.ManyToManyField(
related_name="input_records", to="lamindb.run"
),
),
migrations.AlterField(
model_name="record",
name="run",
field=lamindb.base.fields.ForeignKey(
blank=True,
default=None,
editable=False,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="output_records",
to="lamindb.run",
),
),
migrations.AlterUniqueTogether(
name="recordrecord",
unique_together={("record", "feature", "value")},
),
migrations.AlterUniqueTogether(
name="recordrun",
unique_together={("record", "feature", "value")},
),
migrations.AlterUniqueTogether(
name="recordulabel",
unique_together={("record", "feature", "value")},
),
]
19 changes: 15 additions & 4 deletions lamindb/models/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ class Meta(SQLRecord.Meta, TracksRun.Meta, TracksUpdates.Meta):
"""Linked artifacts."""
runs: Run = models.ManyToManyField(Run, through="RecordRun", related_name="records")
"""Linked runs."""
run: Run | None = ForeignKey(
Run,
PROTECT,
related_name="output_records",
null=True,
default=None,
editable=False,
)
"""Run that created the record."""
input_of_runs: Run = models.ManyToManyField(Run, related_name="input_records")
"""Runs that use this record as an input."""
ulabels: ULabel = models.ManyToManyField(
ULabel,
through="RecordULabel",
Expand Down Expand Up @@ -177,7 +188,7 @@ class RecordJson(BaseSQLRecord, IsLink):
value: Any = JSONField(default=None, db_default=None)

class Meta:
unique_together = ("record", "feature")
unique_together = ("record", "feature") # a list is modeled as a list in json


class RecordRecord(SQLRecord, IsLink):
Expand All @@ -191,7 +202,7 @@ class RecordRecord(SQLRecord, IsLink):
) # component

class Meta:
unique_together = ("record", "feature")
unique_together = ("record", "feature", "value")


class RecordULabel(BaseSQLRecord, IsLink):
Expand All @@ -202,7 +213,7 @@ class RecordULabel(BaseSQLRecord, IsLink):

class Meta:
# allows linking exactly one record to one ulabel per feature, because we likely don't want to have Many
unique_together = ("record", "feature")
unique_together = ("record", "feature", "value")


class RecordRun(BaseSQLRecord, IsLink):
Expand All @@ -213,7 +224,7 @@ class RecordRun(BaseSQLRecord, IsLink):

class Meta:
# allows linking several records to a single run for the same feature because we'll likely need this
unique_together = ("record", "feature")
unique_together = ("record", "feature", "value")


class RecordArtifact(BaseSQLRecord, IsLink):
Expand Down
10 changes: 10 additions & 0 deletions lamindb/models/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ class Run(SQLRecord):

Related accessor: via :attr:`~lamindb.Artifact.run`
"""
input_records: Artifact
"""The records serving as input for this run.

Related accessor: :attr:`~lamindb.Record.input_of_runs`.
"""
output_records: Artifact
"""The records generated by this run.

Related accessor: via :attr:`~lamindb.Record.run`
"""
input_collections: Collection
"""The collections serving as input for this run."""
output_collections: Collection
Expand Down
Loading