The Unified and Autonomous Development Platform
Add PostgreSQL support
Robin Shen8cc950e35b4a
diff --git a/core/pom.xml b/core/pom.xmlindex 295ee12608..27d4fcd7ed 100644--- a/core/pom.xml+++ b/core/pom.xml@@ -235,12 +235,7 @@<dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId>- <version>9.4.1208</version>- </dependency>- <dependency>- <groupId>org.mariadb.jdbc</groupId>- <artifactId>mariadb-java-client</artifactId>- <version>2.3.0</version>+ <version>42.2.5</version></dependency><dependency><groupId>mysql-connector-java</groupId>diff --git a/core/src/main/java/io/onedev/server/persistence/PostgreSQLDialect.java b/core/src/main/java/io/onedev/server/persistence/PostgreSQLDialect.javanew file mode 100644index 0000000000..6d06cdf9de--- /dev/null+++ b/core/src/main/java/io/onedev/server/persistence/PostgreSQLDialect.java@@ -0,0 +1,33 @@+package io.onedev.server.persistence;++import java.sql.Types;++import org.hibernate.dialect.PostgreSQL82Dialect;+import org.hibernate.type.descriptor.sql.BinaryTypeDescriptor;+import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;++/**+ * Map blob to bytea to avoid below issues:+ * <ul>+ * <li> Blobs are stored in a separate table and will not be removed automatically even+ * if the associating row is removed+ * <li> It can not load blobs in auto-commit mode, meaning that we can not lazy load+ * entities with blob fields out side of a transaction even if Hibernate session+ * is available+ */+public class PostgreSQLDialect extends PostgreSQL82Dialect {++ public PostgreSQLDialect() {+ super();+ registerColumnType(Types.BLOB, "bytea");+ }++ @Override+ public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {+ if (sqlTypeDescriptor.getSqlType() == java.sql.Types.BLOB) {+ return BinaryTypeDescriptor.INSTANCE;+ }+ return super.remapSqlTypeDescriptor(sqlTypeDescriptor);+ }++}diff --git a/product/system/conf/hibernate.properties b/product/system/conf/hibernate.propertiesindex edd0315999..2228071bc5 100644--- a/product/system/conf/hibernate.properties+++ b/product/system/conf/hibernate.properties@@ -11,13 +11,13 @@ hibernate.connection.password=#-----------------------------------------------------------------------------------# To use MySQL database, please follow these steps:+# To use MySQL database, please follow below steps:# 1. Uncomment MySQL settings below and comment out settings for other databases-# 2. Create an empty OneDev schema at MySQL side+# 2. Create an empty OneDev schema at MySQL side, and make sure to use "InnoDB" as+# default storage engine# 3. Change the property "hibernate.connection.url", "hibernate.connection.username",# and "hibernate.connection.password" so that OneDev can connect and write to# the database created in step 2-# 4. Make sure to use "InnoDB" as default storage engine#----------------------------------------------------------------------------------#hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect@@ -28,13 +28,13 @@ hibernate.connection.password=#-----------------------------------------------------------------------------------# To use MariaDB database, please follow these steps:+# To use MariaDB database, please follow below steps:# 1. Uncomment MariaDB settings below and comment out settings for other databases-# 2. Create an empty OneDev schema at MariaDB side+# 2. Create an empty OneDev schema at MariaDB side, and make sure to use "XtraDB"+# or "InnoDB" as the default storage engine# 3. Change the property "hibernate.connection.url", "hibernate.connection.username",# and "hibernate.connection.password" so that OneDev can connect and write to# the database created in step 2-# 4. Make sure to use "XtraDB" or "InnoDB" as the default storage engine#----------------------------------------------------------------------------------#hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect@@ -45,15 +45,15 @@ hibernate.connection.password=#-----------------------------------------------------------------------------------# PostgreSQL is currently NOT supported as:-# 1. Blobs are stored in a separate table and will not be removed automatically even-# if the associating row is removed-# 2. It can not load blobs in auto-commit mode, meaning that we can not lazy load-# entities with blob fields out side of a transaction even if Hibernate session-# is available+# To use PostgreSQL database, please follow below steps:+# 1. Uncomment PostgreSQL settings below and comment out settings for other databases+# 2. Create an empty OneDev database at PostgreSQL side+# 3. Change the property "hibernate.connection.url", "hibernate.connection.username",+# and "hibernate.connection.password" so that OneDev can connect and write to+# the database created in step 2#-----------------------------------------------------------------------------------#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect+#hibernate.dialect=io.onedev.server.persistence.PostgreSQLDialect#hibernate.connection.driver_class=org.postgresql.Driver#hibernate.connection.url=jdbc:postgresql://localhost:5432/onedev#hibernate.connection.username=postgres@@ -61,7 +61,7 @@ hibernate.connection.password=#-----------------------------------------------------------------------------------# To use Microsoft SQL Server, please follow these steps:+# To use Microsoft SQL Server, please follow below steps:# 1. Enable tcp/ip access to SQL Server# 2. Uncomment Microsoft SQL Server settings below and comment out settings for# other databases@@ -79,7 +79,7 @@ hibernate.connection.password=#-----------------------------------------------------------------------------------# To use Oracle, please follow these steps:+# To use Oracle, please follow below steps:# 1. Uncomment Oracle settings below and comment out settings for other databases# 2. Create an empty Oracle database# 3. Change the property "hibernate.connection.url", "hibernate.connection.username",