Skip to content

Commit 4c29504

Browse files
committed
Add Ingredient model to demonstrate deployment of update
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.
1 parent 8da6c25 commit 4c29504

File tree

10 files changed

+49
-3
lines changed

10 files changed

+49
-3
lines changed

app/models/ingredient.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Ingredient < ApplicationRecord
2+
end

app/views/welcome/show.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
<h1>Welcome</h1>
2+
3+
<p>Existing Recipes: <%= Recipe.count %></p>
4+
<p>Unique Ingredients: <%= Ingredient.count %></p>

config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Application < Rails::Application
2323

2424
config.generators do |g|
2525
g.test_framework :minitest, spec: true
26+
g.helper false
27+
g.javascript false
28+
g.stylesheet false
2629
end
2730
end
2831
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class CreateIngredients < ActiveRecord::Migration[5.0]
2+
def up
3+
create_table :ingredients do |t|
4+
t.string :name
5+
6+
t.timestamps
7+
end
8+
9+
Ingredient.create(name: "Olives")
10+
Ingredient.create(name: "lettuce")
11+
Ingredient.create(name: "Thyme")
12+
end
13+
14+
def down
15+
drop_table :ingredients
16+
end
17+
end

db/schema.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20161205100045) do
13+
ActiveRecord::Schema.define(version: 20170425120709) do
1414

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

18+
create_table "ingredients", force: :cascade do |t|
19+
t.string "name"
20+
t.datetime "created_at", null: false
21+
t.datetime "updated_at", null: false
22+
end
23+
1824
create_table "meal_plans", force: :cascade do |t|
1925
t.date "start_date", null: false
2026
t.date "end_date", null: false

deployments/mealplan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313
spec:
1414
containers:
1515
- name: mealplan
16-
image: us.gcr.io/mealplan-165022/mealplan:1.0.0
16+
image: us.gcr.io/mealplan-165022/mealplan:1.1.0
1717
ports:
1818
- name: rails
1919
containerPort: 3000

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
image: postgres
1010
env_file: .env
1111
volumes:
12-
- db-data:/var/lib/postgresql/db-data
12+
- db-data:/var/lib/postgresql/data
1313

1414
app:
1515
build: .

script/start

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ fi
66

77
if [[ $RAILS_ENV == "production" ]]; then
88
rake assets:precompile
9+
rake db:migrate
910
mkdir -p /usr/share/nginx/html
1011
cp -R public/* /usr/share/nginx/html
1112
mkdir -p /etc/nginx/conf.d/

test/factories/ingredients.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FactoryGirl.define do
2+
factory :ingredient do
3+
name "MyString"
4+
end
5+
end

test/models/ingredient_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "test_helper"
2+
3+
describe Ingredient do
4+
let(:ingredient) { Ingredient.new }
5+
6+
it "must be valid" do
7+
value(ingredient).must_be :valid?
8+
end
9+
end

0 commit comments

Comments
 (0)