-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
specifyweb/workbench/migrations/0006_spdatasetattachment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Generated by Django 3.2.15 on 2025-02-25 16:43 | ||
''' | ||
This migration creates the spdatasetattachment table and adds it to the schema config. | ||
''' | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import specifyweb.specify.models | ||
from specifyweb.specify.migration_utils.update_schema_config import revert_table_field_schema_config, update_table_field_schema_config_with_defaults | ||
|
||
MIGRATION_0006_FIELDS = { | ||
'SpdatasetAttachment': [ | ||
('id', 'id', 'id'), | ||
('ordinal', 'ordinal', 'ordinal'), | ||
('remarks', 'remarks', 'remarks'), | ||
('timestampcreated', 'timestampcreated', 'timestampcreated'), | ||
('timestampmodified', 'timestampmodified', 'timestampmodified'), | ||
('version', 'version', 'version'), | ||
('attachment', 'attachment', 'attachment'), | ||
('createdbyagent', 'createdbyagent', 'createdbyagent'), | ||
('modifiedbyagent', 'modifiedbyagent', 'modifiedbyagent'), | ||
('storage', 'storage', 'storage'), | ||
], | ||
} | ||
|
||
def create_spdatasetattachment(apps): | ||
migrations.CreateModel( | ||
name='SpdatasetAttachment', | ||
fields=[ | ||
('id', models.AutoField(db_column='spdatasetattachmentid', primary_key=True, serialize=False)), | ||
('ordinal', models.IntegerField(db_column='Ordinal')), | ||
('remarks', models.TextField(blank=True, db_column='Remarks', null=True)), | ||
('timestampcreated', models.DateTimeField(db_column='TimestampCreated', default=django.utils.timezone.now)), | ||
('timestampmodified', models.DateTimeField(blank=True, db_column='TimestampModified', default=django.utils.timezone.now, null=True)), | ||
('version', models.IntegerField(blank=True, db_column='Version', default=0, null=True)), | ||
('attachment', models.ForeignKey(db_column='AttachmentID', on_delete=specifyweb.specify.models.protect_with_blockers, related_name='spdatasetattachments', to='specify.attachment')), | ||
('createdbyagent', models.ForeignKey(db_column='CreatedByAgentID', null=True, on_delete=specifyweb.specify.models.protect_with_blockers, related_name='+', to='specify.agent')), | ||
('modifiedbyagent', models.ForeignKey(db_column='ModifiedByAgentID', null=True, on_delete=specifyweb.specify.models.protect_with_blockers, related_name='+', to='specify.agent')), | ||
('spdataset', models.ForeignKey(db_column='id', on_delete=django.db.models.deletion.CASCADE, related_name='spdatasetattachments', to='workbench.spdataset')), | ||
], | ||
options={ | ||
'db_table': 'spdatasetattachment', | ||
'ordering': (), | ||
}, | ||
), | ||
|
||
def reverse_create_spdatasetattachment(apps): | ||
migrations.DeleteModel( | ||
name='SpdatasetAttachment', | ||
), | ||
|
||
def create_spdatasetattachment_splocalecontaineritem(apps): | ||
Discipline = apps.get_model('specify', 'Discipline') | ||
for discipline in Discipline.objects.all(): | ||
for table, fields in MIGRATION_0006_FIELDS.items(): | ||
for field in fields: | ||
update_table_field_schema_config_with_defaults( | ||
table, discipline.id, field, apps) | ||
|
||
def reverse_create_spdatasetattachment_splocalecontaineritem(apps): | ||
for table, fields in MIGRATION_0006_FIELDS.items(): | ||
for field in fields: | ||
revert_table_field_schema_config(table, field, apps) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('specify', '0023_update_schema_config_text'), | ||
('workbench', '0005_auto_20210428_1634'), | ||
] | ||
|
||
def apply_migration(apps, schema_editor): | ||
create_spdatasetattachment(apps) | ||
create_spdatasetattachment_splocalecontaineritem(apps) | ||
|
||
def revert_migration(apps, schema_editor): | ||
reverse_create_spdatasetattachment(apps) | ||
reverse_create_spdatasetattachment_splocalecontaineritem(apps) | ||
|
||
operations = [ | ||
migrations.RunPython(apply_migration, revert_migration, atomic=True) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters