Commit 2d2ffc6f5c0d9b487cef3079ce3e9d578e5775a9
Exists in
master
and in
4 other branches
Merge pull request #1666 from zzet/feature/postgres
Postgresql
Showing
7 changed files
with
136 additions
and
3 deletions
Show diff stats
.travis.yml
1 | 1 | env: |
2 | + - DB=postgresql | |
2 | 3 | - DB=mysql |
3 | 4 | before_install: |
4 | 5 | - sudo apt-get install libicu-dev -y |
... | ... | @@ -11,6 +12,7 @@ rvm: |
11 | 12 | - 1.9.3 |
12 | 13 | services: |
13 | 14 | - mysql |
15 | + - postgresql | |
14 | 16 | before_script: |
15 | 17 | - "cp config/database.yml.$DB config/database.yml" |
16 | 18 | - "cp config/gitlab.yml.example config/gitlab.yml" | ... | ... |
Gemfile
Gemfile.lock
... | ... | @@ -245,6 +245,7 @@ GEM |
245 | 245 | multi_json (~> 1.3) |
246 | 246 | omniauth-oauth (~> 1.0) |
247 | 247 | orm_adapter (0.3.0) |
248 | + pg (0.14.0) | |
248 | 249 | polyglot (0.3.3) |
249 | 250 | posix-spawn (0.3.6) |
250 | 251 | pry (0.9.9.6) |
... | ... | @@ -441,6 +442,7 @@ DEPENDENCIES |
441 | 442 | omniauth-google-oauth2 |
442 | 443 | omniauth-ldap! |
443 | 444 | omniauth-twitter |
445 | + pg | |
444 | 446 | pry |
445 | 447 | pygments.rb (= 0.3.1) |
446 | 448 | rack-mini-profiler | ... | ... |
... | ... | @@ -0,0 +1,48 @@ |
1 | +# | |
2 | +# PRODUCTION | |
3 | +# | |
4 | +production: | |
5 | + adapter: postgresql | |
6 | + encoding: unicode | |
7 | + database: gitlabhq_production | |
8 | + pool: 5 | |
9 | + username: postgres | |
10 | + password: | |
11 | + # host: localhost | |
12 | + # socket: /tmp/postgresql.sock | |
13 | + | |
14 | +# | |
15 | +# Development specific | |
16 | +# | |
17 | +development: | |
18 | + adapter: postgresql | |
19 | + encoding: unicode | |
20 | + database: gitlabhq_development | |
21 | + pool: 5 | |
22 | + username: postgres | |
23 | + password: | |
24 | + # socket: /tmp/postgresql.sock | |
25 | + | |
26 | +# | |
27 | +# Staging specific | |
28 | +# | |
29 | +staging: | |
30 | + adapter: postgresql | |
31 | + encoding: unicode | |
32 | + database: gitlabhq_staging | |
33 | + pool: 5 | |
34 | + username: postgres | |
35 | + password: | |
36 | + # socket: /tmp/postgresql.sock | |
37 | + | |
38 | +# Warning: The database defined as "test" will be erased and | |
39 | +# re-generated from your development database when you run "rake". | |
40 | +# Do not set this db to the same as development or production. | |
41 | +test: &test | |
42 | + adapter: postgresql | |
43 | + encoding: unicode | |
44 | + database: gitlabhq_test | |
45 | + pool: 5 | |
46 | + username: postgres | |
47 | + password: | |
48 | + # socket: /tmp/postgresql.sock | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) | |
2 | + class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | |
3 | + class TableDefinition | |
4 | + def text(*args) | |
5 | + options = args.extract_options! | |
6 | + options.delete(:limit) | |
7 | + column_names = args | |
8 | + type = :text | |
9 | + column_names.each { |name| column(name, type, options) } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + def add_column_with_limit_filter(table_name, column_name, type, options = {}) | |
14 | + options.delete(:limit) if type == :text | |
15 | + add_column_without_limit_filter(table_name, column_name, type, options) | |
16 | + end | |
17 | + | |
18 | + def change_column_with_limit_filter(table_name, column_name, type, options = {}) | |
19 | + options.delete(:limit) if type == :text | |
20 | + change_column_without_limit_filter(table_name, column_name, type, options) | |
21 | + end | |
22 | + | |
23 | + alias_method_chain :add_column, :limit_filter | |
24 | + alias_method_chain :change_column, :limit_filter | |
25 | + end | |
26 | +end | ... | ... |
db/migrate/20121009205010_postgres_create_integer_cast.rb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +class PostgresCreateIntegerCast < ActiveRecord::Migration | |
2 | + def up | |
3 | + execute <<-SQL | |
4 | + CREATE CAST (integer AS text) WITH INOUT AS IMPLICIT; | |
5 | + SQL | |
6 | + rescue ActiveRecord::StatementInvalid | |
7 | + end | |
8 | + | |
9 | + def down | |
10 | + execute <<-SQL | |
11 | + DROP CAST (integer AS text); | |
12 | + SQL | |
13 | + rescue ActiveRecord::StatementInvalid | |
14 | + end | |
15 | +end | ... | ... |
doc/installation.md
... | ... | @@ -75,6 +75,9 @@ Now install the required packages: |
75 | 75 | # If you want to use MySQL: |
76 | 76 | sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev |
77 | 77 | |
78 | + # If you want to use PostgreSQL: | |
79 | + sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2 | |
80 | + | |
78 | 81 | # 2. Install Ruby |
79 | 82 | |
80 | 83 | 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. |
188 | 191 | # Exit MySQL Server and copy the example config, make sure to update username/password in config/database.yml |
189 | 192 | sudo -u gitlab cp config/database.yml.example config/database.yml |
190 | 193 | |
194 | + # Or | |
195 | + # PostgreSQL | |
196 | + # Install PostgreSQL as directed in Step #1 | |
197 | + | |
198 | + # Connect to database server | |
199 | + sudo -u postgres psql -d template1 | |
200 | + | |
201 | + # Add a user called gitlab. Change $password to a real password | |
202 | + template1=# CREATE USER gitlab WITH PASSWORD '$password'; | |
203 | + | |
204 | + # Create the GitLab production database | |
205 | + template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production; | |
206 | + | |
207 | + # Grant all privileges on database | |
208 | + template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab; | |
209 | + | |
210 | + # Quit from PostgreSQL server | |
211 | + template1=# \q | |
212 | + | |
213 | + # Try connect to new database | |
214 | + $ su - gitlab | |
215 | + $ psql -d gitlabhq_production -U gitlab | |
216 | + | |
217 | + # Exit PostgreSQL Server and copy the example config, make sure to update username/password in config/database.yml | |
218 | + sudo -u gitlab cp config/database.yml.postgres config/database.yml | |
219 | + | |
220 | + # If you need create development, test, staging or another database | |
221 | + # Repeate some steps with actual commands | |
222 | + | |
191 | 223 | #### Install gems |
192 | 224 | |
193 | - sudo -u gitlab -H bundle install --without development test --deployment | |
225 | + # Please, check Gemfile before run bundle install | |
226 | + # Select database gem, wich you will use | |
227 | + # or run to setup gems with mysql usage | |
228 | + sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment | |
229 | + # or postgres | |
230 | + sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment | |
231 | + # or sqlite | |
232 | + sudo -u gitlab -H bundle install --without development test mysql postgres --deployment | |
194 | 233 | |
195 | 234 | #### Setup database |
196 | 235 | ... | ... |