Skip to content

Commit 2d711be

Browse files
Add proper configuration for Postgres database and add Post model
1 parent 2cee688 commit 2d711be

File tree

6 files changed

+63
-20
lines changed

6 files changed

+63
-20
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
.byebug_history
2424
/public/packs
2525
/node_modules
26+
/coverage

app/models/post.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Post < ApplicationRecord
2+
validates :title, :content, presence: true
3+
end

config/database.yml

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
# SQLite version 3.x
2-
# gem install sqlite3
3-
#
4-
# Ensure the SQLite 3 gem is defined in your Gemfile
5-
# gem 'sqlite3'
6-
#
7-
default: &default
8-
adapter: sqlite3
9-
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
1+
development: &default
2+
adapter: postgresql
3+
database: blog_development
4+
encoding: utf8
5+
min_messages: warning
6+
pool: <%= Integer(ENV.fetch("DB_POOL", 5)) %>
7+
reaping_frequency: <%= Integer(ENV.fetch("DB_REAPING_FREQUENCY", 10)) %>
108
timeout: 5000
9+
host: postgres
10+
username: postgres
1111

12-
development:
13-
<<: *default
14-
database: db/development.sqlite3
15-
16-
# Warning: The database defined as "test" will be erased and
17-
# re-generated from your development database when you run "rake".
18-
# Do not set this db to the same as development or production.
1912
test:
2013
<<: *default
21-
database: db/test.sqlite3
14+
database: blog_test
2215

23-
production:
24-
<<: *default
25-
database: db/production.sqlite3
16+
production: &deploy
17+
encoding: utf8
18+
min_messages: warning
19+
pool: <%= [Integer(ENV.fetch("MAX_THREADS", 5)), Integer(ENV.fetch("DB_POOL", 5))].max %>
20+
timeout: 5000
21+
url: <%= ENV.fetch("DATABASE_URL", "") %>
22+
23+
staging: *deploy
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreatePosts < ActiveRecord::Migration[5.1]
2+
def change
3+
create_table :posts do |t|
4+
t.string :title
5+
t.text :content
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# Note that this schema.rb definition is the authoritative source for your
6+
# database schema. If you need to create the application database on another
7+
# system, you should be using db:schema:load, not running all the migrations
8+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9+
# you'll amass, the slower it'll run and the greater likelihood for issues).
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(version: 20170429141050) do
14+
15+
# These are extensions that must be enabled in order to support this database
16+
enable_extension "plpgsql"
17+
18+
create_table "posts", force: :cascade do |t|
19+
t.string "title"
20+
t.text "content"
21+
t.datetime "created_at", null: false
22+
t.datetime "updated_at", null: false
23+
end
24+
25+
end

spec/models/post_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Post, type: :model do
4+
it { is_expected.to validate_presence_of :title }
5+
it { is_expected.to validate_presence_of :content }
6+
end

0 commit comments

Comments
 (0)