-
Notifications
You must be signed in to change notification settings - Fork 12
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
32 changed files
with
555 additions
and
696 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
91 changes: 91 additions & 0 deletions
91
dandiapi/api/migrations/0008_remove_embargoedassetblob_dandiset_and_more.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,91 @@ | ||
# Generated by Django 4.1.13 on 2024-01-16 18:31 | ||
from __future__ import annotations | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def migrate_embargoed_asset_blobs(apps, _): | ||
Asset = apps.get_model('api.Asset') | ||
AssetBlob = apps.get_model('api.AssetBlob') | ||
|
||
# We must include a filter to only include assets which are part of a version, as otherwise | ||
# we may include an embargoed asset which has been previously updated. Since updating an asset | ||
# results in a new asset which points to the same blob as the original asset, this would copy | ||
# the same blob twice, resulting in an integrity error (same blob_id). | ||
embargoed_assets = Asset.objects.filter( | ||
embargoed_blob__isnull=False, versions__isnull=False | ||
).select_related('embargoed_blob') | ||
|
||
# For each relevant asset, create a new asset blob with embargoed=True, | ||
# and point the asset to that | ||
for asset in embargoed_assets.iterator(): | ||
blob_id = str(asset.embargoed_blob.blob_id) | ||
new_blob_location = f'blobs/{blob_id[0:3]}/{blob_id[3:6]}/{blob_id}' | ||
new_asset_blob = AssetBlob.objects.create( | ||
embargoed=True, | ||
blob=new_blob_location, | ||
blob_id=asset.embargoed_blob.blob_id, | ||
created=asset.embargoed_blob.created, | ||
modified=asset.embargoed_blob.modified, | ||
sha256=asset.embargoed_blob.sha256, | ||
etag=asset.embargoed_blob.etag, | ||
size=asset.embargoed_blob.size, | ||
download_count=asset.embargoed_blob.download_count, | ||
) | ||
asset.blob = new_asset_blob | ||
asset.embargoed_blob = None | ||
asset.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('api', '0007_alter_asset_options_alter_version_options'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='assetblob', | ||
name='embargoed', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='upload', | ||
name='embargoed', | ||
field=models.BooleanField(default=False), | ||
), | ||
# Migrate all embargoedassetblobs and embargoeduploads to other models with embargoed=True | ||
migrations.RunPython(migrate_embargoed_asset_blobs), | ||
migrations.RemoveField( | ||
model_name='embargoedassetblob', | ||
name='dandiset', | ||
), | ||
migrations.RemoveField( | ||
model_name='embargoedupload', | ||
name='dandiset', | ||
), | ||
migrations.RemoveConstraint( | ||
model_name='asset', | ||
name='exactly-one-blob', | ||
), | ||
migrations.RemoveField( | ||
model_name='asset', | ||
name='embargoed_blob', | ||
), | ||
migrations.AddConstraint( | ||
model_name='asset', | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
models.Q(('blob__isnull', True), ('zarr__isnull', False)), | ||
models.Q(('blob__isnull', False), ('zarr__isnull', True)), | ||
_connector='OR', | ||
), | ||
name='blob-xor-zarr', | ||
), | ||
), | ||
migrations.DeleteModel( | ||
name='EmbargoedAssetBlob', | ||
), | ||
migrations.DeleteModel( | ||
name='EmbargoedUpload', | ||
), | ||
] |
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.