예제 #1
0
    def _get_installed_version(self):
        """Return current version of schema or None if not any found.
        """
        query = "SELECT tablename FROM pg_tables WHERE tablename = 'metadata';"
        with self.client.connect() as conn:
            result = conn.execute(query)
            tables_exist = result.rowcount > 0

        if not tables_exist:
            return

        query = """
        SELECT value AS version
          FROM metadata
         WHERE name = 'storage_schema_version'
         ORDER BY value DESC;
        """
        with self.client.connect() as conn:
            result = conn.execute(query)
            if result.rowcount > 0:
                return int(result.fetchone()['version'])
            else:
                # Guess current version.
                query = "SELECT COUNT(*) FROM metadata;"
                result = conn.execute(query)
                was_flushed = int(result.fetchone()[0]) == 0
                if was_flushed:
                    error_msg = 'Missing schema history: consider version %s.'
                    logger.warning(error_msg % self.schema_version)
                    return self.schema_version

                # In the first versions of Cliquet, there was no migration.
                return 1
예제 #2
0
    def _get_installed_version(self):
        """Return current version of schema or None if not any found.
        """
        query = "SELECT tablename FROM pg_tables WHERE tablename = 'metadata';"
        with self.client.connect() as conn:
            result = conn.execute(query)
            tables_exist = result.rowcount > 0

        if not tables_exist:
            return

        query = """
        SELECT value AS version
          FROM metadata
         WHERE name = 'storage_schema_version'
         ORDER BY LPAD(value, 3, '0') DESC;
        """
        with self.client.connect() as conn:
            result = conn.execute(query)
            if result.rowcount > 0:
                return int(result.fetchone()['version'])
            else:
                # Guess current version.
                query = "SELECT COUNT(*) FROM metadata;"
                result = conn.execute(query)
                was_flushed = int(result.fetchone()[0]) == 0
                if was_flushed:
                    error_msg = 'Missing schema history: consider version %s.'
                    logger.warning(error_msg % self.schema_version)
                    return self.schema_version

                # In the first versions of Cliquet, there was no migration.
                return 1
예제 #3
0
 def _check_database_timezone(self):
     # Make sure database has UTC timezone.
     query = "SELECT current_setting('TIMEZONE') AS timezone;"
     with self.client.connect() as conn:
         result = conn.execute(query)
         record = result.fetchone()
     timezone = record['timezone'].upper()
     if timezone != 'UTC':  # pragma: no cover
         msg = 'Database timezone is not UTC (%s)' % timezone
         warnings.warn(msg)
         logger.warning(msg)
예제 #4
0
 def _check_database_timezone(self):
     # Make sure database has UTC timezone.
     query = "SELECT current_setting('TIMEZONE') AS timezone;"
     with self.client.connect() as conn:
         result = conn.execute(query)
         record = result.fetchone()
     timezone = record['timezone'].upper()
     if timezone != 'UTC':  # pragma: no cover
         msg = 'Database timezone is not UTC (%s)' % timezone
         warnings.warn(msg)
         logger.warning(msg)