Skip to content
Snippets Groups Projects
Commit 7e138bbe authored by Samuel GAIST's avatar Samuel GAIST Committed by Flavio TARSETTI
Browse files

[databases][migrations] Pre-commit cleanup

parent 70df561e
No related branches found
No related tags found
2 merge requests!350Cleanup databases,!342Django 3 migration
......@@ -27,99 +27,269 @@
from __future__ import unicode_literals
from django.db import migrations, models
import beat.web.code.models
import beat.web.databases.models
from django.conf import settings
from django.db import migrations
from django.db import models
import beat.web.code.models
import beat.web.common.models
import beat.web.databases.models
class Migration(migrations.Migration):
dependencies = [
('dataformats', '0001_initial'),
("dataformats", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('team', '0001_initial'),
("team", "0001_initial"),
]
operations = [
migrations.CreateModel(
name='Database',
name="Database",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('sharing', models.CharField(default='P', max_length=1, choices=[('P', 'Private'), ('S', 'Shared'), ('A', 'Public'), ('U', 'Usable')])),
('name', models.CharField(help_text='The name for this object (space-like characters will be automatically replaced by dashes)', max_length=200)),
('version', models.PositiveIntegerField(default=1, help_text='The version of this object (an integer starting from 1)')),
('short_description', models.CharField(default='', help_text='Describe the object succinctly (try to keep it under 80 characters)', max_length=100, blank=True)),
('creation_date', models.DateTimeField(auto_now_add=True, verbose_name='Creation date')),
('hash', models.CharField(help_text='Hashed value of the object contents (<a href="https://docs.python.org/2/library/hashlib.html">SHA256, hexadecimal digest</a>). This field is auto-generated and managed by the platform.', max_length=64, editable=False)),
('declaration_file', models.FileField(db_column='declaration', upload_to=beat.web.common.models.get_contribution_declaration_filename, storage=beat.web.databases.models.DatabaseStorage(), max_length=200, blank=True, null=True)),
('description_file', models.FileField(db_column='description', upload_to=beat.web.common.models.get_contribution_description_filename, storage=beat.web.databases.models.DatabaseStorage(), max_length=200, blank=True, null=True)),
('source_code_file', models.FileField(db_column='source_code', upload_to=beat.web.code.models.get_contribution_source_code_filename, storage=beat.web.databases.models.DatabaseStorage(), max_length=200, blank=True, null=True)),
('fork_of', models.ForeignKey(related_name='forks', blank=True, to='databases.Database', null=True, on_delete=models.SET_NULL)),
('previous_version', models.ForeignKey(related_name='next_versions', blank=True, to='databases.Database', null=True, on_delete=models.CASCADE)),
('shared_with', models.ManyToManyField(related_name='shared_databases', to=settings.AUTH_USER_MODEL, blank=True)),
('shared_with_team', models.ManyToManyField(related_name='shared_databases', to='team.Team', blank=True)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
(
"sharing",
models.CharField(
default="P",
max_length=1,
choices=[
("P", "Private"),
("S", "Shared"),
("A", "Public"),
("U", "Usable"),
],
),
),
(
"name",
models.CharField(
help_text="The name for this object (space-like characters will be automatically replaced by dashes)",
max_length=200,
),
),
(
"version",
models.PositiveIntegerField(
default=1,
help_text="The version of this object (an integer starting from 1)",
),
),
(
"short_description",
models.CharField(
default="",
help_text="Describe the object succinctly (try to keep it under 80 characters)",
max_length=100,
blank=True,
),
),
(
"creation_date",
models.DateTimeField(
auto_now_add=True, verbose_name="Creation date"
),
),
(
"hash",
models.CharField(
help_text='Hashed value of the object contents (<a href="https://docs.python.org/2/library/hashlib.html">SHA256, hexadecimal digest</a>). This field is auto-generated and managed by the platform.',
max_length=64,
editable=False,
),
),
(
"declaration_file",
models.FileField(
db_column="declaration",
upload_to=beat.web.common.models.get_contribution_declaration_filename,
storage=beat.web.databases.models.DatabaseStorage(),
max_length=200,
blank=True,
null=True,
),
),
(
"description_file",
models.FileField(
db_column="description",
upload_to=beat.web.common.models.get_contribution_description_filename,
storage=beat.web.databases.models.DatabaseStorage(),
max_length=200,
blank=True,
null=True,
),
),
(
"source_code_file",
models.FileField(
db_column="source_code",
upload_to=beat.web.code.models.get_contribution_source_code_filename,
storage=beat.web.databases.models.DatabaseStorage(),
max_length=200,
blank=True,
null=True,
),
),
(
"fork_of",
models.ForeignKey(
related_name="forks",
blank=True,
to="databases.Database",
null=True,
on_delete=models.SET_NULL,
),
),
(
"previous_version",
models.ForeignKey(
related_name="next_versions",
blank=True,
to="databases.Database",
null=True,
on_delete=models.CASCADE,
),
),
(
"shared_with",
models.ManyToManyField(
related_name="shared_databases",
to=settings.AUTH_USER_MODEL,
blank=True,
),
),
(
"shared_with_team",
models.ManyToManyField(
related_name="shared_databases", to="team.Team", blank=True
),
),
],
),
migrations.CreateModel(
name='DatabaseOutput',
name="DatabaseOutput",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=200)),
('dataformat', models.ForeignKey(related_name='database_outputs', to='dataformats.DataFormat', on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("name", models.CharField(max_length=200)),
(
"dataformat",
models.ForeignKey(
related_name="database_outputs",
to="dataformats.DataFormat",
on_delete=models.CASCADE,
),
),
],
),
migrations.CreateModel(
name='DatabaseProtocol',
name="DatabaseProtocol",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=200, blank=True)),
('database', models.ForeignKey(related_name='protocols', to='databases.Database', on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("name", models.CharField(max_length=200, blank=True)),
(
"database",
models.ForeignKey(
related_name="protocols",
to="databases.Database",
on_delete=models.CASCADE,
),
),
],
options={
'ordering': ['name'],
},
options={"ordering": ["name"]},
),
migrations.CreateModel(
name='DatabaseSet',
name="DatabaseSet",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=200, blank=True)),
('protocol', models.ForeignKey(related_name='sets', to='databases.DatabaseProtocol', on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("name", models.CharField(max_length=200, blank=True)),
(
"protocol",
models.ForeignKey(
related_name="sets",
to="databases.DatabaseProtocol",
on_delete=models.CASCADE,
),
),
],
),
migrations.CreateModel(
name='DatabaseSetTemplate',
name="DatabaseSetTemplate",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(unique=True, max_length=200)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("name", models.CharField(unique=True, max_length=200)),
],
),
migrations.AddField(
model_name='databaseset',
name='template',
field=models.ForeignKey(related_name='sets', to='databases.DatabaseSetTemplate', on_delete=models.CASCADE),
model_name="databaseset",
name="template",
field=models.ForeignKey(
related_name="sets",
to="databases.DatabaseSetTemplate",
on_delete=models.CASCADE,
),
),
migrations.AddField(
model_name='databaseoutput',
name='template',
field=models.ForeignKey(related_name='outputs', to='databases.DatabaseSetTemplate', on_delete=models.CASCADE),
model_name="databaseoutput",
name="template",
field=models.ForeignKey(
related_name="outputs",
to="databases.DatabaseSetTemplate",
on_delete=models.CASCADE,
),
),
migrations.AlterUniqueTogether(
name='databaseset',
unique_together=set([('protocol', 'name', 'template')]),
name="databaseset", unique_together=set([("protocol", "name", "template")]),
),
migrations.AlterUniqueTogether(
name='databaseprotocol',
unique_together=set([('database', 'name')]),
name="databaseprotocol", unique_together=set([("database", "name")]),
),
migrations.AlterUniqueTogether(
name='databaseoutput',
unique_together=set([('template', 'name', 'dataformat')]),
name="databaseoutput",
unique_together=set([("template", "name", "dataformat")]),
),
migrations.AlterUniqueTogether(
name='database',
unique_together=set([('name', 'version')]),
name="database", unique_together=set([("name", "version")]),
),
]
......@@ -23,31 +23,32 @@
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
from __future__ import unicode_literals
from django.db import migrations, models
import logging
from ...common.models import get_declaration
from django.db import migrations
from django.db import models
from ...common.models import get_declaration
from ..models import validate_database
import logging
logger = logging.getLogger(__name__)
def refresh_databases(apps, schema_editor):
'''Refreshes each database so datasets/outputs are recreated'''
"""Refreshes each database so datasets/outputs are recreated"""
Database = apps.get_model("databases", "Database")
DatabaseSetOutput = apps.get_model("databases", "DatabaseSetOutput")
Database.declaration = property(get_declaration)
Database.fullname = lambda self: '%s/%d' % (self.name, self.version)
Database.fullname = lambda self: "%s/%d" % (self.name, self.version)
if Database.objects.count(): print('')
if Database.objects.count():
print("")
for db in Database.objects.order_by('id'):
for db in Database.objects.order_by("id"):
print("Refreshing protocols for database `%s'..." % db.fullname())
core = validate_database(db.declaration)
core.name = db.fullname()
......@@ -55,36 +56,62 @@ def refresh_databases(apps, schema_editor):
for set in proto.sets.all():
for output in set.template.outputs.all():
try:
DatabaseSetOutput(template=output, set=set,
hash=core.hash_output(proto.name, set.name,
output.name)).save()
DatabaseSetOutput(
template=output,
set=set,
hash=core.hash_output(proto.name, set.name, output.name),
).save()
except KeyError:
logger.warn('Database output %s/%d.%s.%s.%s does ' \
'not exist' % (db.name, db.version, proto.name,
set.name, output.name))
logger.warn(
"Database output %s/%d.%s.%s.%s does "
"not exist"
% (db.name, db.version, proto.name, set.name, output.name)
)
continue
class Migration(migrations.Migration):
dependencies = [
('dataformats', '0001_initial'),
('databases', '0001_initial'),
("dataformats", "0001_initial"),
("databases", "0001_initial"),
]
operations = [
migrations.RenameModel('DatabaseOutput', 'DatabaseSetTemplateOutput'),
migrations.RenameModel("DatabaseOutput", "DatabaseSetTemplateOutput"),
migrations.AlterUniqueTogether(
name='databasesettemplateoutput',
unique_together=set([('template', 'name')]),
name="databasesettemplateoutput",
unique_together=set([("template", "name")]),
),
migrations.CreateModel(
name='DatabaseSetOutput',
name="DatabaseSetOutput",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('hash', models.CharField(unique=True, max_length=64)),
('set', models.ForeignKey(related_name='outputs', to='databases.DatabaseSet', on_delete=models.CASCADE)),
('template', models.ForeignKey(related_name='instances', to='databases.DatabaseSetTemplateOutput', on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("hash", models.CharField(unique=True, max_length=64)),
(
"set",
models.ForeignKey(
related_name="outputs",
to="databases.DatabaseSet",
on_delete=models.CASCADE,
),
),
(
"template",
models.ForeignKey(
related_name="instances",
to="databases.DatabaseSetTemplateOutput",
on_delete=models.CASCADE,
),
),
],
),
migrations.RunPython(refresh_databases),
......
......@@ -8,12 +8,11 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('databases', '0002_scheduler_addons'),
("databases", "0002_scheduler_addons"),
]
operations = [
migrations.AlterModelOptions(
name='database',
options={'ordering': ['name', '-version']},
name="database", options={"ordering": ["name", "-version"]},
),
]
......@@ -2,24 +2,22 @@
# Generated by Django 1.9.13 on 2018-01-25 09:06
from __future__ import unicode_literals
from django.db import migrations, models
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
('databases', '0003_auto_20160704_1316'),
("databases", "0003_auto_20160704_1316"),
]
operations = [
migrations.RemoveField(
model_name='databasesetoutput',
name='hash',
),
migrations.RemoveField(model_name="databasesetoutput", name="hash",),
migrations.AddField(
model_name='databaseset',
name='hash',
field=models.CharField(default='', max_length=64),
model_name="databaseset",
name="hash",
field=models.CharField(default="", max_length=64),
preserve_default=False,
),
]
......@@ -2,33 +2,42 @@
# Generated by Django 1.9.13 on 2018-01-25 09:06
from __future__ import unicode_literals
from django.db import migrations, models
from django.db import migrations
from beat.backend.python.hash import hashDataset
def compute_hashes(apps, schema_editor):
'''Refreshes each database so datasets/outputs are recreated'''
"""Refreshes each database so datasets/outputs are recreated"""
DatabaseSet = apps.get_model("databases", "DatabaseSet")
if DatabaseSet.objects.count():
print('')
for db_set in DatabaseSet.objects.order_by('id'):
print("Computing hashes for database set '%s/%d/%s/%s'..." % \
(db_set.protocol.database.name, db_set.protocol.database.version,
db_set.protocol.name, db_set.name))
db_set.hash = hashDataset('%s/%d' % (db_set.protocol.database.name, db_set.protocol.database.version),
db_set.protocol.name, db_set.name)
print("")
for db_set in DatabaseSet.objects.order_by("id"):
print(
"Computing hashes for database set '%s/%d/%s/%s'..."
% (
db_set.protocol.database.name,
db_set.protocol.database.version,
db_set.protocol.name,
db_set.name,
)
)
db_set.hash = hashDataset(
"%s/%d" % (db_set.protocol.database.name, db_set.protocol.database.version),
db_set.protocol.name,
db_set.name,
)
db_set.save()
class Migration(migrations.Migration):
dependencies = [
('databases', '0004_beat_backend_python_1_5_x'),
("databases", "0004_beat_backend_python_1_5_x"),
]
operations = [
......
......@@ -2,19 +2,20 @@
# Generated by Django 1.9.13 on 2018-01-25 09:06
from __future__ import unicode_literals
from django.db import migrations, models
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
('databases', '0005_databaseset_data_migration'),
("databases", "0005_databaseset_data_migration"),
]
operations = [
migrations.AlterField(
model_name='databaseset',
name='hash',
model_name="databaseset",
name="hash",
field=models.CharField(max_length=64, unique=True),
preserve_default=False,
),
......
......@@ -2,7 +2,8 @@
# Generated by Django 1.11.25 on 2020-02-12 11:22
from __future__ import unicode_literals
from django.db import migrations, models
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment