Exemplo n.º 1
0
 def test_success(self):
     ''' Test for the successful case '''
     connection = sqlite3.connect(':memory:')
     connection.execute(_table_utils.make_create_table(
                        'Person', self.template))
     _table_utils.rename_column(connection, 'Person', self.template,
                                self.mapping)
     cursor = connection.cursor()
     cursor.execute('SELECT sql FROM sqlite_master WHERE name="Person";')
     query = cursor.next()[0]
     self.assertEqual(query, 'CREATE TABLE Person (id INTEGER PRIMARY '
                             'KEY, age INTEGER, surname TEXT, name TEXT)')
Exemplo n.º 2
0
 def test_success(self):
     ''' Test for the successful case '''
     connection = sqlite3.connect(':memory:')
     connection.execute(
         _table_utils.make_create_table('Person', self.template))
     _table_utils.rename_column(connection, 'Person', self.template,
                                self.mapping)
     cursor = connection.cursor()
     cursor.execute('SELECT sql FROM sqlite_master WHERE name="Person";')
     query = cursor.next()[0]
     self.assertEqual(
         query, 'CREATE TABLE Person (id INTEGER PRIMARY '
         'KEY, age INTEGER, surname TEXT, name TEXT)')
Exemplo n.º 3
0
def migrate_from__v4_1__to__v4_2(connection):
    """Migrate database from version 4.1 to version 4.2"""

    cursor = connection.cursor()
    cursor.execute("SELECT value FROM config WHERE name='version';")
    ver = cursor.fetchone()[0]
    if ver == "4.1":
        logging.info("* Migrating database from version 4.1 to 4.2")
        cursor.execute("""UPDATE config SET value='4.2'
                        WHERE name='version';""")

        # Config
        cursor.execute("""UPDATE config SET name='privacy.can_publish'
                        WHERE name='privacy.can_share';""")

        logging.info("* Renaming columns (this may take a long time)")
        mapping = { "privacy_can_share": "privacy_can_publish" }

        # BitTorrent
        template_bt = { "timestamp": 0, "uuid": "", "internal_address": "",
                        "real_address": "", "remote_address": "",
                        "privacy_informed": 0, "privacy_can_collect": 0,
                        "privacy_can_share": 0, "connect_time": 0.0,
                        "download_speed": 0.0, "upload_speed": 0.0,
                        "neubot_version": "", "platform": "", }
        #
        # Here we need to break the columns order so that we can
        # fix it up again when migrating from 4.2 to 4.3
        #
        _table_utils.rename_column(connection, "bittorrent",
                                   template_bt, mapping,
                                   broken=True)

        # Speedtest
        template_st = { "timestamp": 0, "uuid": "", "internal_address": "",
                        "real_address": "", "remote_address": "",
                        "privacy_informed": 0, "privacy_can_collect": 0,
                        "privacy_can_share": 0, "connect_time": 0.0,
                        "download_speed": 0.0, "upload_speed": 0.0,
                        "neubot_version": "", "platform": "", "latency": 0.0,}
        #
        # Here we need to break the columns order so that we can
        # fix it up again when migrating from 4.2 to 4.3
        #
        _table_utils.rename_column(connection, "speedtest",
                                   template_st, mapping,
                                   broken=True)

        connection.execute('VACUUM;')
        connection.commit()
    cursor.close()