Skip to content

Commit

Permalink
Return table list in order usable for imports.
Browse files Browse the repository at this point in the history
Fixes constraint violation when using copy_from on a dumps that include
both link_lengths and peer_count.
  • Loading branch information
Thynix committed Jul 27, 2013
1 parent 8ebe77a commit 7d7f125
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions fnprobe/db.py
Expand Up @@ -413,7 +413,7 @@ def drop_indexes(self):
def list_tables(self, cur=None):
"""
Return a list of the names of public tables in the database (excluding
"meta") in ascending alphabetical order.
"meta") in order usable for importing dumps.
Can take a cursor to use, but defaults to read.
"""
Expand All @@ -433,8 +433,20 @@ def list_tables(self, cur=None):
table_name
""")

# Each element will be a singleton tuple, but we want just a string.
return [x[0] for x in cur.fetchall()]
# Each element will be a singleton tuple.
tables = [x[0] for x in cur.fetchall()]

# peer_count comes after link_lengths alphabetically, but link_lengths
# REFERENCES peer_count, so peer_count must come first when importing.
peer_count_index = tables.index('peer_count')
link_lengths_index = tables.index('link_lengths')

assert peer_count_index > link_lengths_index

tables[peer_count_index], tables[link_lengths_index] = \
tables[link_lengths_index], tables[peer_count_index]

return tables

def upgrade(self, version, config):
# The user names (in config) will be needed to modify permissions as
Expand Down

0 comments on commit 7d7f125

Please sign in to comment.