diff --git a/.travis.yml b/.travis.yml index 2aa468fd..df3974fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ env: + - DB=postgresql - DB=mysql before_install: - sudo apt-get install libicu-dev -y @@ -11,6 +12,7 @@ rvm: - 1.9.3 services: - mysql + - postgresql before_script: - "cp config/database.yml.$DB config/database.yml" - "cp config/gitlab.yml.example config/gitlab.yml" diff --git a/Gemfile b/Gemfile index 042fbc4d..954fb888 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,9 @@ end gem "rails", "3.2.8" # Supported DBs -gem "sqlite3" -gem "mysql2" +gem "sqlite3", :group => :sqlite +gem "mysql2", :group => :mysql +gem "pg", :group => :postgres # Auth gem "devise", "~> 2.1.0" diff --git a/Gemfile.lock b/Gemfile.lock index 3c3bea9d..87fd1c90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -245,6 +245,7 @@ GEM multi_json (~> 1.3) omniauth-oauth (~> 1.0) orm_adapter (0.3.0) + pg (0.14.0) polyglot (0.3.3) posix-spawn (0.3.6) pry (0.9.9.6) @@ -441,6 +442,7 @@ DEPENDENCIES omniauth-google-oauth2 omniauth-ldap! omniauth-twitter + pg pry pygments.rb (= 0.3.1) rack-mini-profiler diff --git a/config/database.yml.postgresql b/config/database.yml.postgresql new file mode 100644 index 00000000..17b38f3d --- /dev/null +++ b/config/database.yml.postgresql @@ -0,0 +1,48 @@ +# +# PRODUCTION +# +production: + adapter: postgresql + encoding: unicode + database: gitlabhq_production + pool: 5 + username: postgres + password: + # host: localhost + # socket: /tmp/postgresql.sock + +# +# Development specific +# +development: + adapter: postgresql + encoding: unicode + database: gitlabhq_development + pool: 5 + username: postgres + password: + # socket: /tmp/postgresql.sock + +# +# Staging specific +# +staging: + adapter: postgresql + encoding: unicode + database: gitlabhq_staging + pool: 5 + username: postgres + password: + # socket: /tmp/postgresql.sock + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: &test + adapter: postgresql + encoding: unicode + database: gitlabhq_test + pool: 5 + username: postgres + password: + # socket: /tmp/postgresql.sock diff --git a/config/initializers/postgresql_limit_fix.rb b/config/initializers/postgresql_limit_fix.rb new file mode 100644 index 00000000..0cb3aaf4 --- /dev/null +++ b/config/initializers/postgresql_limit_fix.rb @@ -0,0 +1,26 @@ +if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) + class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + class TableDefinition + def text(*args) + options = args.extract_options! + options.delete(:limit) + column_names = args + type = :text + column_names.each { |name| column(name, type, options) } + end + end + + def add_column_with_limit_filter(table_name, column_name, type, options = {}) + options.delete(:limit) if type == :text + add_column_without_limit_filter(table_name, column_name, type, options) + end + + def change_column_with_limit_filter(table_name, column_name, type, options = {}) + options.delete(:limit) if type == :text + change_column_without_limit_filter(table_name, column_name, type, options) + end + + alias_method_chain :add_column, :limit_filter + alias_method_chain :change_column, :limit_filter + end +end diff --git a/db/migrate/20121009205010_postgres_create_integer_cast.rb b/db/migrate/20121009205010_postgres_create_integer_cast.rb new file mode 100644 index 00000000..b9a97138 --- /dev/null +++ b/db/migrate/20121009205010_postgres_create_integer_cast.rb @@ -0,0 +1,15 @@ +class PostgresCreateIntegerCast < ActiveRecord::Migration + def up + execute <<-SQL + CREATE CAST (integer AS text) WITH INOUT AS IMPLICIT; + SQL + rescue ActiveRecord::StatementInvalid + end + + def down + execute <<-SQL + DROP CAST (integer AS text); + SQL + rescue ActiveRecord::StatementInvalid + end +end diff --git a/doc/installation.md b/doc/installation.md index fd8a8b9b..fc5ea828 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -75,6 +75,9 @@ Now install the required packages: # If you want to use MySQL: sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev + # If you want to use PostgreSQL: + sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2 + # 2. Install Ruby wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz @@ -188,9 +191,45 @@ and ensure you have followed all of the above steps carefully. # Exit MySQL Server and copy the example config, make sure to update username/password in config/database.yml sudo -u gitlab cp config/database.yml.example config/database.yml + # Or + # PostgreSQL + # Install PostgreSQL as directed in Step #1 + + # Connect to database server + sudo -u postgres psql -d template1 + + # Add a user called gitlab. Change $password to a real password + template1=# CREATE USER gitlab WITH PASSWORD '$password'; + + # Create the GitLab production database + template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production; + + # Grant all privileges on database + template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab; + + # Quit from PostgreSQL server + template1=# \q + + # Try connect to new database + $ su - gitlab + $ psql -d gitlabhq_production -U gitlab + + # Exit PostgreSQL Server and copy the example config, make sure to update username/password in config/database.yml + sudo -u gitlab cp config/database.yml.postgres config/database.yml + + # If you need create development, test, staging or another database + # Repeate some steps with actual commands + #### Install gems - sudo -u gitlab -H bundle install --without development test --deployment + # Please, check Gemfile before run bundle install + # Select database gem, wich you will use + # or run to setup gems with mysql usage + sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment + # or postgres + sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment + # or sqlite + sudo -u gitlab -H bundle install --without development test mysql postgres --deployment #### Setup database