Пример #1
0
 def test_non_composite_fk(self):
     paths, _, models, _ = generate_update_map()
     for table_paths in paths.values():
         for core_name, path in table_paths:
             model, _ = second_last_model_in_path(SCHEMA[core_name].model, path)
             if path:
                 prop_name = path.split(".")[-1]
                 try:
                     prop = getattr(model, prop_name).prop
                 except AttributeError:
                     pass
                 else:
                     if isinstance(prop, RelationshipProperty):
                         if prop.direction.name == 'MANYTOONE':
                             self.assertEqual(len(prop.local_columns), 1)
Пример #2
0
 def test_non_composite_fk(self):
     paths, _, models, _ = generate_update_map()
     for table_paths in paths.values():
         for core_name, path in table_paths:
             model, _ = second_last_model_in_path(SCHEMA[core_name].model,
                                                  path)
             if path:
                 prop_name = path.split(".")[-1]
                 try:
                     prop = getattr(model, prop_name).prop
                 except AttributeError:
                     pass
                 else:
                     if isinstance(prop, RelationshipProperty):
                         if prop.direction.name == 'MANYTOONE':
                             self.assertEqual(len(prop.local_columns), 1)
Пример #3
0
from functools import partial, wraps
from logging import getLogger
from retrying import retry
from socket import error as socket_error
from sqlalchemy.orm import class_mapper
from sys import exit
from urllib2 import URLError
from ConfigParser import NoOptionError
from collections import defaultdict
from traceback import format_exc

__all__ = ["callback_wrapper", "watch", "Handler"]

logger = getLogger("sir")

update_map, column_map, model_map, core_map = generate_update_map()

#: The number of times we'll try to process a message.
_DEFAULT_MB_RETRIES = 4

#: The number of seconds between each connection attempt to the AMQP server.
_RETRY_WAIT_SECS = 30

# Tables which are core entities, but do not have a guid.
# These will be deleted via their `id`.
_ID_DELETE_TABLE_NAMES = ['annotation', 'tag', 'release_raw', 'editor']


class INDEX_LIMIT_EXCEEDED(Exception):
    def __init__(self, core_name, total_ids, extra_data=None):
        exception_message = 'Index limit exceeded.'
Пример #4
0
# Copyright (c) Wieland Hoffmann
# License: MIT, see LICENSE for details
from sir.schema import SCHEMA, generate_update_map
from sir.trigger_generation.paths import unique_split_paths, last_model_in_path
from sir.trigger_generation import sql_generator
from sqlalchemy.orm import class_mapper
import collections

column_map = generate_update_map()[1]


def generate_func(args):
    """
    This is the entry point for this trigger_generation module. This function
    gets called from :func:`~sir.__main__.main`.
    """
    generate(
        trigger_filename=args["trigger_file"],
        function_filename=args["function_file"],
        broker_id=args["broker_id"],
    )


def generate(trigger_filename, function_filename, broker_id):
    """Generates SQL queries that create and remove triggers for the MusicBrainz database.

    Generation works in the following way:

        1. Determine which tables need to have triggers on them:
            * Entity tables themselves
            * Tables in every path of entity's fields
Пример #5
0
# Copyright (c) Wieland Hoffmann
# License: MIT, see LICENSE for details
from sir.schema import SCHEMA, generate_update_map
from sir.trigger_generation.paths import unique_split_paths, last_model_in_path
from sir.trigger_generation import sql_generator
from sqlalchemy.orm import class_mapper
import collections

column_map = generate_update_map()[1]


def generate_func(args):
    """
    This is the entry point for this trigger_generation module. This function
    gets called from :func:`~sir.__main__.main`.
    """
    generate(
        trigger_filename=args["trigger_file"],
        function_filename=args["function_file"],
        broker_id=args["broker_id"],
    )


def generate(trigger_filename, function_filename, broker_id):
    """Generates SQL queries that create and remove triggers for the MusicBrainz database.

    Generation works in the following way:

        1. Determine which tables need to have triggers on them:
            * Entity tables themselves
            * Tables in every path of entity's fields
Пример #6
0
from logging import getLogger
from retrying import retry
from socket import error as socket_error
from sqlalchemy.orm import class_mapper
from sys import exit
from urllib2 import URLError
from ConfigParser import NoOptionError
from collections import defaultdict
from traceback import format_exc


__all__ = ["callback_wrapper", "watch", "Handler"]

logger = getLogger("sir")

update_map, column_map, model_map, core_map = generate_update_map()

#: The number of times we'll try to process a message.
_DEFAULT_MB_RETRIES = 4

#: The number of seconds between each connection attempt to the AMQP server.
_RETRY_WAIT_SECS = 30

# Tables which are core entities, but do not have a guid.
# These will be deleted via their `id`.
_ID_DELETE_TABLE_NAMES = ['annotation', 'tag', 'release_raw', 'editor']


class INDEX_LIMIT_EXCEEDED(Exception):

    def __init__(self, core_name, total_ids, extra_data=None):