Skip to content

Commit

Permalink
Add Ingredient model to demonstrate deployment of update
Browse files Browse the repository at this point in the history
This commit adds an additional model to the application for the
purpose of showing how we would go about deploying an application
update to our app that is running in a Kubernetes cluster. We address
the application update portion and also the database migration portion.
  • Loading branch information
keiththomps committed Apr 26, 2017
1 parent 8da6c25 commit 4c29504
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/ingredient.rb
@@ -0,0 +1,2 @@
class Ingredient < ApplicationRecord
end
3 changes: 3 additions & 0 deletions app/views/welcome/show.html.erb
@@ -1 +1,4 @@
<h1>Welcome</h1>

<p>Existing Recipes: <%= Recipe.count %></p>
<p>Unique Ingredients: <%= Ingredient.count %></p>
3 changes: 3 additions & 0 deletions config/application.rb
Expand Up @@ -23,6 +23,9 @@ class Application < Rails::Application

config.generators do |g|
g.test_framework :minitest, spec: true
g.helper false
g.javascript false
g.stylesheet false
end
end
end
17 changes: 17 additions & 0 deletions db/migrate/20170425120709_create_ingredients.rb
@@ -0,0 +1,17 @@
class CreateIngredients < ActiveRecord::Migration[5.0]
def up
create_table :ingredients do |t|
t.string :name

t.timestamps
end

Ingredient.create(name: "Olives")
Ingredient.create(name: "lettuce")
Ingredient.create(name: "Thyme")
end

def down
drop_table :ingredients
end
end
8 changes: 7 additions & 1 deletion db/schema.rb
Expand Up @@ -10,11 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161205100045) do
ActiveRecord::Schema.define(version: 20170425120709) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "ingredients", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "meal_plans", force: :cascade do |t|
t.date "start_date", null: false
t.date "end_date", null: false
Expand Down
2 changes: 1 addition & 1 deletion deployments/mealplan.yml
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: mealplan
image: us.gcr.io/mealplan-165022/mealplan:1.0.0
image: us.gcr.io/mealplan-165022/mealplan:1.1.0
ports:
- name: rails
containerPort: 3000
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Expand Up @@ -9,7 +9,7 @@ services:
image: postgres
env_file: .env
volumes:
- db-data:/var/lib/postgresql/db-data
- db-data:/var/lib/postgresql/data

app:
build: .
Expand Down
1 change: 1 addition & 0 deletions script/start
Expand Up @@ -6,6 +6,7 @@ fi

if [[ $RAILS_ENV == "production" ]]; then
rake assets:precompile
rake db:migrate
mkdir -p /usr/share/nginx/html
cp -R public/* /usr/share/nginx/html
mkdir -p /etc/nginx/conf.d/
Expand Down
5 changes: 5 additions & 0 deletions test/factories/ingredients.rb
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :ingredient do
name "MyString"
end
end
9 changes: 9 additions & 0 deletions test/models/ingredient_test.rb
@@ -0,0 +1,9 @@
require "test_helper"

describe Ingredient do
let(:ingredient) { Ingredient.new }

it "must be valid" do
value(ingredient).must_be :valid?
end
end

0 comments on commit 4c29504

Please sign in to comment.