設置config/database.yml特別注意

在rails的config/database.yml中有一段注釋:

# 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.

我沒有注意,不小心將三種環境的database設成一樣了,昨天運行了一下:rake --trace,就將已經上線的系統資料全部清除了,真是'慘!慘!慘!'。

我通常會用到sqlite、mysql、oracle,一般database.yml設置如下:

development_defaults: &development_defaults
<% if RUBY_PLATFORM =~ /java/ %>
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/rged_development
  database: myapp_development
  username: root
  password:
  host: localhost
<% else %>
  adapter: mysql
  database: myapp_development
  username: root
  password:
  host: localhost
  #socket: /opt/local/var/run/mysql5/mysqld.sock
<% end %>

test_defaults: &test_defaults
<% if RUBY_PLATFORM =~ /java/ %>
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/rged_test
  database: myapp_test
  username: root
  password:
  host: localhost
<% else %>
  adapter: mysql
  database: myapp_test
  username: root
  password:
  host: localhost
  #socket: /opt/local/var/run/mysql5/mysqld.sock
<% end %>

production_defaults: &production_defaults
<% if RUBY_PLATFORM =~ /java/ %>
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/rged_production
  database: myapp_production
  username: root
  password:
  host: localhost
<% else %>
  adapter: mysql
  database: myapp_production
  username: root
  password:
  host: localhost
  #socket: /opt/local/var/run/mysql5/mysqld.sock
<% end %>

sqlite_db: &sqlite_db
  adapter: sqlite3  
  timeout: 5000

oracle_db: &oracle_db
  adapter: oracle
  database: 60200
  
ora_dms: &ora_dms
  <<: *oracle_db
  username: dms
  password: practice
  
development:
  <<: *development_defaults

test:
  <<: *sqlite_db
  database: db/dms_test.db

production:
  <<: *ora_dms 
 

你可能感兴趣的:(oracle,mysql,jdbc,sqlite,Ruby)