Commit f5869cb5 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler
Browse files

models: Use explicit on_delete=models.CASCADE



As it will be mandatory in future versions of django.
Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent ace98b24
......@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=50)),
('public', models.BooleanField(default=False)),
('owner', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('owner', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
......@@ -29,7 +29,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('order', models.IntegerField()),
('bundle', models.ForeignKey(to='patchwork.Bundle')),
('bundle', models.ForeignKey(to='patchwork.Bundle', on_delete=models.CASCADE)),
],
options={
'ordering': ['order'],
......@@ -57,7 +57,7 @@ class Migration(migrations.Migration):
('key', patchwork.models.HashField(max_length=40)),
('date', models.DateTimeField(default=datetime.datetime.now)),
('active', models.BooleanField(default=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
......@@ -153,47 +153,47 @@ class Migration(migrations.Migration):
('send_email', models.BooleanField(default=False, help_text=b'Selecting this option allows patchwork to send email on your behalf')),
('patches_per_page', models.PositiveIntegerField(default=100, help_text=b'Number of patches to display per page')),
('maintainer_projects', models.ManyToManyField(related_name='maintainer_project', to='patchwork.Project')),
('primary_project', models.ForeignKey(blank=True, to='patchwork.Project', null=True)),
('user', models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL)),
('primary_project', models.ForeignKey(blank=True, to='patchwork.Project', null=True, on_delete=models.CASCADE)),
('user', models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
name='PatchChangeNotification',
fields=[
('patch', models.OneToOneField(primary_key=True, serialize=False, to='patchwork.Patch')),
('patch', models.OneToOneField(primary_key=True, serialize=False, to='patchwork.Patch', on_delete=models.CASCADE)),
('last_modified', models.DateTimeField(default=datetime.datetime.now)),
('orig_state', models.ForeignKey(to='patchwork.State')),
('orig_state', models.ForeignKey(to='patchwork.State', on_delete=models.CASCADE)),
],
),
migrations.AddField(
model_name='patchtag',
name='patch',
field=models.ForeignKey(to='patchwork.Patch'),
field=models.ForeignKey(to='patchwork.Patch', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='patchtag',
name='tag',
field=models.ForeignKey(to='patchwork.Tag'),
field=models.ForeignKey(to='patchwork.Tag', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='patch',
name='delegate',
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True),
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE),
),
migrations.AddField(
model_name='patch',
name='project',
field=models.ForeignKey(to='patchwork.Project'),
field=models.ForeignKey(to='patchwork.Project', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='patch',
name='state',
field=models.ForeignKey(to='patchwork.State'),
field=models.ForeignKey(to='patchwork.State', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='patch',
name='submitter',
field=models.ForeignKey(to='patchwork.Person'),
field=models.ForeignKey(to='patchwork.Person', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='patch',
......@@ -203,17 +203,17 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='comment',
name='patch',
field=models.ForeignKey(to='patchwork.Patch'),
field=models.ForeignKey(to='patchwork.Patch', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='comment',
name='submitter',
field=models.ForeignKey(to='patchwork.Person'),
field=models.ForeignKey(to='patchwork.Person', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='bundlepatch',
name='patch',
field=models.ForeignKey(to='patchwork.Patch'),
field=models.ForeignKey(to='patchwork.Patch', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='bundle',
......@@ -223,7 +223,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='bundle',
name='project',
field=models.ForeignKey(to='patchwork.Project'),
field=models.ForeignKey(to='patchwork.Project', on_delete=models.CASCADE),
),
migrations.AlterUniqueTogether(
name='patchtag',
......
......@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='patch',
name='state',
field=models.ForeignKey(to='patchwork.State', null=True),
field=models.ForeignKey(to='patchwork.State', null=True, on_delete=models.CASCADE),
),
]
......@@ -23,9 +23,9 @@ class Migration(migrations.Migration):
('last_updated', models.DateTimeField(auto_now=True)),
('version', models.IntegerField(default=1)),
('n_patches', models.IntegerField(default=0)),
('project', models.ForeignKey(to='patchwork.Project')),
('reviewer', models.ForeignKey(related_name='reviewers', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('submitter', models.ForeignKey(related_name='submitters', to='patchwork.Person')),
('project', models.ForeignKey(to='patchwork.Project', on_delete=models.CASCADE)),
('reviewer', models.ForeignKey(related_name='reviewers', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)),
('submitter', models.ForeignKey(related_name='submitters', to='patchwork.Person', on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
......@@ -45,8 +45,8 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('order', models.IntegerField()),
('patch', models.ForeignKey(to='patchwork.Patch')),
('revision', models.ForeignKey(to='patchwork.SeriesRevision')),
('patch', models.ForeignKey(to='patchwork.Patch', on_delete=models.CASCADE)),
('revision', models.ForeignKey(to='patchwork.SeriesRevision', on_delete=models.CASCADE)),
],
options={
'ordering': ['order'],
......@@ -60,7 +60,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='seriesrevision',
name='series',
field=models.ForeignKey(to='patchwork.Series'),
field=models.ForeignKey(to='patchwork.Series', on_delete=models.CASCADE),
),
migrations.AlterUniqueTogether(
name='seriesrevisionpatch',
......
......@@ -25,9 +25,9 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('event_time', models.DateTimeField(auto_now=True)),
('event', models.ForeignKey(to='patchwork.Event')),
('series', models.ForeignKey(to='patchwork.Series')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)),
('event', models.ForeignKey(to='patchwork.Event', on_delete=models.CASCADE)),
('series', models.ForeignKey(to='patchwork.Series', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)),
],
options={
'ordering': ['-event_time'],
......
......@@ -19,7 +19,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255)),
('project', models.ForeignKey(to='patchwork.Project')),
('project', models.ForeignKey(to='patchwork.Project', on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
......@@ -30,10 +30,10 @@ class Migration(migrations.Migration):
('state', models.SmallIntegerField(choices=[(0, b'pending'), (1, b'success'), (2, b'warning'), (3, b'failure')])),
('url', models.URLField(null=True, blank=True)),
('summary', models.TextField(null=True, blank=True)),
('patch', models.ForeignKey(blank=True, to='patchwork.Patch', null=True)),
('revision', models.ForeignKey(blank=True, to='patchwork.SeriesRevision', null=True)),
('test', models.ForeignKey(to='patchwork.Test')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('patch', models.ForeignKey(blank=True, to='patchwork.Patch', null=True, on_delete=models.CASCADE)),
('revision', models.ForeignKey(blank=True, to='patchwork.SeriesRevision', null=True, on_delete=models.CASCADE)),
('test', models.ForeignKey(to='patchwork.Test', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
migrations.AlterUniqueTogether(
......
......@@ -43,7 +43,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='series',
name='last_revision',
field=models.OneToOneField(related_name='+', null=True, to='patchwork.SeriesRevision'),
field=models.OneToOneField(related_name='+', null=True, to='patchwork.SeriesRevision', on_delete=models.CASCADE),
),
migrations.AddField(
model_name='seriesrevision',
......
......@@ -19,8 +19,8 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('path', models.CharField(max_length=255)),
('priority', models.IntegerField(default=0)),
('project', models.ForeignKey(to='patchwork.Project')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('project', models.ForeignKey(to='patchwork.Project', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
options={
'ordering': ['-priority', 'path'],
......
......@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='eventlog',
name='patch',
field=models.ForeignKey(to='patchwork.Patch', null=True),
field=models.ForeignKey(to='patchwork.Patch', null=True, on_delete=models.CASCADE),
),
]
......@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='EventLog',
name='series',
field=models.ForeignKey(to='patchwork.Series', null=True),
field=models.ForeignKey(to='patchwork.Series', null=True, on_delete=models.CASCADE),
),
]
......@@ -131,9 +131,9 @@ auth.models.User.add_to_class('name', user_name)
@python_2_unicode_compatible
class DelegationRule(models.Model):
user = models.ForeignKey(User)
user = models.ForeignKey(User, on_delete=models.CASCADE)
path = models.CharField(max_length=255)
project = models.ForeignKey(Project)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
priority = models.IntegerField(default=0)
def __str__(self):
......@@ -146,8 +146,10 @@ class DelegationRule(models.Model):
@python_2_unicode_compatible
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, related_name='profile')
primary_project = models.ForeignKey(Project, null=True, blank=True)
user = models.OneToOneField(User, unique=True, related_name='profile',
on_delete=models.CASCADE)
primary_project = models.ForeignKey(Project, null=True, blank=True,
on_delete=models.CASCADE)
maintainer_projects = models.ManyToManyField(Project,
related_name='maintainer_project', blank=True)
send_email = models.BooleanField(default=False,
......@@ -252,8 +254,8 @@ class Tag(models.Model):
class PatchTag(models.Model):
patch = models.ForeignKey('Patch')
tag = models.ForeignKey('Tag')
patch = models.ForeignKey('Patch', on_delete=models.CASCADE)
tag = models.ForeignKey('Tag', on_delete=models.CASCADE)
count = models.IntegerField(default=1)
class Meta:
......@@ -306,14 +308,15 @@ def filename(name, ext):
@python_2_unicode_compatible
class Patch(models.Model):
project = models.ForeignKey(Project)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
msgid = models.CharField(max_length=255)
name = models.CharField(max_length=255)
date = models.DateTimeField(default=datetime.datetime.now)
last_updated = models.DateTimeField(auto_now=True)
submitter = models.ForeignKey(Person)
delegate = models.ForeignKey(User, blank=True, null=True)
state = models.ForeignKey(State, null=True)
submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
delegate = models.ForeignKey(User, blank=True, null=True,
on_delete=models.CASCADE)
state = models.ForeignKey(State, null=True, on_delete=models.CASCADE)
archived = models.BooleanField(default=False)
headers = models.TextField(blank=True)
content = models.TextField(null=True, blank=True)
......@@ -400,9 +403,9 @@ class Patch(models.Model):
class Comment(models.Model):
patch = models.ForeignKey(Patch)
patch = models.ForeignKey(Patch, on_delete=models.CASCADE)
msgid = models.CharField(max_length=255)
submitter = models.ForeignKey(Person)
submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
date = models.DateTimeField(default=datetime.datetime.now)
headers = models.TextField(blank=True)
content = models.TextField()
......@@ -429,8 +432,8 @@ class Comment(models.Model):
class Bundle(models.Model):
owner = models.ForeignKey(User)
project = models.ForeignKey(Project)
owner = models.ForeignKey(User, on_delete=models.CASCADE)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
name = models.CharField(max_length=50, null=False, blank=False)
patches = models.ManyToManyField(Patch, through='BundlePatch')
public = models.BooleanField(default=False)
......@@ -482,8 +485,8 @@ class Bundle(models.Model):
class BundlePatch(models.Model):
patch = models.ForeignKey(Patch)
bundle = models.ForeignKey(Bundle)
patch = models.ForeignKey(Patch, on_delete=models.CASCADE)
bundle = models.ForeignKey(Bundle, on_delete=models.CASCADE)
order = models.IntegerField()
class Meta:
......@@ -518,17 +521,19 @@ class TestState:
# with the various versions of patches sent to the mailing list.
@python_2_unicode_compatible
class Series(models.Model):
project = models.ForeignKey(Project)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
name = models.CharField(max_length=200, default=SERIES_DEFAULT_NAME)
submitter = models.ForeignKey(Person, related_name='submitters')
submitter = models.ForeignKey(Person, related_name='submitters',
on_delete=models.CASCADE)
reviewer = models.ForeignKey(User, related_name='reviewers', null=True,
blank=True)
blank=True, on_delete=models.CASCADE)
submitted = models.DateTimeField(default=datetime.datetime.now)
last_updated = models.DateTimeField(auto_now=True)
# direct access to the latest revision so we can get the latest revision
# information with a JOIN
last_revision = models.OneToOneField('SeriesRevision', null=True,
related_name='+')
related_name='+',
on_delete=models.CASCADE)
def revisions(self):
return SeriesRevision.objects.filter(series=self)
......@@ -608,7 +613,7 @@ class RevisionState:
@python_2_unicode_compatible
class SeriesRevision(models.Model):
series = models.ForeignKey(Series)
series = models.ForeignKey(Series, on_delete=models.CASCADE)
version = models.IntegerField(default=1)
root_msgid = models.CharField(max_length=255)
cover_letter = models.TextField(null=True, blank=True)
......@@ -687,8 +692,8 @@ class SeriesRevision(models.Model):
class SeriesRevisionPatch(models.Model):
patch = models.ForeignKey(Patch)
revision = models.ForeignKey(SeriesRevision)
patch = models.ForeignKey(Patch, on_delete=models.CASCADE)
revision = models.ForeignKey(SeriesRevision, on_delete=models.CASCADE)
order = models.IntegerField()
class Meta:
......@@ -701,12 +706,12 @@ class Event(models.Model):
class EventLog(models.Model):
event = models.ForeignKey(Event)
event = models.ForeignKey(Event, on_delete=models.CASCADE)
event_time = models.DateTimeField(auto_now=True)
series = models.ForeignKey(Series, null=True)
user = models.ForeignKey(User, null=True)
series = models.ForeignKey(Series, null=True, on_delete=models.CASCADE)
user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
parameters = jsonfield.JSONField(null=True)
patch = models.ForeignKey(Patch, null=True)
patch = models.ForeignKey(Patch, null=True, on_delete=models.CASCADE)
class Meta:
ordering = ['-event_time']
......@@ -742,7 +747,7 @@ class Test(models.Model):
(CONDITION_ON_FAILURE, 'on failure'),
)
project = models.ForeignKey(Project)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
mail_recipient = models.SmallIntegerField(choices=RECIPIENT_CHOICES,
default=RECIPIENT_NONE)
......@@ -771,10 +776,12 @@ class Test(models.Model):
@python_2_unicode_compatible
class TestResult(models.Model):
test = models.ForeignKey(Test)
revision = models.ForeignKey(SeriesRevision, blank=True, null=True)
patch = models.ForeignKey(Patch, blank=True, null=True)
user = models.ForeignKey(User)
test = models.ForeignKey(Test, on_delete=models.CASCADE)
revision = models.ForeignKey(SeriesRevision, blank=True, null=True,
on_delete=models.CASCADE)
patch = models.ForeignKey(Patch, blank=True, null=True,
on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
date = models.DateTimeField(auto_now=True)
state = models.SmallIntegerField(choices=TestState.STATE_CHOICES)
url = models.URLField(blank=True, null=True)
......@@ -795,7 +802,7 @@ class EmailConfirmation(models.Model):
('optout', 'Email opt-out'),
])
email = models.CharField(max_length=200)
user = models.ForeignKey(User, null=True)
user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
key = HashField()
date = models.DateTimeField(default=datetime.datetime.now)
active = models.BooleanField(default=True)
......@@ -829,9 +836,10 @@ class EmailOptout(models.Model):
class PatchChangeNotification(models.Model):
patch = models.OneToOneField(Patch, primary_key=True)
patch = models.OneToOneField(Patch, primary_key=True,
on_delete=models.CASCADE)
last_modified = models.DateTimeField(default=datetime.datetime.now)
orig_state = models.ForeignKey(State)
orig_state = models.ForeignKey(State, on_delete=models.CASCADE)
def _patch_change_log_event(old_patch, new_patch):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment