From f94bdf55c8024e329641ddaf31099b923a7cf81e Mon Sep 17 00:00:00 2001 From: altrive Date: Tue, 18 Apr 2017 23:35:07 +0900 Subject: [PATCH 1/5] Split Solidbase setting files for SQL Server (It requires some DBMS dependent sql query) --- .../update/gitbucket-core_4.0_mssql.sql | 18 + .../update/gitbucket-core_4.0_mssql.xml | 351 ++++++++++++++++++ .../update/gitbucket-core_4.7_mssql.sql | 2 + .../update/gitbucket-core_4.7_mssql.xml | 33 ++ 4 files changed, 404 insertions(+) create mode 100644 src/main/resources/update/gitbucket-core_4.0_mssql.sql create mode 100644 src/main/resources/update/gitbucket-core_4.0_mssql.xml create mode 100644 src/main/resources/update/gitbucket-core_4.7_mssql.sql create mode 100644 src/main/resources/update/gitbucket-core_4.7_mssql.xml diff --git a/src/main/resources/update/gitbucket-core_4.0_mssql.sql b/src/main/resources/update/gitbucket-core_4.0_mssql.sql new file mode 100644 index 0000000000..f97bdbc27c --- /dev/null +++ b/src/main/resources/update/gitbucket-core_4.0_mssql.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS + SELECT + A.USER_NAME, + A.REPOSITORY_NAME, + A.ISSUE_ID, + COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT + FROM ISSUE A + LEFT OUTER JOIN ( + SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT + WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment') + GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID + ) B + ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID) + LEFT OUTER JOIN ( + SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT + GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID + ) C + ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID); diff --git a/src/main/resources/update/gitbucket-core_4.0_mssql.xml b/src/main/resources/update/gitbucket-core_4.0_mssql.xml new file mode 100644 index 0000000000..04f33fe530 --- /dev/null +++ b/src/main/resources/update/gitbucket-core_4.0_mssql.xml @@ -0,0 +1,351 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/update/gitbucket-core_4.7_mssql.sql b/src/main/resources/update/gitbucket-core_4.7_mssql.sql new file mode 100644 index 0000000000..ef13c706bd --- /dev/null +++ b/src/main/resources/update/gitbucket-core_4.7_mssql.sql @@ -0,0 +1,2 @@ +-- DELETE COLLABORATORS IN GROUP REPOSITORIES +DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = TRUE) diff --git a/src/main/resources/update/gitbucket-core_4.7_mssql.xml b/src/main/resources/update/gitbucket-core_4.7_mssql.xml new file mode 100644 index 0000000000..4eb2f0357f --- /dev/null +++ b/src/main/resources/update/gitbucket-core_4.7_mssql.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + ENABLE_WIKI = FALSE + + + + ENABLE_WIKI = TRUE AND ALLOW_WIKI_EDITING = FALSE + + + + ENABLE_WIKI = TRUE AND ALLOW_WIKI_EDITING = TRUE + + + + ENABLE_ISSUES = FALSE + + + + ENABLE_ISSUES = TRUE + + + + + From 288c61485ba34577423bb70b77e5264041cf144d Mon Sep 17 00:00:00 2001 From: altrive Date: Tue, 18 Apr 2017 23:42:03 +0900 Subject: [PATCH 2/5] Modify DBMS specific SQL queries for SQL Server --- .../resources/update/gitbucket-core_4.0_mssql.sql | 2 +- .../resources/update/gitbucket-core_4.0_mssql.xml | 7 ++++++- .../resources/update/gitbucket-core_4.7_mssql.sql | 2 +- .../resources/update/gitbucket-core_4.7_mssql.xml | 13 ++++++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/resources/update/gitbucket-core_4.0_mssql.sql b/src/main/resources/update/gitbucket-core_4.0_mssql.sql index f97bdbc27c..0f261bada3 100644 --- a/src/main/resources/update/gitbucket-core_4.0_mssql.sql +++ b/src/main/resources/update/gitbucket-core_4.0_mssql.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS +CREATE OR ALTER VIEW ISSUE_OUTLINE_VIEW AS SELECT A.USER_NAME, A.REPOSITORY_NAME, diff --git a/src/main/resources/update/gitbucket-core_4.0_mssql.xml b/src/main/resources/update/gitbucket-core_4.0_mssql.xml index 04f33fe530..5289d494e1 100644 --- a/src/main/resources/update/gitbucket-core_4.0_mssql.xml +++ b/src/main/resources/update/gitbucket-core_4.0_mssql.xml @@ -142,7 +142,7 @@ - + @@ -207,6 +207,11 @@ + + + + + diff --git a/src/main/resources/update/gitbucket-core_4.7_mssql.sql b/src/main/resources/update/gitbucket-core_4.7_mssql.sql index ef13c706bd..774d6d9765 100644 --- a/src/main/resources/update/gitbucket-core_4.7_mssql.sql +++ b/src/main/resources/update/gitbucket-core_4.7_mssql.sql @@ -1,2 +1,2 @@ -- DELETE COLLABORATORS IN GROUP REPOSITORIES -DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = TRUE) +DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = 'TRUE') diff --git a/src/main/resources/update/gitbucket-core_4.7_mssql.xml b/src/main/resources/update/gitbucket-core_4.7_mssql.xml index 4eb2f0357f..ec61d593bb 100644 --- a/src/main/resources/update/gitbucket-core_4.7_mssql.xml +++ b/src/main/resources/update/gitbucket-core_4.7_mssql.xml @@ -9,24 +9,27 @@ - ENABLE_WIKI = FALSE + ENABLE_WIKI = 'FALSE' - ENABLE_WIKI = TRUE AND ALLOW_WIKI_EDITING = FALSE + ENABLE_WIKI = 'TRUE' AND ALLOW_WIKI_EDITING = 'FALSE' - ENABLE_WIKI = TRUE AND ALLOW_WIKI_EDITING = TRUE + ENABLE_WIKI = 'TRUE' AND ALLOW_WIKI_EDITING = 'TRUE' - ENABLE_ISSUES = FALSE + ENABLE_ISSUES = 'FALSE' - ENABLE_ISSUES = TRUE + ENABLE_ISSUES = 'TRUE' + + + From 9baa3e6ae4d5007c015caeff74d01269461ab917 Mon Sep 17 00:00:00 2001 From: altrive Date: Tue, 18 Apr 2017 23:57:25 +0900 Subject: [PATCH 3/5] Add backend database support for SQL Server --- build.sbt | 11 +++++++---- .../scala/gitbucket/core/util/DatabaseConfig.scala | 12 ++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index b7c12bce34..6cf3808ea1 100644 --- a/build.sbt +++ b/build.sbt @@ -16,31 +16,34 @@ scalaVersion := "2.12.1" resolvers ++= Seq( Classpaths.typesafeReleases, Resolver.jcenterRepo, + Resolver.mavenLocal, "amateras" at "http://amateras.sourceforge.jp/mvn/", "sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/", "amateras-snapshot" at "http://amateras.sourceforge.jp/mvn-snapshot/" ) + libraryDependencies ++= Seq( - "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.7.0.201704051617-r", - "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.7.0.201704051617-r", + "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.6.1.201703071140-r", + "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.6.1.201703071140-r", "org.scalatra" %% "scalatra" % ScalatraVersion, "org.scalatra" %% "scalatra-json" % ScalatraVersion, "org.json4s" %% "json4s-jackson" % "3.5.0", "io.github.gitbucket" %% "scalatra-forms" % "1.1.0", "commons-io" % "commons-io" % "2.4", - "io.github.gitbucket" % "solidbase" % "1.0.0", + "io.github.gitbucket" % "solidbase" % "1.0.2", "io.github.gitbucket" % "markedj" % "1.0.10", "org.apache.commons" % "commons-compress" % "1.11", "org.apache.commons" % "commons-email" % "1.4", "org.apache.httpcomponents" % "httpclient" % "4.5.1", "org.apache.sshd" % "apache-sshd" % "1.2.0", "org.apache.tika" % "tika-core" % "1.13", - "com.github.takezoe" %% "blocking-slick-32" % "0.0.8", + "com.github.takezoe" %% "blocking-slick-32" % "0.0.9-SNAPSHOT", "joda-time" % "joda-time" % "2.9.6", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", "mysql" % "mysql-connector-java" % "5.1.39", "org.postgresql" % "postgresql" % "9.4.1208", + "com.microsoft.sqlserver" % "mssql-jdbc" % "6.1.0.jre8", "ch.qos.logback" % "logback-classic" % "1.1.7", "com.zaxxer" % "HikariCP" % "2.4.6", "com.typesafe" % "config" % "1.3.0", diff --git a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala index 644c3f25ac..e208e267ba 100644 --- a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala +++ b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala @@ -4,9 +4,9 @@ import com.typesafe.config.ConfigFactory import java.io.File import Directory._ -import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, BlockingJdbcProfile} +import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, BlockingJdbcProfile, BlockingSQLServerDriver} import liquibase.database.AbstractJdbcDatabase -import liquibase.database.core.{H2Database, MySQLDatabase, PostgresDatabase} +import liquibase.database.core.{H2Database, MySQLDatabase, PostgresDatabase, MSSQLDatabase} import org.apache.commons.io.FileUtils object DatabaseConfig { @@ -68,6 +68,8 @@ object DatabaseType { MySQL } else if(url.startsWith("jdbc:postgresql:")){ PostgreSQL + } else if(url.startsWith("jdbc:sqlserver:")){ + SQLServer } else { throw new IllegalArgumentException(s"${url} is not supported.") } @@ -91,6 +93,12 @@ object DatabaseType { val liquiDriver = new PostgresDatabase() } + object SQLServer extends DatabaseType { + val jdbcDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" + val slickDriver = BlockingSQLServerDriver + val liquiDriver = new MSSQLDatabase() + } + object BlockingPostgresDriver extends slick.jdbc.PostgresProfile with BlockingJdbcProfile { override def quoteIdentifier(id: String): String = { val s = new StringBuilder(id.length + 4) append '"' From e1361d18bff052f2a7d45a95d0baad7862b866ba Mon Sep 17 00:00:00 2001 From: altrive Date: Tue, 18 Apr 2017 23:58:28 +0900 Subject: [PATCH 4/5] Modify "FOR UPDATE" SQL query hint based on Slick notation --- src/main/scala/gitbucket/core/service/IssuesService.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 4a9b12c2d7..9922f9705a 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -256,8 +256,11 @@ trait IssuesService { assignedUserName: Option[String], milestoneId: Option[Int], isPullRequest: Boolean = false)(implicit s: Session): Int = { // next id number - sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] - .firstOption.filter { id => + IssueId.filter(_.byPrimaryKey(owner, repository)) + .forUpdate + .map(_.issueId + 1) + .firstOption + .filter { id => Issues insert Issue( owner, repository, From 9e24b866722e9f85d0de182d6538127dd6563b15 Mon Sep 17 00:00:00 2001 From: altrive Date: Wed, 19 Apr 2017 00:31:00 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E3=83=9E=E3=83=BC=E3=82=B8=E3=81=AB?= =?UTF-8?q?=E5=A4=B1=E6=95=97=E3=81=97=E3=81=A6=E3=81=9F=E7=AE=87=E6=89=80?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 6cf3808ea1..cb043cccd4 100644 --- a/build.sbt +++ b/build.sbt @@ -23,8 +23,8 @@ resolvers ++= Seq( ) libraryDependencies ++= Seq( - "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.6.1.201703071140-r", - "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.6.1.201703071140-r", + "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.7.0.201704051617-r", + "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.7.0.201704051617-r", "org.scalatra" %% "scalatra" % ScalatraVersion, "org.scalatra" %% "scalatra-json" % ScalatraVersion, "org.json4s" %% "json4s-jackson" % "3.5.0",