From 41afd3bf16b6ceff2b0dab24ce2eeae8056a7577 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 10 Oct 2012 03:14:58 +0400 Subject: [PATCH 1/6] add pg gem --- Gemfile | 5 +++-- Gemfile.lock | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) 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 From 3e1d52f4b7accb100d8a312236f8fc8005b78a69 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 10 Oct 2012 03:15:26 +0400 Subject: [PATCH 2/6] add default postgres config --- config/database.yml.postgresql | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 config/database.yml.postgresql 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 From 4eb7d82ae7b085049a889b8f4e7d421f05b39d07 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 10 Oct 2012 03:31:51 +0400 Subject: [PATCH 3/6] add support use string FK with integer PK --- ...20121009205010_postgres_create_integer_cast.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/migrate/20121009205010_postgres_create_integer_cast.rb 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 From 75e6eb59ecd21735c87eb53eb68d510760580b3f Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 10 Oct 2012 03:41:14 +0400 Subject: [PATCH 4/6] patch rails to ignore text limit --- config/initializers/postgresql_limit_fix.rb | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 config/initializers/postgresql_limit_fix.rb 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 From 92ac42a27c1251304f408fdff162999d0577a340 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 10 Oct 2012 03:41:33 +0400 Subject: [PATCH 5/6] update doc --- doc/installation.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) 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 From 8402bca7355c95e60b9d5cfd124a839de60cd50b Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 10 Oct 2012 03:41:44 +0400 Subject: [PATCH 6/6] travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) 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"