2014-02-26 91 views
0

我是新来的红宝石和MySQL。耙分贝:迁移,源和目的

我被告知要执行以下两条命令:

  1. mysql -u root; then CREATE DATABASE sd

  2. rake db:migrate

sd数据库在创建时为空。在我执行第二个命令后,sd中充满了物品。

我想知道如何耙知道目的地是SD和什么来源。

我知道有一些脚本在DB /迁移的文件夹,所以我想知道耙目标是从这样的新创建(我假设,因为我是新来的红宝石)脚本谁。但是来源呢?

谢谢!

+0

检查'/配置/ database.yml'文件,这就是你的数据库配置的叶子,你会发现你的模式的副本中'db/schema.rb'和所有迁移文件保留在'db/migrations'中 – bjhaid

回答

0

数据的来源通常由分贝控制/迁移/ * .rb文件,如你所知。

但他们可能已经迷上另一个任务到DB:通过Rake文件或IIb /任务/ *迁移耙文件,这样。“耙分贝:mirgrate”还可以运行一些额外的任务。添加种子信息的常见任务是rake db:seed任务,通常运行db/seeds.rb。

当我使用DB/seeds.rb我通常把我的种子数据DB /夹具/ *。YML,但其他人可能有不同的地方。

在较新的轨道,你也可以使用rake db:create做数据库的创建(假设在database.yml中的用户有足够的权限)。 rake -T db会告诉你wnat任务被命名在他们分贝,如:

$ rake -T db 
rake db:create   # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) 
rake db:drop   # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases) 
rake db:fixtures:load # Load fixtures into the current environment's database. 
rake db:migrate   # Migrate the database (options: VERSION=x, VERBOSE=false). 
rake db:migrate:status # Display status of migrations 
rake db:rollback  # Rolls the schema back to the previous version (specify steps w/ STEP=n). 
rake db:schema:dump  # Create a db/schema.rb file that can be portably used against any DB supported by AR 
rake db:schema:load  # Load a schema.rb file into the database 
rake db:seed   # Load the seed data from db/seeds.rb 
rake db:seed_fu   # Loads seed data for the current environment. 
rake db:setup   # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first) 
rake db:structure:dump # Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql 
rake db:test:seed  # seed the test database 
rake db:version   # Retrieves the current schema version number 
0

它看起来像你试图用Rails应用程序的工作。我会建议看看config/database.yml。该文件保存测试,开发和生产环境的配置数据。默认情况下,rails使用开发环境。您可能会在开发部分的config/database.yml中找到答案。