Skip to content

Commit

Permalink
migrate to pg
Browse files Browse the repository at this point in the history
  • Loading branch information
aisensiy committed Apr 20, 2017
1 parent 17f7b50 commit a0bce4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'jwt'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ GEM
nio4r (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
pg (0.19.0)
puma (3.8.2)
rack (2.0.1)
rack-cors (0.4.1)
Expand Down Expand Up @@ -117,7 +118,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.19.4)
thread_safe (0.3.6)
tzinfo (1.2.3)
Expand All @@ -135,12 +135,12 @@ DEPENDENCIES
byebug
jwt
listen (~> 3.0.5)
pg
puma (~> 3.0)
rack-cors
rails (~> 5.0.2)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
tzinfo-data

BUNDLED WITH
Expand Down
16 changes: 10 additions & 6 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
database: db/development.sqlite3
database: rails_survey_backend_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
database: rails_survey_backend_test

production:
<<: *default
database: db/production.sqlite3
database: rails_survey_backend_production
username: exame
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
6 changes: 3 additions & 3 deletions db/migrate/20170419091845_create_surveys.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class CreateSurveys < ActiveRecord::Migration[5.0]
def change
create_table :surveys do |t|
t.references :user_id, foreign_key: true
t.references :user, foreign_key: true
t.string :title
t.text :sub_title
t.text :questions
t.boolean :publish_results
t.boolean :receive_results
t.boolean :publish_results, default: false
t.boolean :receive_results, default: false

t.timestamps
end
Expand Down
9 changes: 7 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@

ActiveRecord::Schema.define(version: 20170419105840) do

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

create_table "results", force: :cascade do |t|
t.integer "survey_id"
t.text "result"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["survey_id"], name: "index_results_on_survey_id"
t.index ["survey_id"], name: "index_results_on_survey_id", using: :btree
end

create_table "surveys", force: :cascade do |t|
Expand All @@ -29,7 +32,7 @@
t.boolean "receive_results", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index [nil], name: "index_surveys_on_user_id_id"
t.index ["user_id"], name: "index_surveys_on_user_id", using: :btree
end

create_table "users", force: :cascade do |t|
Expand All @@ -40,4 +43,6 @@
t.datetime "updated_at", null: false
end

add_foreign_key "results", "surveys"
add_foreign_key "surveys", "users"
end

0 comments on commit a0bce4a

Please sign in to comment.