Read table metadata and data from the source database and create a replica in the destination database. For example, the Impala functional test database could be copied into Postgresql.
(src_cursor, dst_cursor, include_table_names=None)
| 62 | |
| 63 | |
| 64 | def migrate_db(src_cursor, dst_cursor, include_table_names=None): |
| 65 | '''Read table metadata and data from the source database and create a replica in |
| 66 | the destination database. For example, the Impala functional test database could |
| 67 | be copied into Postgresql. |
| 68 | ''' |
| 69 | for table_name in src_cursor.list_table_names(): |
| 70 | if include_table_names and table_name not in include_table_names: |
| 71 | continue |
| 72 | table = src_cursor.describe_table(table_name) |
| 73 | dst_cursor.create_table(table) |
| 74 | src_cursor.execute('SELECT * FROM ' + table_name) |
| 75 | while True: |
| 76 | rows = src_cursor.fetchmany(size=100) |
| 77 | if not rows: |
| 78 | break |
| 79 | sql = dst_cursor.make_insert_sql_from_data(table, rows) |
| 80 | dst_cursor.execute(sql) |
| 81 | index_tables_in_db_if_possible(dst_cursor) |
| 82 | |
| 83 | |
| 84 | class DbPopulator(object): |
no test coverage detected