Permalink
Browse files

Adding information about rails migrations

  • Loading branch information...
danman01 committed Jul 24, 2018
1 parent b4f0e79 commit dcef2cfce6633444fc62d1f7e95c3acbf08a9b42
Showing with 21 additions and 0 deletions.
  1. +21 −0 rails-api-single-resource/README.md
@@ -33,7 +33,28 @@ By the end of this, developers should be able to:
- ERD (just version 1)
![Library ERD diagram](https://git.generalassemb.ly/storage/user/3667/files/41f4659c-ce2e-11e7-8e42-a1adbefc1bd5)

### Database and Rails

- Rails uses ActiveRecord to connect your Postgresql database to your Rails application
- To update your Postgresql database _structure_, you use a Rails migration
- To add _data_ to your database, you can use the Rails console, curl scripts or some other client that accesses your Rails API


Think of a database as a neighborhood
- without any tables, it's just an empty plot of land
- you add structure by adding Tables to a database, these are like houses in a neighborhood
- But it's not yet populated yet! There's no data in the tables.
- When you add data, it's like people moving into the houses

In Rails, the empty database is created by `bin/rails db:create`
- This will create the database, which you can verify by looking at your databases in the `psql` console

In Rails, adding tables and structure is done by a 2 step process using a migration:
- Step 1 is generating a migration file:
- A new migration file is generated with `bin/rails generate migration <MigrationName>`. You can add additional command line arguments to auto-fill in the migration, like `AddColumnToTable column_name:data_type`
- Step 2 is running the migration, which applies the changes to your database
- `bin/rails db:migrate`

#### CRUD in Rails:
##### Index Action (HTTP GET / Read)

0 comments on commit dcef2cf

Please sign in to comment.