Example #1
0
    def write_migration_history(name, package):

        sql = '''
            INSERT INTO %s(name, package)
            VALUES (%%s, %%s);
        ''' % rsm_config.history_table_name
        database_api.execute(sql, params=(name, package, ), return_result=None)
Example #2
0
 def tearDown(self):
     try:
         database_api.execute('''
             DROP TABLE %s;
             ''' % self.config.history_table_name)
         database_api.commit()
     except:
         pass
     super(DatabaseTestCase, self).tearDown()
Example #3
0
    def drop_history_table():

        sql = '''
            DROP TABLE %s;
        ''' % rsm_config.history_table_name
        database_api.execute(
            sql, params=(rsm_config.history_table_name,), return_result=None
        )
        database_api.commit()
Example #4
0
 def tearDown(self):
     try:
         database_api.execute(
             '''
             DROP TABLE %s;
             ''' % self.config.history_table_name
         )
         database_api.commit()
     except:
         pass
     super(DatabaseTestCase, self).tearDown()
Example #5
0
    def create_history_table():

        sql = '''
            CREATE TABLE %s (
                id SERIAL PRIMARY KEY,
                package VARCHAR(200) NOT NULL,
                name VARCHAR(200) NOT NULL,
                processed_at  TIMESTAMP default current_timestamp
            );
        ''' % rsm_config.history_table_name
        database_api.execute(
            sql, params=(), return_result=None
        )
        database_api.commit()
Example #6
0
 def status(package=None):
     migration_history_param = (rsm_config.history_table_name, ) * 2
     if package:
         sql = '''
             SELECT package, name, processed_at FROM  %s
             WHERE id IN (
                 SELECT max(id)
                 FROM %s
                 GROUP BY package
             )
             AND package = %%s
             ORDER BY package;
         '''
         params = (package, )
     else:
         sql = '''
             SELECT package, name, processed_at FROM  %s
             WHERE id IN (
                 SELECT max(id)
                 FROM %s
                 GROUP BY package
             ) ORDER BY package;
         '''
         params = ()
     sql = sql % migration_history_param
     rows = database_api.execute(
         sql, params=params, return_result=database_api.CursorResult.FETCHALL
     )
     result = {}
     for row in rows:
         result[row[0]] = {'name': row[1], 'processed_at': row[2]}
     return result
Example #7
0
    def migration_history_exists():

        sql = '''
            SELECT *
            FROM information_schema.tables
            WHERE table_name=%(history_table_name)s
        '''

        result = database_api.execute(
            sql,
            params={'history_table_name': rsm_config.history_table_name},
            return_result='rowcount',
        )

        return True if result else False
Example #8
0
    def get_latest_migration_number(cls, package):
        result = 0
        if not cls.migration_history_exists():
            cls.create_history_table()
        else:
            sql = '''
                SELECT name
                FROM %s
                WHERE package = %%s
                ORDER BY id DESC LIMIT 1;
            ''' % rsm_config.history_table_name
            query_params = (package,)

            rows = database_api.execute(sql, params=query_params, return_result='fetchall')
            if rows:
                name = rows[0][0]
                result = int(name.split('_')[0].strip('0'))

        return result
Example #9
0
 def delete_migration_history(name, package):
     sql = '''
         DELETE FROM %s
         WHERE name=%%s and package=%%s
     ''' % rsm_config.history_table_name
     database_api.execute(sql, params=(name, package, ), return_result=None)