Database and Schema

Database and Helpers

geordi.data.model

Geordi model grouping module and general database-management tools.

geordi.data.model.create_tables(app)

Initialize tables in the database. Assumes the database already exists and a ‘geordi’ schema is created.

geordi.data.model.db = <SQLAlchemy engine=None>

A shared SQLAlchemy object for use across geordi. Intended to be imported from views, models, etc.

geordi.data.model.mixins

Helpful mixin classes for commonalities between models.

class geordi.data.model.mixins.DeleteMixin

Provides a ‘delete’ method deleting an object from the DB.

delete()

Delete this object from the DB.

Models

Core data

geordi.data.model.item

class geordi.data.model.item.Item(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘item’ table, storing item type information and mapped data.

id

Integer ID of this item.

type

Nominal type guess for this item.

map

Mapped data for this item, JSON.

item_data

Property for data items linked to this item. Included by default when loading.

item_redirects

Property for redirects to this item.

Property for links from this item to other items. Included by default when loading.

items_linked

Property for links from other items to this item. Not loaded by default.

raw_matches

Property for matches of this item to MusicBrainz entities.

map_dict
to_dict()
classmethod get(item_id, **kwargs)
classmethod create(type=None, map=None)

geordi.data.model.item_data

class geordi.data.model.item_data.ItemData(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘item_data’ table, storing index-specific raw data.

id

Data item identifier of the form (index)/(item type)/(identifier).

item_id

Item ID of the item to which this data item belongs.

data

Raw JSON data.

to_dict()
classmethod get(id, **kwargs)
classmethod get_by_item_id(item_id, **kwargs)
classmethod data_to_item(data_id)

Resolve a data ID to its associated item ID, if it has one (it should).

classmethod create(item_id, data_json, data_id)
classmethod update(item_id, data, data_id)
static get_indexes()
static get_item_types_by_index(index)
static get_item_ids(index, item_type)
static delete_data_item(data_id)

geordi.data.model.item_redirect

class geordi.data.model.item_redirect.ItemRedirect(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘item_redirect’ table, storing the old IDs of items that have been merged.

old_id

The obsolete item ID which should be redirected.

new_id

The item ID to which it should be redirected.

Matches and entities

geordi.data.model.raw_match

class geordi.data.model.raw_match.RawMatch(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘raw_match’ table, storing matches between items and MusicBrainz entities.

id

A unique ID for the match.

item_id

The item ID for the item this match is for.

editor_name

The editor name for the editor who created this match.

timestamp

The time when the match was made.

superseded

Boolean, false if this match is current, true if it should be considered historical only.

entities

Property for raw match entities linking this match to MusicBrainz entities.

classmethod get_by_item(item_id, **kwargs)
classmethod match_item(item_id, editor_name, entities)
to_dict()

geordi.data.model.raw_match_entity

class geordi.data.model.raw_match_entity.RawMatchEntity(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘raw_match_entity’ table, storing the link between matches and materialized entity data.

raw_match_id

The ID of the match.

entity_mbid

The MBID of the entity.

geordi.data.model.entity

class geordi.data.model.entity.Entity(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘entity’ table, storing materialized information about entities in MusicBrainz.

mbid

The entity’s MBID.

type

The type of entity (e.g. ‘release’, ‘release_group’, ‘artist’, etc.

data

Materialized JSON data used to display a link (e.g. the name or title).

raw_match_entities

Property for matches using this entity.

classmethod get(mbid, **kwargs)
classmethod get_remote(mbid, **kwargs)
merge_into(target)
to_dict()

Editors and login

geordi.data.model.csrf

class geordi.data.model.csrf.CSRF(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘csrf’ table, storing information about users who may be logging in via MusicBrainz OAuth.

ip

The user’s IP, after stripping away known/trusted proxies.

csrf

The random csrf value passed as the ‘state’ to MusicBrainz’s OAuth.

opts

JSON representation of user options, e.g. ‘remember me’ and the URL to return to.

timestamp

Timestamp for when this was allocated, used for automatic removal.

classmethod get(csrf, **kwargs)
classmethod update_csrf(ip, rand)

Called with an ip and a random value to be used as a csrf. Inserts this into the DB and automatically deletes other values for this IP older than 1 hour.

geordi.data.model.editor

class geordi.data.model.editor.Editor(**kwargs)

Bases: flask_sqlalchemy.Model, geordi.data.model.mixins.DeleteMixin

Model for the ‘editor’ table, storing information about both human users and automated processes which match items.

name

Editor name from MusicBrainz, or a descriptive name for an automated process.

tz

For human editors, timezone preference.

internal

Boolean; True for automated processes, otherwise False.

matches

Property for matches entered by this user. Not loaded by default.

classmethod get(name, **kwargs)
classmethod add_or_update(name, tz=None)

Given a name and optionally a timezone, either insert a new row, update the timezone preference, or do nothing, depending on what’s already stored.