aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2009-02-07 15:44:07 +1100
committerJeremy Kerr <jk@ozlabs.org>2009-02-07 15:44:07 +1100
commit9b5c682e8ffb1d711f2848e990140383967380d2 (patch)
treeed7fe4a2201e0dc1df7c809763bc090dc93b624b /lib
parentc105cb0f107a7459abc8c33988d2da24582a7a5a (diff)
downloadpatchwork-9b5c682e8ffb1d711f2848e990140383967380d2.tar
patchwork-9b5c682e8ffb1d711f2848e990140383967380d2.tar.gz
Complete bundle ordering migration script
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/sql/migration/005-bundle-patch-ordering.sql12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/sql/migration/005-bundle-patch-ordering.sql b/lib/sql/migration/005-bundle-patch-ordering.sql
index 9f5bcf3..e0db398 100644
--- a/lib/sql/migration/005-bundle-patch-ordering.sql
+++ b/lib/sql/migration/005-bundle-patch-ordering.sql
@@ -1,9 +1,11 @@
BEGIN;
ALTER TABLE patchwork_bundle_patches RENAME TO patchwork_bundlepatch;
-ALTER TABLE patchwork_bundlepatch ADD COLUMN "order" INTEGER NULL;
-UPDATE patchwork_bundlepatch SET "order" =
- (SELECT COALESCE(max("order"), 0) + 1 FROM patchwork_bundlepatch AS p2
- WHERE p2.bundle_id = patchwork_bundlepatch.bundle_id);
-ALTER TABLE patchwork_bundlepatch ALTER COLUMN "order" SET NOT NULL;
+CREATE SEQUENCE bundlepatch_tmp_seq;
+
+ALTER TABLE patchwork_bundlepatch
+ ADD COLUMN "order" INTEGER NOT NULL
+ DEFAULT nextval('bundlepatch_tmp_seq');
+ALTER TABLE patchwork_bundlepatch ALTER COLUMN "order" DROP DEFAULT;
+DROP SEQUENCE bundlepatch_tmp_seq;
ALTER TABLE patchwork_bundlepatch ADD UNIQUE("bundle_id", "order");
COMMIT;