Skip to content

Commit cf77122

Browse files
authored
Merge pull request #94 from aplbrain/93-transfer-to-using-open-data-bucket
created new script to update manifest files after copying over to new…
2 parents a7d0105 + 900949e commit cf77122

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

scripts/rewrite_manifest_files.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Rewrite (update) all manifest files.
3+
4+
This script runs the `write_manifest_files()` function on all dandiset versions, allowing us to
5+
rewrite the manifest files. We needed to run this as a one-time script when we moved from our
6+
development AWS account to the AWS Open Data account, thus changing the AWS S3 bucket our data is
7+
stored in. Currently the asset manifest files (.jsonld and .yaml) contain the name of the bucket, so
8+
this became out of date when we copied the data over and changed the bucket. This script runs an
9+
update on the manifest files, fixing the bucket referenced the asset manifest files.
10+
11+
We are doing this using the heroku CLI to connect to our database and then write_manifest_files()
12+
13+
Usage:
14+
# Open an interactive bash shell inside the heroku dyno for the given app
15+
heroku run -a <heroku_app_name> bash
16+
17+
# Open a Django shell
18+
./manage.py shell_plus
19+
# Run the script by copying and pasting the code
20+
"""
21+
22+
from __future__ import annotations
23+
24+
import click
25+
26+
from dandiapi.api.models import Version
27+
from dandiapi.api.tasks import write_manifest_files
28+
29+
all_versions = Version.objects.values_list('id', flat=True)
30+
all_versions_count = all_versions.count()
31+
click.echo(f'version count is {all_versions_count}')
32+
33+
if all_versions_count > 0:
34+
for version_id in all_versions.iterator():
35+
write_manifest_files.delay(version_id)
36+
else:
37+
click.echo('Found no versions.')

0 commit comments

Comments
 (0)