-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow possibility to add version to schema metadata (#2600)
- Loading branch information
1 parent
32d906a
commit dd7bc85
Showing
10 changed files
with
204 additions
and
32 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
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
32 changes: 32 additions & 0 deletions
32
udata/migrations/2021-04-08-update-schema-with-new-structure.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,32 @@ | ||
''' | ||
The purpose here is to update every resource's metadata 'schema' | ||
with a new format (string to object) | ||
''' | ||
import logging | ||
|
||
from udata.models import Dataset | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def migrate(db): | ||
log.info('Processing resources.') | ||
|
||
datasets = Dataset.objects().no_cache().timeout(False) | ||
for dataset in datasets: | ||
save_res = False | ||
for resource in dataset.resources: | ||
if hasattr(resource, 'schema'): | ||
schema = resource.schema | ||
resource.schema = {'name': None} | ||
if schema is not None and isinstance(schema, str): | ||
resource.schema = {'name': schema} | ||
save_res = True | ||
if save_res: | ||
try: | ||
dataset.save() | ||
except Exception as e: | ||
log.warning(e) | ||
pass | ||
|
||
log.info('Completed.') |
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