Make reset-postgresql-sequences work on empty tables

This commit is contained in:
Andrew Ekstedt 2012-10-19 13:35:05 -07:00
parent c4d360e0ec
commit 787a7b864b

View file

@ -33,8 +33,9 @@ for table in sorted(mapped_classes):
for c in sequence_columns(table): for c in sequence_columns(table):
max_value, = session.query(func.max(c)).one() max_value, = session.query(func.max(c)).one()
if options.verbose: if options.verbose:
print "%s.%s <- %s" % (table_name, c.name, max_value) print "%s.%s <- %s" % (table_name, c.name, max_value or 0)
session.execute(func.setval( session.execute(func.setval(
func.pg_get_serial_sequence(table_name, c.name), func.pg_get_serial_sequence(table_name, c.name),
max_value, max_value or 1,
max_value is not None,
)) ))