From 47bdb8da239d76e7363f89f38c4ec61916304296 Mon Sep 17 00:00:00 2001 From: takezoe Date: Thu, 4 Jul 2013 18:46:01 +0900 Subject: [PATCH] (refs #18)Add schema update to fix constraints for COLLABORATOR. --- src/main/resources/update/1_1.sql | 8 ++++++++ src/main/scala/servlet/AutoUpdateListener.scala | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/update/1_1.sql diff --git a/src/main/resources/update/1_1.sql b/src/main/resources/update/1_1.sql new file mode 100644 index 000000000..9cfd50a4c --- /dev/null +++ b/src/main/resources/update/1_1.sql @@ -0,0 +1,8 @@ +-- Fix COLLABORATOR constraints +ALTER TABLE COLLABORATOR DROP CONSTRAINT IDX_COLLABORATOR_FK1 IF EXISTS; +ALTER TABLE COLLABORATOR DROP CONSTRAINT IDX_COLLABORATOR_FK0 IF EXISTS; +ALTER TABLE COLLABORATOR DROP CONSTRAINT IDX_COLLABORATOR_PK IF EXISTS; + +ALTER TABLE COLLABORATOR ADD CONSTRAINT IDX_COLLABORATOR_PK PRIMARY KEY (USER_NAME, REPOSITORY_NAME, COLLABORATOR_NAME); +ALTER TABLE COLLABORATOR ADD CONSTRAINT IDX_COLLABORATOR_FK0 FOREIGN KEY (USER_NAME, REPOSITORY_NAME) REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME); +ALTER TABLE COLLABORATOR ADD CONSTRAINT IDX_COLLABORATOR_FK1 FOREIGN KEY (COLLABORATOR_NAME) REFERENCES ACCOUNT (USER_NAME); diff --git a/src/main/scala/servlet/AutoUpdateListener.scala b/src/main/scala/servlet/AutoUpdateListener.scala index aa48a0042..5453c2264 100644 --- a/src/main/scala/servlet/AutoUpdateListener.scala +++ b/src/main/scala/servlet/AutoUpdateListener.scala @@ -14,7 +14,7 @@ object AutoUpdate { * Version of GitBucket * * @param majorVersion the major version - * @param minorVersion the minor version + * @param minorVersion the minor version */ case class Version(majorVersion: Int, minorVersion: Int){ @@ -22,7 +22,7 @@ object AutoUpdate { /** * Execute update/MAJOR_MINOR.sql to update schema to this version. - * If corresponding SQL file does not exist, this method do nothing. + * If corresponding SQL file does not exist, this method do nothing. */ def update(conn: Connection): Unit = { val sqlPath = "update/%d_%d.sql".format(majorVersion, minorVersion) @@ -40,7 +40,7 @@ object AutoUpdate { } /** - * MAJOR.MINOR + * MAJOR.MINOR */ val versionString = "%d.%d".format(majorVersion, minorVersion) } @@ -49,6 +49,7 @@ object AutoUpdate { * The history of versions. A head of this sequence is the current BitBucket version. */ val versions = Seq( + Version(1, 1), Version(1, 0) ) @@ -84,7 +85,7 @@ object AutoUpdate { } /** - * Start H2 database and update schema automatically. + * Start H2 database and update schema automatically. */ class AutoUpdateListener extends org.h2.server.web.DbStarter { import AutoUpdate._