Reputation: 32321
I am new to Ruby On Rails , i am using Rails 3.2.7 version .
On Rails Tutorials its mentioned as "On the command line, if you run “rake db:migrate”, your database will be upgraded to the latest version. "
Could anybody please clarify me these questions ??
What does it mean by "your database will be upgraded to the latest version" ( I am using MySQL 5 , and i have created 3 databases in it for rails Development , test and Production )
With What data will my Database will be upgraded with ??
I manually created these 3 Databases , and configured them inside the database.yml file . Is running rake db:migrate is mandatory ??
Upvotes: 3
Views: 2056
Reputation: 1618
3 )It is not mandatory to run db:migrate. With just the table name in your DB mapped to the Model Name in the application we can access all the attributes of the table in the applicaiton. Migrations are used so that we could manage our tables and databases within our application (without ever going to the mysql terminal to create a table and its attributes). Generally when a application is being developed its database structure changes over time that is when we use our migrations to alter the structure of the table with out going to mysql terminal and more over when we move from development to production. We need not sit and create the whole DB structure again . its already in our migration we just run db:migrate in production mode
2 ) I am not sure (too my knowledge old data will be preserved as far as possible )
1 ) Suppose that at first my migration and the corresponding model says that I have only 5 attributes and I run a db:migrate and get that table in MY Database and after a few days of development I figure out that I need 8 attributes. Then, I change the structure in my migration file and model and then run db:migrate again then my database table structure will be updated with three new attributes.
Upvotes: 4
Reputation: 47462
Ref this
Rails provides a set of rake tasks to work with migrations which boil down to running certain sets of migrations.
The very first migration related rake task you will use will probably be rake db:migrate. In its most basic form it just runs the up or change method for all the migrations that have not yet been run. If there are no such migrations, it exits. It will run these migrations in order based on the date of the migration.
Note that running the db:migrate also invokes the db:schema:dump task, which will update your db/schema.rb file to match the structure of your database.
If you specify a target version, Active Record will run the required migrations (up, down or change) until it has reached the specified version. The version is the numerical prefix on the migration’s filename. For example, to migrate to version 20080906120000 run
$ rake db:migrate VERSION=20080906120000
If version 20080906120000 is greater than the current version (i.e., it is migrating upwards), this will run the up method on all migrations up to and including 20080906120000, and will not execute any later migrations. If migrating downwards, this will run the down method on all the migrations down to, but not including, 20080906120000.
Upvotes: 1