mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
chore: add command to migrate from fs to S3
This commit is contained in:
parent
14e74d15c1
commit
834970b725
1 changed files with 29 additions and 0 deletions
29
umap/management/commands/migrate_to_S3.py
Normal file
29
umap/management/commands/migrate_to_S3.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from umap.models import DataLayer
|
||||||
|
from umap.storage import UmapFileSystem
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Migrate latest datalayers from filesystem to S3."
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
assert settings.UMAP_READONLY, "You must run that script with a read-only uMap."
|
||||||
|
assert (
|
||||||
|
settings.STORAGES["data"]["BACKEND"] == "umap.storage.UmapS3"
|
||||||
|
), "You must configure your storages to point to S3"
|
||||||
|
fs_storage = UmapFileSystem()
|
||||||
|
for datalayer in DataLayer.objects.all():
|
||||||
|
geojson_fs_path = str(datalayer.geojson)
|
||||||
|
try:
|
||||||
|
datalayer.geojson.save(
|
||||||
|
datalayer.geojson.name, fs_storage.open(geojson_fs_path)
|
||||||
|
)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(e)
|
||||||
|
print(geojson_fs_path, "not found on disk")
|
||||||
|
continue
|
||||||
|
if options["verbosity"] > 1:
|
||||||
|
print("Migrated:", geojson_fs_path)
|
||||||
|
datalayer.save(force_update=True)
|
Loading…
Reference in a new issue