From 5f20247c07c17d266321d49042c525deafe65152 Mon Sep 17 00:00:00 2001
From: Jeremy Kerr <jk@ozlabs.org>
Date: Sat, 7 Feb 2009 15:48:37 +1100
Subject: Normalise order numbers in bundle-ordering migration SQL

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
---
 lib/sql/migration/005-bundle-patch-ordering.sql | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'lib/sql/migration/005-bundle-patch-ordering.sql')

diff --git a/lib/sql/migration/005-bundle-patch-ordering.sql b/lib/sql/migration/005-bundle-patch-ordering.sql
index e0db398..1491aa8 100644
--- a/lib/sql/migration/005-bundle-patch-ordering.sql
+++ b/lib/sql/migration/005-bundle-patch-ordering.sql
@@ -8,4 +8,7 @@ ALTER TABLE patchwork_bundlepatch
 ALTER TABLE patchwork_bundlepatch ALTER COLUMN "order" DROP DEFAULT;
 DROP SEQUENCE bundlepatch_tmp_seq;
 ALTER TABLE patchwork_bundlepatch ADD UNIQUE("bundle_id", "order");
+UPDATE patchwork_bundlepatch SET "order" = 1 + "order" -
+	(SELECT min("order") FROM patchwork_bundlepatch AS p2
+		WHERE p2.bundle_id = patchwork_bundlepatch.bundle_id);
 COMMIT;
-- 
cgit v1.2.3

