Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SQL Server database backend support #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ 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",
Expand All @@ -28,19 +30,20 @@ libraryDependencies ++= Seq(
"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",
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/update/gitbucket-core_4.0_mssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE OR ALTER 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);
356 changes: 356 additions & 0 deletions src/main/resources/update/gitbucket-core_4.0_mssql.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main/resources/update/gitbucket-core_4.7_mssql.sql
Original file line number Diff line number Diff line change
@@ -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')
36 changes: 36 additions & 0 deletions src/main/resources/update/gitbucket-core_4.7_mssql.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<changeSet>
<addColumn tableName="COLLABORATOR">
<column name="ROLE" type="varchar(10)" nullable="false" defaultValue="ADMIN"/>
</addColumn>
<addColumn tableName="REPOSITORY">
<column name="WIKI_OPTION" type="varchar(10)" nullable="false" defaultValue="DISABLE"/>
<column name="ISSUES_OPTION" type="varchar(10)" nullable="false" defaultValue="DISABLE"/>
</addColumn>
<update tableName="REPOSITORY">
<column name="WIKI_OPTION" value="DISABLE"/>
<where>ENABLE_WIKI = 'FALSE'</where>
</update>
<update tableName="REPOSITORY">
<column name="WIKI_OPTION" value="PRIVATE"/>
<where>ENABLE_WIKI = 'TRUE' AND ALLOW_WIKI_EDITING = 'FALSE'</where>
</update>
<update tableName="REPOSITORY">
<column name="WIKI_OPTION" value="PUBLIC"/>
<where>ENABLE_WIKI = 'TRUE' AND ALLOW_WIKI_EDITING = 'TRUE'</where>
</update>
<update tableName="REPOSITORY">
<column name="ISSUES_OPTION" value="DISABLE"/>
<where>ENABLE_ISSUES = 'FALSE'</where>
</update>
<update tableName="REPOSITORY">
<column name="ISSUES_OPTION" value="PUBLIC"/>
<where>ENABLE_ISSUES = 'TRUE'</where>
</update>
<dropDefaultValue tableName="REPOSITORY" columnName="ENABLE_WIKI"/>
<dropDefaultValue tableName="REPOSITORY" columnName="ALLOW_WIKI_EDITING"/>
<dropDefaultValue tableName="REPOSITORY" columnName="ENABLE_ISSUES"/>
<dropColumn tableName="REPOSITORY" columnName="ENABLE_WIKI"/>
<dropColumn tableName="REPOSITORY" columnName="ALLOW_WIKI_EDITING"/>
<dropColumn tableName="REPOSITORY" columnName="ENABLE_ISSUES"/>
</changeSet>
7 changes: 5 additions & 2 deletions src/main/scala/gitbucket/core/service/IssuesService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions src/main/scala/gitbucket/core/util/DatabaseConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")
}
Expand All @@ -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 '"'
Expand Down