Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hophacker/3ad016db693dd03bf879 to your computer and use it in GitHub Desktop.
Save hophacker/3ad016db693dd03bf879 to your computer and use it in GitHub Desktop.

Revisions

  1. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions rails_migration_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -63,16 +63,19 @@ $ rake db:reset #drop database and recreate it
    $ rake db:migrate:up VERSION=20080906120000
    ```

    ## Migrations commands (rake -T db)
    ## Migrations commands
    ```
    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:test:prepare # Rebuild it from scratch according to the specs defined in the development database
    ```

    ## Database commands (rake -T db)
    ## more Database commands (rake -T db)
    ```
    rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in t...
    rake db:drop # Drops the database for 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
  2. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion rails_migration_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -63,7 +63,9 @@ $ rake db:reset #drop database and recreate it
    $ rake db:migrate:up VERSION=20080906120000
    ```

    ## Rake -T db
    ## Migrations commands (rake -T db)

    ## Database commands (rake -T db)
    ```
    rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in t...
    rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
  3. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions rails_migration_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -62,3 +62,19 @@ $ rake db:migrate:redo STEP=3
    $ rake db:reset #drop database and recreate it
    $ rake db:migrate:up VERSION=20080906120000
    ```

    ## Rake -T db
    ```
    rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in t...
    rake db:drop # Drops the database for 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: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:version # Retrieves the current schema version number
    ```
  4. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions rails_migration_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -32,8 +32,9 @@ YYYYMMDDHHMMSS_create_products.rb
    especial type:
    * :references

    ## create_table

    ## Commands to create migrations
    ### Commands to create migrations

    ```
    $ rails generate model Product name:string description:text
    @@ -42,5 +43,22 @@ $ rails generate migration RemovePartNumberFromProducts part_number:string
    $ rails generate migration AddDetailsToProducts part_number:string price:decimal
    ```

    ## change_table
    * add_column
    * add_index
    * add_timestamps
    * create_table
    * remove_timestamps
    * rename_column
    * rename_index
    * rename_table


    ## Running Migrations
    ```
    $ rake db:migrate VERSION=20080906120000
    $ rake db:rollback
    $ rake db:rollback STEP=3
    $ rake db:migrate:redo STEP=3
    $ rake db:reset #drop database and recreate it
    $ rake db:migrate:up VERSION=20080906120000
    ```
  5. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 33 additions and 2 deletions.
    35 changes: 33 additions & 2 deletions rails_migration_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    === Rails Migration
    # Rails Migration
    http://guides.rubyonrails.org/migrations.html

    == Migrations methods:
    ## Migrations methods:
    * add_column
    * add_index
    * change_column
    @@ -12,4 +12,35 @@ http://guides.rubyonrails.org/migrations.html
    * remove_index
    * rename_column

    Basic format
    YYYYMMDDHHMMSS_create_products.rb

    ## Supported types

    * :binary
    * :boolean
    * :date
    * :datetime
    * :decimal
    * :float
    * :integer
    * :primary_key
    * :string
    * :text
    * :time
    * :timestamp
    especial type:
    * :references


    ## Commands to create migrations

    ```
    $ rails generate model Product name:string description:text
    $ rails generate migration AddPartNumberToProducts part_number:string
    $ rails generate migration RemovePartNumberFromProducts part_number:string
    $ rails generate migration AddDetailsToProducts part_number:string price:decimal
    ```



  6. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions rails_migration_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,15 @@
    Rails Migration
    === Rails Migration
    http://guides.rubyonrails.org/migrations.html

    == Migrations methods:
    * add_column
    * add_index
    * change_column
    * change_table
    * create_table
    * drop_table
    * remove_column
    * remove_index
    * rename_column


    "http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html"
  7. @amejiarosario amejiarosario renamed this gist Jun 18, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.textile
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,3 @@
    hn. Rails Migration
    !"http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html"
    Rails Migration

    "http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html"
  9. @amejiarosario amejiarosario revised this gist Jun 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.textile
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    == Rails Migration
    hn. Rails Migration
    !"http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html"
  10. @amejiarosario amejiarosario created this gist Jun 18, 2012.
    2 changes: 2 additions & 0 deletions gistfile1.textile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    == Rails Migration
    !"http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html"