Merge pull request #1666 from zzet/feature/postgres

Postgresql
This commit is contained in:
Dmitriy Zaporozhets 2012-10-10 04:47:05 -07:00
commit 2d2ffc6f5c
7 changed files with 136 additions and 3 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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