@@ -29,6 +29,42 namespace :ci do | |||
|
29 | 29 | task :teardown do |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | desc "Creates and configures the databases for the CI server" | |
|
33 | task :database do | |
|
34 | path = 'config/database.yml' | |
|
35 | unless File.exists?(path) | |
|
36 | database = ENV['DATABASE_ADAPTER'] | |
|
37 | ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '') | |
|
38 | branch = ENV['BRANCH'].gsub('.', '').gsub('-', '') | |
|
39 | dev_db_name = "ci_#{branch}_#{ruby}_dev" | |
|
40 | test_db_name = "ci_#{branch}_#{ruby}_test" | |
|
41 | ||
|
42 | case database | |
|
43 | when 'mysql' | |
|
44 | raise "Error creating databases" unless | |
|
45 | system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) && | |
|
46 | system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|) | |
|
47 | dev_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } | |
|
48 | test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } | |
|
49 | when 'postgresql' | |
|
50 | raise "Error creating databases" unless | |
|
51 | system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';|) && | |
|
52 | system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';|) | |
|
53 | dev_conf = { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } | |
|
54 | test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } | |
|
55 | when 'sqlite3' | |
|
56 | dev_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" } | |
|
57 | test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" } | |
|
58 | else | |
|
59 | raise "Unknown database" | |
|
60 | end | |
|
61 | ||
|
62 | File.open(path, 'w') do |f| | |
|
63 | f.write YAML.dump({'development' => dev_conf, 'test' => test_conf}) | |
|
64 | end | |
|
65 | end | |
|
66 | end | |
|
67 | ||
|
32 | 68 | desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging" |
|
33 | 69 | task :dump_environment do |
|
34 | 70 |
General Comments 0
You need to be logged in to leave comments.
Login now