diff --git a/scripts/setup/postgres-reset-sequences b/scripts/setup/postgres-reset-sequences new file mode 100755 index 0000000000..2aab7336b0 --- /dev/null +++ b/scripts/setup/postgres-reset-sequences @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +./manage.py sqlsequencereset zerver | ./manage.py dbshell +echo "Sequence has been reset successfully!" diff --git a/zerver/management/commands/import.py b/zerver/management/commands/import.py index b7eece8243..acb8e11d40 100644 --- a/zerver/management/commands/import.py +++ b/zerver/management/commands/import.py @@ -72,3 +72,7 @@ import a database dump from one or more JSON files.""" print("Processing dump: %s ..." % (path,)) do_import_realm(path) + if options["destroy_rebuild_database"]: + print("Resetting auto-increment sequence for Postgres......") + subprocess.check_call([os.path.join(settings.DEPLOY_ROOT, + "scripts/setup/postgres-reset-sequences")])