Beispiel #1
0
 def initialize_schema(self):
     # Create schema
     here = os.path.abspath(os.path.dirname(__file__))
     schema = open(os.path.join(here, 'schema.sql')).read()
     # Since called outside request, force commit.
     with self.client.connect(force_commit=True) as conn:
         conn.execute(schema)
     logger.info('Created PostgreSQL cache tables')
Beispiel #2
0
 def initialize_schema(self):
     # Create schema
     here = os.path.abspath(os.path.dirname(__file__))
     schema = open(os.path.join(here, 'schema.sql')).read()
     # Since called outside request, force commit.
     with self.client.connect(force_commit=True) as conn:
         conn.execute(schema)
     logger.info('Created PostgreSQL permission tables')
Beispiel #3
0
    def initialize_schema(self, dry_run=False):
        # Check if user_principals table exists.
        query = """
        SELECT 1
          FROM information_schema.tables
         WHERE table_name = 'user_principals';
        """
        with self.client.connect(readonly=True) as conn:
            result = conn.execute(query)
            if result.rowcount > 0:
                logger.info("PostgreSQL permission schema is up-to-date.")
                return

        # Create schema
        here = os.path.abspath(os.path.dirname(__file__))
        sql_file = os.path.join(here, 'schema.sql')

        if dry_run:
            logger.info("Create permission schema from %s" % sql_file)
            return

        # Since called outside request, force commit.
        schema = open(sql_file).read()
        with self.client.connect(force_commit=True) as conn:
            conn.execute(schema)
        logger.info('Created PostgreSQL permission tables')
Beispiel #4
0
    def initialize_schema(self, dry_run=False):
        # Check if user_principals table exists.
        query = """
        SELECT 1
          FROM information_schema.tables
         WHERE table_name = 'user_principals';
        """
        with self.client.connect(readonly=True) as conn:
            result = conn.execute(query)
            if result.rowcount > 0:
                logger.info("PostgreSQL permission schema is up-to-date.")
                return

        # Create schema
        here = os.path.abspath(os.path.dirname(__file__))
        sql_file = os.path.join(here, 'schema.sql')

        if dry_run:
            logger.info("Create permission schema from %s" % sql_file)
            return

        # Since called outside request, force commit.
        schema = open(sql_file).read()
        with self.client.connect(force_commit=True) as conn:
            conn.execute(schema)
        logger.info('Created PostgreSQL permission tables')
Beispiel #5
0
    def initialize_schema(self):
        """Create PostgreSQL tables, and run necessary schema migrations.

        .. note::

            Relies on JSONB fields, available in recent versions of PostgreSQL.
        """
        version = self._get_installed_version()
        if not version:
            # Create full schema.
            self._check_database_encoding()
            self._check_database_timezone()
            # Create full schema.
            self._execute_sql_file('schema.sql')
            logger.info('Created PostgreSQL storage tables '
                        '(version %s).' % self.schema_version)
            return

        logger.debug('Detected PostgreSQL schema version %s.' % version)
        migrations = [(v, v + 1) for v in range(version, self.schema_version)]
        if not migrations:
            logger.info('Schema is up-to-date.')

        for migration in migrations:
            # Check order of migrations.
            expected = migration[0]
            current = self._get_installed_version()
            error_msg = "Expected version %s. Found version %s."
            if expected != current:
                raise AssertionError(error_msg % (expected, current))

            logger.info('Migrate schema from version %s to %s.' % migration)
            filepath = 'migration_%03d_%03d.sql' % migration
            self._execute_sql_file(os.path.join('migrations', filepath))

        logger.info('Schema migration done.')
Beispiel #6
0
 def __call__(self, event):
     try:
         logger.info(json.dumps(event.payload))
     except TypeError:
         logger.error("Unable to dump the payload", exc_info=True)
         return
Beispiel #7
0
    def initialize_schema(self, dry_run=False):
        """Create PostgreSQL tables, and run necessary schema migrations.

        .. note::

            Relies on JSONB fields, available in recent versions of PostgreSQL.
        """
        here = os.path.abspath(os.path.dirname(__file__))

        version = self._get_installed_version()
        if not version:
            filepath = os.path.join(here, 'schema.sql')
            logger.info("Create PostgreSQL storage schema at version "
                        "%s from %s" % (self.schema_version, filepath))
            # Create full schema.
            self._check_database_encoding()
            self._check_database_timezone()
            # Create full schema.
            if not dry_run:
                self._execute_sql_file(filepath)
                logger.info('Created PostgreSQL storage schema '
                            '(version %s).' % self.schema_version)
            return

        logger.info('Detected PostgreSQL storage schema version %s.' % version)
        migrations = [(v, v + 1) for v in range(version, self.schema_version)]
        if not migrations:
            logger.info('PostgreSQL storage schema is up-to-date.')
            return

        for migration in migrations:
            # Check order of migrations.
            expected = migration[0]
            current = self._get_installed_version()
            error_msg = "Expected version %s. Found version %s."
            if not dry_run and expected != current:
                raise AssertionError(error_msg % (expected, current))

            logger.info('Migrate PostgreSQL storage schema from'
                        ' version %s to %s.' % migration)
            filename = 'migration_%03d_%03d.sql' % migration
            filepath = os.path.join(here, 'migrations', filename)
            logger.info("Execute PostgreSQL storage migration"
                        " from %s" % filepath)
            if not dry_run:
                self._execute_sql_file(filepath)
        logger.info("PostgreSQL storage schema migration " +
                    ("simulated." if dry_run else "done."))
Beispiel #8
0
    def initialize_schema(self, dry_run=False):
        """Create PostgreSQL tables, and run necessary schema migrations.

        .. note::

            Relies on JSONB fields, available in recent versions of PostgreSQL.
        """
        here = os.path.abspath(os.path.dirname(__file__))

        version = self._get_installed_version()
        if not version:
            filepath = os.path.join(here, 'schema.sql')
            logger.info("Create PostgreSQL storage schema at version "
                        "%s from %s" % (self.schema_version, filepath))
            # Create full schema.
            self._check_database_encoding()
            self._check_database_timezone()
            # Create full schema.
            if not dry_run:
                self._execute_sql_file(filepath)
                logger.info('Created PostgreSQL storage schema '
                            '(version %s).' % self.schema_version)
            return

        logger.info('Detected PostgreSQL storage schema version %s.' % version)
        migrations = [(v, v + 1) for v in range(version, self.schema_version)]
        if not migrations:
            logger.info('PostgreSQL storage schema is up-to-date.')
            return

        for migration in migrations:
            # Check order of migrations.
            expected = migration[0]
            current = self._get_installed_version()
            error_msg = "Expected version %s. Found version %s."
            if not dry_run and expected != current:
                raise AssertionError(error_msg % (expected, current))

            logger.info('Migrate PostgreSQL storage schema from'
                        ' version %s to %s.' % migration)
            filename = 'migration_%03d_%03d.sql' % migration
            filepath = os.path.join(here, 'migrations', filename)
            logger.info("Execute PostgreSQL storage migration"
                        " from %s" % filepath)
            if not dry_run:
                self._execute_sql_file(filepath)
        logger.info("PostgreSQL storage schema migration " +
                    ("simulated." if dry_run else "done."))