database_yml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/database_yml +16 -0
- data/lib/database_yml.rb +51 -0
- data/lib/templates/mysql +39 -0
- data/lib/templates/postgresql +51 -0
- data/lib/templates/sqlite3 +22 -0
- metadata +50 -0
data/bin/database_yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'database_yml'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: database_yml [options]"
|
9
|
+
|
10
|
+
opts.on("-d database", "--database database", DatabaseYML::DRIVERS.join(", ")) do |v|
|
11
|
+
options[:database] = v
|
12
|
+
end
|
13
|
+
|
14
|
+
end.parse!
|
15
|
+
|
16
|
+
DatabaseYML.new(options[:database]).create!
|
data/lib/database_yml.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Obtained from rails source code
|
2
|
+
# https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/script_rails_loader.rb
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
class DatabaseYML
|
8
|
+
SCRIPT_RAILS = File.join('script', 'rails')
|
9
|
+
DRIVERS = %W(mysql postgresql sqlite3)
|
10
|
+
TEMPLATES_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "templates")
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(database)
|
14
|
+
@database = database || 'sqlite3'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create!
|
18
|
+
|
19
|
+
return unless DRIVERS.include? @database
|
20
|
+
|
21
|
+
cwd = Dir.pwd
|
22
|
+
return unless self.class.in_rails_application? || self.class.in_rails_application_subdirectory?
|
23
|
+
|
24
|
+
if self.class.in_rails_application?
|
25
|
+
generate_database_yml!
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir.chdir("..") do
|
30
|
+
# Recurse in a chdir block: if the search fails we want to be sure
|
31
|
+
# the application is generated in the original working directory.
|
32
|
+
create! unless cwd == Dir.pwd
|
33
|
+
end
|
34
|
+
rescue SystemCallError
|
35
|
+
# could not chdir, no problem just return
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.in_rails_application?
|
39
|
+
File.exists?(SCRIPT_RAILS)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
|
43
|
+
File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent)
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_database_yml!
|
47
|
+
FileUtils.cp(File.join(TEMPLATES_DIR, @database), File.join(Dir.pwd, "config", "database.yml"))
|
48
|
+
puts "database.yml created for #{@database}"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/templates/mysql
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# MySQL. Versions 4.1 and 5.0 are recommended.
|
2
|
+
#
|
3
|
+
# Install the MySQL driver:
|
4
|
+
# gem install mysql2
|
5
|
+
#
|
6
|
+
# And be sure to use new-style password hashing:
|
7
|
+
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
|
8
|
+
development:
|
9
|
+
adapter: mysql2
|
10
|
+
encoding: utf8
|
11
|
+
reconnect: false
|
12
|
+
database: test-mysql2_development
|
13
|
+
pool: 5
|
14
|
+
username: root
|
15
|
+
password:
|
16
|
+
socket: /tmp/mysql.sock
|
17
|
+
|
18
|
+
# Warning: The database defined as "test" will be erased and
|
19
|
+
# re-generated from your development database when you run "rake".
|
20
|
+
# Do not set this db to the same as development or production.
|
21
|
+
test:
|
22
|
+
adapter: mysql2
|
23
|
+
encoding: utf8
|
24
|
+
reconnect: false
|
25
|
+
database: test-mysql2_test
|
26
|
+
pool: 5
|
27
|
+
username: root
|
28
|
+
password:
|
29
|
+
socket: /tmp/mysql.sock
|
30
|
+
|
31
|
+
production:
|
32
|
+
adapter: mysql2
|
33
|
+
encoding: utf8
|
34
|
+
reconnect: false
|
35
|
+
database: test-mysql2_production
|
36
|
+
pool: 5
|
37
|
+
username: root
|
38
|
+
password:
|
39
|
+
socket: /tmp/mysql.sock
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# PostgreSQL. Versions 7.4 and 8.x are supported.
|
2
|
+
#
|
3
|
+
# Install the pg driver:
|
4
|
+
# gem install pg
|
5
|
+
# On Mac OS X with macports:
|
6
|
+
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
|
7
|
+
# On Windows:
|
8
|
+
# gem install pg
|
9
|
+
# Choose the win32 build.
|
10
|
+
# Install PostgreSQL and put its /bin directory on your path.
|
11
|
+
development:
|
12
|
+
adapter: postgresql
|
13
|
+
encoding: unicode
|
14
|
+
database: test-postgres_development
|
15
|
+
pool: 5
|
16
|
+
username: test-postgres (or your username if PostgreSQL installed by Homebrew)
|
17
|
+
password:
|
18
|
+
|
19
|
+
# Connect on a TCP socket. Omitted by default since the client uses a
|
20
|
+
# domain socket that doesn't need configuration. Windows does not have
|
21
|
+
# domain sockets, so uncomment these lines.
|
22
|
+
#host: localhost
|
23
|
+
#port: 5432
|
24
|
+
|
25
|
+
# Schema search path. The server defaults to $user,public
|
26
|
+
#schema_search_path: myapp,sharedapp,public
|
27
|
+
|
28
|
+
# Minimum log levels, in increasing order:
|
29
|
+
# debug5, debug4, debug3, debug2, debug1,
|
30
|
+
# log, notice, warning, error, fatal, and panic
|
31
|
+
# The server defaults to notice.
|
32
|
+
#min_messages: warning
|
33
|
+
|
34
|
+
# Warning: The database defined as "test" will be erased and
|
35
|
+
# re-generated from your development database when you run "rake".
|
36
|
+
# Do not set this db to the same as development or production.
|
37
|
+
test:
|
38
|
+
adapter: postgresql
|
39
|
+
encoding: unicode
|
40
|
+
database: test-postgres_test
|
41
|
+
pool: 5
|
42
|
+
username: test-postgres (or your username if PostgreSQL installed by Homebrew)
|
43
|
+
password:
|
44
|
+
|
45
|
+
production:
|
46
|
+
adapter: postgresql
|
47
|
+
encoding: unicode
|
48
|
+
database: test-postgres_production
|
49
|
+
pool: 5
|
50
|
+
username: test-postgres
|
51
|
+
password:
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: database_yml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrián González
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Generate database yml for rails projects
|
15
|
+
email: adrian@icalialabs.com
|
16
|
+
executables:
|
17
|
+
- database_yml
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/database_yml.rb
|
22
|
+
- lib/templates/mysql
|
23
|
+
- lib/templates/postgresql
|
24
|
+
- lib/templates/sqlite3
|
25
|
+
- bin/database_yml
|
26
|
+
homepage: http://rubygems.org/gems/database_yml
|
27
|
+
licenses: []
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.24
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: Generate database yml for rails projects
|
50
|
+
test_files: []
|