Coder Social home page Coder Social logo

lab-w10d04-migrations's Introduction

Rails Migrations Lab

Objectives

By the end of this, students should be able to:

  • Write Rails migrations to alter a database schema
  • Migrate and rollback between migrations to change the current state of the schema

Instructions/Setup

  • Start a new ruby project called "location_manager"
  • Follow below instructions in order

Step 1

Your boss comes to you and says, "We just got in a new project. I need you to setup the database to make it happen, here's what I need..." and points at a schema drawn out on the wall with names of columns an datatypes.

"Location is everything!" he exclaims and walks off.

Your Job:

Create a single migration called CreateLocations, using the migrations generator, that will have these columns in place on the board.

Run the migrations with rails db:migrate

Step 2

"I don't even know what city and state these location are in!" says your boss. You wonder why he couldn't have done this right in the first place.

Your Job:

Create a migration called AddCityAndStateToLocations, using the migrations generator, that will add columns of city and state to the schema. City and state should each be of type string.

Run the migrations with rails db:migrate to apply the migrations.

Step 3

"I just read that places have colors. All our locations should have a color"

At this point you're pretty sure your boss has lost it, but he signs off on your paycheck so you're going to deal with it.

Your Job:

Create a migration called AddColorToLocations, using the migrations generator, that will add a column called color to the locations table with the datatype of string.

Run the migrations with rails db:migrate to apply the migrations.

Step 4

"Colors are so 2014. Now we need flavors!"

At this point, you're brushing up on your resume and making sure you know where the nearest emergency exit is, but tomorrow's payday and you're hoping for him to sign off on that check.

Your Job:

Create a migration called AddFlavorAndRemoveColorFromLocations, using the migrations generator. Add a column called flavor with datatype of string, and remove the column called color in the same migration.

Run the migrations with rails db:migrate to apply the migrations.

Step 5

"All things are for sale. Why don't we sell the locations? We need prices!"

Create a migration called AddPricesToLocations, using the migrations generator. Add a column called 'price' with datatype of decimal.

Run the migrations with rails db:migrate to apply the migrations.

Step 6

"Maybe that last one was a poor idea, let's talk a step back"

You did your job well, but he just can't make up his mind. Thankfully you've been getting some calls from recruiters and have an interview at Google on Tuesday.

Your Job:

Rollback the last migration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.