示例#1
0
 def _process_user_mappings(self) -> typing.NoReturn:
     for _schema, name, definition in self._iterate_files(
             constants.USER_MAPPING):
         if 'sql' in definition:
             sql = [definition['sql'].strip()]
         else:
             sql = [
                 'CREATE USER MAPPING FOR',
                 utils.quote_ident(definition['user']), 'SERVER',
                 utils.quote_ident(definition['server'])
             ]
             if 'options' in definition:
                 sql.append('OPTIONS')
                 sql.append('({})'.format(', '.join([
                     "{} '{}'".format(k, v)
                     for k, v in definition['options'].items()
                 ])))
         entry = self._dump.add_entry(desc=constants.USER_MAPPING,
                                      dump_id=self._next_dump_id(),
                                      tag=definition.get('name', name),
                                      owner=definition.get(
                                          'owner', self._project.superuser),
                                      defn='{};\n'.format(' '.join(sql)))
         self._maybe_add_comment(entry, definition)
         self._objects += 1
         self._processed.add(entry.dump_id)
示例#2
0
 def _process_servers(self) -> typing.NoReturn:
     for _schema, name, definition in self._iterate_files(constants.SERVER):
         if 'sql' in definition:
             sql = '{}\n'.format(definition['sql']).strip()
         else:
             sql = [
                 'CREATE SERVER IF NOT EXISTS {}'.format(
                     utils.quote_ident(definition.get('name', name)))
             ]
             if 'type' in definition:
                 sql.append("TYPE '{}'".format(definition['type']))
             if 'version' in definition:
                 sql.append("VERSION '{}'".format(definition['version']))
             sql.append('FOREIGN DATA WRAPPER {}'.format(
                 utils.quote_ident(definition['fdw'])))
             if 'options' in definition:
                 sql.append('OPTIONS ({})'.format(', '.join([
                     "{} '{}'".format(k, v)
                     for k, v in definition['options'].items()
                 ])))
         entry = self._add_generic_item(
             constants.FOREIGN_DATA_WRAPPER, '',
             definition.get('name', name), sql,
             definition.get('owner', self._project.superuser))
         self._maybe_add_comment(entry, definition)
示例#3
0
 def _process_fdws(self) -> typing.NoReturn:
     for _schema, name, definition in self._iterate_files(
             constants.FOREIGN_DATA_WRAPPER):
         if 'sql' in definition:
             sql = [definition['sql'].strip()]
         else:
             sql = [
                 'CREATE FOREIGN DATA WRAPPER',
                 utils.quote_ident(definition.get('name', name))
             ]
             if 'handler' in definition:
                 sql.append('HANDLER')
                 sql.append(utils.quote_ident(definition['handler']))
             else:
                 sql.append('NO HANDLER')
             if 'validator' in definition:
                 sql.append('VALIDATOR')
                 sql.append(utils.quote_ident(definition['validator']))
             else:
                 sql.append('NO VALIDATOR')
             if 'options' in definition:
                 sql.append('OPTIONS')
                 sql.append('({})'.format(', '.join([
                     "{} '{}'".format(k, v)
                     for k, v in definition['options'].items()
                 ])))
         entry = self._add_generic_item(
             constants.FOREIGN_DATA_WRAPPER, '',
             definition.get('name', name), '{};\n'.format(' '.join(sql)),
             definition.get('owner', self._project.superuser))
         self._maybe_add_comment(entry, definition)
         self._objects += 1
示例#4
0
    def _process_schemas(self) -> typing.NoReturn:
        # Add the public schema
        self._add_generic_item(constants.SCHEMA, '', 'public',
                               '-- No DDL required', self._project.superuser)

        for schema, _name, definition in self._iterate_files(constants.SCHEMA):
            name = definition.get('name', schema)
            if name == 'public':
                LOGGER.warning('Skipping project declared public schema')
                continue
            if 'sql' in definition:
                sql = '{}\n'.format(definition['sql']).strip()
            else:
                sql = ['CREATE SCHEMA IF NOT EXISTS', utils.quote_ident(name)]
                if definition.get('authorization'):
                    sql.append('AUTHORIZATION')
                    sql.append(utils.quote_ident(definition['authorization']))
            entry = self._add_generic_item(constants.SCHEMA, '', name, sql,
                                           definition.get('owner'))
            self._maybe_add_comment(entry, definition)
示例#5
0
 def _process_extensions(self) -> typing.NoReturn:
     for extension in self._project.extensions:
         schema = extension.get('schema', '')
         sql = [
             'CREATE EXTENSION IF NOT EXISTS',
             utils.quote_ident(extension['name'])
         ]
         if schema:
             sql.append('WITH SCHEMA')
             sql.append(schema)
         entry = self._add_generic_item(constants.EXTENSION, schema,
                                        extension['name'],
                                        '{};\n'.format(' '.join(sql)))
         self._maybe_add_comment(entry, extension)
示例#6
0
 def _process_languages(self) -> typing.NoReturn:
     for language in self._project.languages:
         sql = ['CREATE']
         if language.get('replace'):
             sql.append('OR REPLACE')
         if language.get('trusted'):
             sql.append('TRUSTED')
         if language.get('procedural'):
             sql.append('PROCEDURAL')
         sql.append('LANGUAGE')
         sql.append(utils.quote_ident(language['name']))
         if language.get('handler'):
             sql.append('HANDLER')
             sql.append(utils.quote_ident(language['handler']))
         if language.get('inline_handler'):
             sql.append('INLINE')
             sql.append(utils.quote_ident(language['inline_handler']))
         if language.get('validator'):
             sql.append('VALIDATOR')
             sql.append(utils.quote_ident(language['validator']))
         entry = self._add_generic_item(constants.PROCEDURAL_LANGUAGE, '',
                                        language['name'],
                                        '{};'.format(' '.join(sql)))
         self._maybe_add_comment(entry, language)