fairdm.management.commands.upgrade_vocabularies#
Move a database from django-research-vocabs to terms stored by their vocabulary addresses.
Module Contents#
Classes#
Convert a database that stored terms with django-research-vocabs. |
Data#
API#
- FAIRDM_VOCABULARIES#
None
- LEGACY_TABLES#
(‘research_vocabs_concept’, ‘research_vocabs_vocabulary’)
- class Command(stdout=None, stderr=None, no_color=False, force_color=False)#
Bases:
django.core.management.base.BaseCommandConvert a database that stored terms with django-research-vocabs.
django-research-vocabs stored a term in a model’s own column by its name, such as
Abstractorunknown, and kept keywords and roles in its own tables. This command stores each term as the address of the same concept in the vocabularies the site has loaded, matching a stored name to a concept’sskos:notation. A keyword or role from one of FairDM’s own vocabularies is matched by notation too, and one from any other vocabulary by the address django-research-vocabs held for it.Every stored value is matched before anything is written. If any value has no match, the command lists them all and changes nothing. Run it before
migrate. A database created with this release needs none of it.Initialization
- help#
‘Store the terms django-research-vocabs held as the addresses of the same concepts. Load the vocabula…’
- add_arguments(parser)#
Add
--database.
- handle(*args, database, **options)#
Upgrade the database in one transaction, or change nothing.
- create_vocabulary_tables(connection)#
Apply django-controlled-vocabularies’ own migrations, which nothing else needs.
migraterefuses this database while its FairDM migrations are recorded and the ones they now depend on are not, so the tables the vocabularies load into are made here, from an empty state, asmigratewould.Args: connection: The connection to the database being upgraded.
- models_to_upgrade(database)#
Yield every installed model this database holds a table for.
Args: database: The alias of the database being upgraded.
Yields: Each managed, concrete model migrations would create on it.
- legacy_columns(connection, database)#
Find each concept field whose column still holds a term’s name.
Args: connection: The connection to the database being upgraded. database: Its alias.
Returns: One
(model, field, length)triple per field,lengthbeing the old column’s size. A model whose table does not exist yet is skipped:migratecreates it with the new schema, so it has nothing to convert.
- legacy_tables(connection, database)#
Find each concept set whose table still points at django-research-vocabs.
Args: connection: The connection to the database being upgraded. database: Its alias.
Returns: The
MultiConceptFieldof each such table. A table that does not exist yet is skipped, as inlegacy_columns.
- admitted(field, database)#
Return the concepts a field admits, as
{notation: address}and a set of addresses.Args: field: A
ConceptFieldorMultiConceptField. database: The alias of the database being upgraded.Returns: A
(by_notation, addresses)pair over the concepts the field may hold.
- match_columns(cursor, database, fields)#
Match every distinct value of each old column to a concept the field admits.
Args: cursor: A cursor on the database being upgraded. database: Its alias. fields: The
(model, field)pairs whose columns still hold names.Returns: The
(model, field, {old: address})updates, and one line per value with no match.
- match_tables(cursor, database, tables)#
Match every keyword and role held in django-research-vocabs’ tables to a concept.
Args: cursor: A cursor on the database being upgraded. database: Its alias. tables: The fields from :meth:
legacy_tables.Returns:
{field: [(owner id, address)]}, and one line per term with no match.
- through_columns(field)#
Name the columns of a concept set’s table: the owner’s and the concept’s.
Args: field: A
MultiConceptField.Returns: The
(owner column, concept column)pair.
- wide_column(model, field)#
Return the old column as text wide enough for an address.
Args: model: The model the field belongs to. field: The concept field.
Returns: An unsaved
CharFieldon the old column, the size of an address.
- widen(editor, model, field, length)#
Make the old column wide enough to hold an address.
Args: editor: The schema editor to alter the table with. model: The model the field belongs to. field: The concept field. length: The old column’s size.