-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from dandi/remove-metadata-tables
Remove metadata tables
- Loading branch information
Showing
21 changed files
with
255 additions
and
291 deletions.
There are no files selected for viewing
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
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
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
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
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,88 @@ | ||
# Generated by Django 3.2 on 2021-08-09 18:00 | ||
|
||
import django.contrib.postgres.indexes | ||
from django.db import migrations, models | ||
|
||
|
||
def migrate_metadata(apps, schema_editor): | ||
Version = apps.get_model('api', 'Version') # noqa: N806 | ||
Asset = apps.get_model('api', 'Asset') # noqa: N806 | ||
|
||
versions = Version.objects.all() | ||
for version in versions: | ||
version.name = version.old_metadata.name | ||
version.metadata = version.old_metadata.metadata | ||
Version.objects.bulk_update(versions, ['name', 'metadata']) | ||
|
||
assets = Asset.objects.all() | ||
for asset in assets: | ||
asset.metadata = asset.old_metadata.metadata | ||
Asset.objects.bulk_update(assets, ['metadata']) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0015_validation_fields'), | ||
] | ||
|
||
operations = [ | ||
# Move the original metadata fields to old_metadata | ||
migrations.RenameField( | ||
model_name='asset', | ||
old_name='metadata', | ||
new_name='old_metadata', | ||
), | ||
migrations.RenameField( | ||
model_name='version', | ||
old_name='metadata', | ||
new_name='old_metadata', | ||
), | ||
# Create metadata field on Asset | ||
migrations.AddField( | ||
model_name='asset', | ||
name='metadata', | ||
field=models.JSONField(blank=True, default=dict), | ||
), | ||
# Create name and metadata fields on Version | ||
migrations.AddField( | ||
model_name='version', | ||
name='name', | ||
field=models.CharField(default='temporary_name', max_length=300), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='version', | ||
name='metadata', | ||
field=models.JSONField(blank=True, default=dict), | ||
), | ||
migrations.AddIndex( | ||
model_name='version', | ||
index=django.contrib.postgres.indexes.HashIndex( | ||
fields=['metadata'], name='api_version_metadat_f0b8f8_hash' | ||
), | ||
), | ||
migrations.AddIndex( | ||
model_name='version', | ||
index=django.contrib.postgres.indexes.HashIndex( | ||
fields=['name'], name='api_version_name_5d8af6_hash' | ||
), | ||
), | ||
# Move the data from the old_metadata fields to the new metadata fields | ||
migrations.RunPython(migrate_metadata), | ||
# Delete the old_metadata fields | ||
migrations.RemoveField( | ||
model_name='Asset', | ||
name='old_metadata', | ||
), | ||
migrations.RemoveField( | ||
model_name='Version', | ||
name='old_metadata', | ||
), | ||
migrations.DeleteModel( | ||
name='AssetMetadata', | ||
), | ||
migrations.DeleteModel( | ||
name='VersionMetadata', | ||
), | ||
] |
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
from .asset import Asset, AssetBlob, AssetMetadata | ||
from .asset import Asset, AssetBlob | ||
from .dandiset import Dandiset | ||
from .oauth import StagingApplication | ||
from .upload import Upload | ||
from .version import Version, VersionMetadata | ||
from .version import Version | ||
|
||
__all__ = [ | ||
'Asset', | ||
'AssetBlob', | ||
'AssetMetadata', | ||
'Dandiset', | ||
'StagingApplication', | ||
'Upload', | ||
'Version', | ||
'VersionMetadata', | ||
] |
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
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
Oops, something went wrong.