From 003b5615a0cddc2e64db097f6f2d1649f3b1358b Mon Sep 17 00:00:00 2001 From: Derek Ekins Date: Tue, 8 Oct 2019 22:06:32 +0100 Subject: [PATCH] added postgres database --- Gemfile | 1 + Gemfile.lock | 2 ++ app/models/initiative.rb | 6 ++---- config/database.yml | 38 ++++++++++++++++++-------------------- db/schema.rb | 15 +++++++++------ nuke | 7 ++++++- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 600a482..dbea61c 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,7 @@ gem 'jbuilder', '~> 2.7' gem 'bootsnap', '>= 1.4.2', require: false gem 'devise' gem 'komponent', '>= 3.0.0.beta1' +gem 'pg' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index a66c4bf..077d2d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,6 +126,7 @@ GEM parallel (1.17.0) parser (2.6.4.0) ast (~> 2.4.0) + pg (1.1.4) public_suffix (3.1.1) puma (3.12.1) rack (2.0.7) @@ -250,6 +251,7 @@ DEPENDENCIES jbuilder (~> 2.7) komponent (>= 3.0.0.beta1) listen (>= 3.0.5, < 3.2) + pg puma (~> 3.11) rails (~> 6.0.0) rails_best_practices diff --git a/app/models/initiative.rb b/app/models/initiative.rb index 89b4e42..b374e00 100644 --- a/app/models/initiative.rb +++ b/app/models/initiative.rb @@ -8,10 +8,8 @@ class Initiative < ApplicationRecord after_initialize :set_default_location def set_default_location - return if persisted? - - self.latitude = 51.742 - self.longitude = -2.222 + self.latitude ||= 51.742 + self.longitude ||= -2.222 end # rubocop:disable Metrics/MethodLength diff --git a/config/database.yml b/config/database.yml index 4a8a1b2..96e1585 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,25 +1,23 @@ -# SQLite. Versions 3.8.0 and up are supported. -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# -default: &default - adapter: sqlite3 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - timeout: 5000 - development: - <<: *default - database: db/development.sqlite3 + adapter: postgresql + encoding: unicode + database: carbon_map_development + pool: 5 + username: + password: -# 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 + adapter: postgresql + encoding: unicode + database: carbon_map_test + pool: 5 + username: + password: production: - <<: *default - database: db/production.sqlite3 + adapter: postgresql + encoding: unicode + database: carbon_map_production + pool: 5 + username: + password: diff --git a/db/schema.rb b/db/schema.rb index 3f8c9f8..b944072 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,9 +11,12 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_10_05_213108) do + # These are extensions that must be enabled in order to support this database + enable_extension 'plpgsql' + create_table 'group_group_types', force: :cascade do |t| - t.integer 'group_id', null: false - t.integer 'group_type_id', null: false + t.bigint 'group_id', null: false + t.bigint 'group_type_id', null: false t.datetime 'created_at', precision: 6, null: false t.datetime 'updated_at', precision: 6, null: false t.index %w[group_id], name: 'index_group_group_types_on_group_id' @@ -28,7 +31,7 @@ create_table 'group_websites', force: :cascade do |t| t.string 'website' - t.integer 'group_id', null: false + t.bigint 'group_id', null: false t.datetime 'created_at', precision: 6, null: false t.datetime 'updated_at', precision: 6, null: false t.index %w[group_id], name: 'index_group_websites_on_group_id' @@ -43,7 +46,7 @@ t.string 'contact_phone' t.boolean 'gdpr' t.boolean 'gdpr_email_verified' - t.integer 'owner_id' + t.bigint 'owner_id' t.datetime 'created_at', precision: 6, null: false t.datetime 'updated_at', precision: 6, null: false t.index %w[owner_id], name: 'index_groups_on_owner_id' @@ -64,12 +67,12 @@ t.string 'locality' t.string 'location' t.string 'alternative_solution_name' - t.integer 'lead_group_id', null: false + t.bigint 'lead_group_id', null: false t.string 'contact_name' t.string 'contact_email' t.string 'contact_phone' t.string 'partner_groups_role' - t.integer 'status_id', null: false + t.bigint 'status_id', null: false t.boolean 'gdpr' t.boolean 'gdpr_email_verified' t.datetime 'created_at', precision: 6, null: false diff --git a/nuke b/nuke index 03e39b3..76a048d 100755 --- a/nuke +++ b/nuke @@ -1 +1,6 @@ -rails db:drop db:migrate db:seed +#!/usr/bin/env bash + +set -e + +rails db:drop db:create db:migrate +rails db:seed