From cfd4c0dd3253e4718bbb323df708dfd3599bed68 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sun, 15 Mar 2020 16:53:55 -0600 Subject: Switch to pg database --- .gitignore | 1 - rvh/Gemfile | 1 + rvh/Gemfile.lock | 2 + rvh/app/models/staff.rb | 4 +- rvh/config/application.rb | 2 + rvh/config/database.yml | 10 +++++ rvh/config/database.yml.sample | 8 ---- .../migrate/20200315180101_create_laboratories.rb | 10 +++++ rvh/db/migrate/20200315180102_create_staff.rb | 14 +++++++ rvh/db/migrate/20200315180103_create_patients.rb | 4 +- rvh/db/migrate/20200315181211_create_staff.rb | 14 ------- rvh/db/migrate/20200315183345_create_treatments.rb | 2 +- .../migrate/20200315183903_create_consumptions.rb | 2 +- .../migrate/20200315204511_create_laboratories.rb | 10 ----- rvh/db/migrate/mple_postgres | 0 rvh/db/schema.rb | 47 ++++++++++------------ 16 files changed, 67 insertions(+), 64 deletions(-) create mode 100644 rvh/config/database.yml delete mode 100644 rvh/config/database.yml.sample create mode 100644 rvh/db/migrate/20200315180101_create_laboratories.rb create mode 100644 rvh/db/migrate/20200315180102_create_staff.rb delete mode 100644 rvh/db/migrate/20200315181211_create_staff.rb delete mode 100644 rvh/db/migrate/20200315204511_create_laboratories.rb create mode 100644 rvh/db/migrate/mple_postgres diff --git a/.gitignore b/.gitignore index 100b7ac..891a8c9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ assignments/**/*.pdf db/data/ tmp *.sqlite* -database.yml diff --git a/rvh/Gemfile b/rvh/Gemfile index 5f29f3a..0e592c9 100644 --- a/rvh/Gemfile +++ b/rvh/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' +gem 'pg' gem 'rails', '~> 6.0' gem 'rails-erd', '~> 1.6' gem 'sqlite3', '~> 1.4' diff --git a/rvh/Gemfile.lock b/rvh/Gemfile.lock index ffe409e..b7dd29d 100644 --- a/rvh/Gemfile.lock +++ b/rvh/Gemfile.lock @@ -80,6 +80,7 @@ GEM nio4r (2.5.2) nokogiri (1.10.9) mini_portile2 (~> 2.4.0) + pg (1.2.2) rack (2.2.2) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -139,6 +140,7 @@ PLATFORMS ruby DEPENDENCIES + pg rails (~> 6.0) rails-erd (~> 1.6) sqlite3 (~> 1.4) diff --git a/rvh/app/models/staff.rb b/rvh/app/models/staff.rb index 5acf25d..8ac92cd 100644 --- a/rvh/app/models/staff.rb +++ b/rvh/app/models/staff.rb @@ -1,8 +1,8 @@ class Staff < ApplicationRecord belongs_to :account - belongs_to :laboratory + belongs_to :laboratory, optional: true has_many :treatments - serialize :qualifications, Array + attribute :qualifications, :string, array: true delegate :name, to: :account delegate :phone_number, to: :account diff --git a/rvh/config/application.rb b/rvh/config/application.rb index 14cc56a..2228a0a 100644 --- a/rvh/config/application.rb +++ b/rvh/config/application.rb @@ -9,5 +9,7 @@ module Rvh class Application < Rails::Application config.load_defaults 6.0 config.api_only = true + #config.active_record.schema_format = :sql + config.active_record.schema_format = :ruby end end diff --git a/rvh/config/database.yml b/rvh/config/database.yml new file mode 100644 index 0000000..ba21ec5 --- /dev/null +++ b/rvh/config/database.yml @@ -0,0 +1,10 @@ +default: &default + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + host: <%= "#{Dir.pwd}/../tmp/sockets" %> + +development: + <<: *default + database: rvh_development diff --git a/rvh/config/database.yml.sample b/rvh/config/database.yml.sample deleted file mode 100644 index 18e724b..0000000 --- a/rvh/config/database.yml.sample +++ /dev/null @@ -1,8 +0,0 @@ -default: &default - adapter: sqlite3 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - timeout: 5000 - -development: - <<: *default - database: db/development.sqlite3 diff --git a/rvh/db/migrate/20200315180101_create_laboratories.rb b/rvh/db/migrate/20200315180101_create_laboratories.rb new file mode 100644 index 0000000..6a45e84 --- /dev/null +++ b/rvh/db/migrate/20200315180101_create_laboratories.rb @@ -0,0 +1,10 @@ +class CreateLaboratories < ActiveRecord::Migration[6.0] + def change + create_table :laboratories do |t| + t.string :name + t.string :location + + t.timestamps + end + end +end diff --git a/rvh/db/migrate/20200315180102_create_staff.rb b/rvh/db/migrate/20200315180102_create_staff.rb new file mode 100644 index 0000000..63d8bfd --- /dev/null +++ b/rvh/db/migrate/20200315180102_create_staff.rb @@ -0,0 +1,14 @@ +class CreateStaff < ActiveRecord::Migration[6.0] + def change + create_table :staff do |t| + t.references :account, null: false, foreign_key: true, index: { unique: true } + t.references :laboratory, null: true, foreign_key: true + t.string :type + t.datetime :hired_at + # physician.specialty, technician.skill, nurse.certification, volunteer.skill + t.text :qualifications, array: true + t.timestamps + end + add_index :staff, :type + end +end diff --git a/rvh/db/migrate/20200315180103_create_patients.rb b/rvh/db/migrate/20200315180103_create_patients.rb index b08df6f..ba76fea 100644 --- a/rvh/db/migrate/20200315180103_create_patients.rb +++ b/rvh/db/migrate/20200315180103_create_patients.rb @@ -2,8 +2,8 @@ class CreatePatients < ActiveRecord::Migration[6.0] def change create_table :patients do |t| t.references :account, null: false, foreign_key: true, index: { unique: true } - t.references :physician, null: false, foreign_key: true - t.references :referring_physician, null: false, foreign_key: true + t.references :physician, null: false, foreign_key: { to_table: :staff } + t.references :referring_physician, null: false, foreign_key: { to_table: :staff } t.datetime :contacted_at, null: false t.timestamps diff --git a/rvh/db/migrate/20200315181211_create_staff.rb b/rvh/db/migrate/20200315181211_create_staff.rb deleted file mode 100644 index 63d8bfd..0000000 --- a/rvh/db/migrate/20200315181211_create_staff.rb +++ /dev/null @@ -1,14 +0,0 @@ -class CreateStaff < ActiveRecord::Migration[6.0] - def change - create_table :staff do |t| - t.references :account, null: false, foreign_key: true, index: { unique: true } - t.references :laboratory, null: true, foreign_key: true - t.string :type - t.datetime :hired_at - # physician.specialty, technician.skill, nurse.certification, volunteer.skill - t.text :qualifications, array: true - t.timestamps - end - add_index :staff, :type - end -end diff --git a/rvh/db/migrate/20200315183345_create_treatments.rb b/rvh/db/migrate/20200315183345_create_treatments.rb index c6f1016..7d6d77d 100644 --- a/rvh/db/migrate/20200315183345_create_treatments.rb +++ b/rvh/db/migrate/20200315183345_create_treatments.rb @@ -1,7 +1,7 @@ class CreateTreatments < ActiveRecord::Migration[6.0] def change create_table :treatments do |t| - t.references :physician, null: false, foreign_key: true + #t.references :physician, null: false, foreign_key: true t.references :patient, null: false, foreign_key: true t.string :name, null: false t.string :number, null: false diff --git a/rvh/db/migrate/20200315183903_create_consumptions.rb b/rvh/db/migrate/20200315183903_create_consumptions.rb index cdb0997..c46e434 100644 --- a/rvh/db/migrate/20200315183903_create_consumptions.rb +++ b/rvh/db/migrate/20200315183903_create_consumptions.rb @@ -2,7 +2,7 @@ class CreateConsumptions < ActiveRecord::Migration[6.0] def change create_table :consumptions do |t| t.references :patient, null: false, foreign_key: true - t.references :physician, null: false, foreign_key: true + #t.references :physician, null: false, foreign_key: true t.references :item, null: false, foreign_key: true t.datetime :consumed_at, null: false t.integer :quantity, null: false diff --git a/rvh/db/migrate/20200315204511_create_laboratories.rb b/rvh/db/migrate/20200315204511_create_laboratories.rb deleted file mode 100644 index 6a45e84..0000000 --- a/rvh/db/migrate/20200315204511_create_laboratories.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateLaboratories < ActiveRecord::Migration[6.0] - def change - create_table :laboratories do |t| - t.string :name - t.string :location - - t.timestamps - end - end -end diff --git a/rvh/db/migrate/mple_postgres b/rvh/db/migrate/mple_postgres new file mode 100644 index 0000000..e69de29 diff --git a/rvh/db/schema.rb b/rvh/db/schema.rb index bda5cef..7e2d0b3 100644 --- a/rvh/db/schema.rb +++ b/rvh/db/schema.rb @@ -10,7 +10,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_03_15_204511) do +ActiveRecord::Schema.define(version: 2020_03_15_190540) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" create_table "accounts", force: :cascade do |t| t.string "name", null: false @@ -25,8 +28,8 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do create_table "beds", force: :cascade do |t| t.string "bed_number" t.string "room_number" - t.integer "care_centre_id", null: false - t.integer "patient_id" + t.bigint "care_centre_id", null: false + t.bigint "patient_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["care_centre_id"], name: "index_beds_on_care_centre_id" @@ -34,7 +37,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "care_centres", force: :cascade do |t| - t.integer "nurse_id", null: false + t.bigint "nurse_id", null: false t.string "name" t.string "location" t.datetime "created_at", precision: 6, null: false @@ -43,9 +46,8 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "consumptions", force: :cascade do |t| - t.integer "patient_id", null: false - t.integer "physician_id", null: false - t.integer "item_id", null: false + t.bigint "patient_id", null: false + t.bigint "item_id", null: false t.datetime "consumed_at", null: false t.integer "quantity", null: false t.decimal "total_cost", null: false @@ -53,7 +55,6 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do t.datetime "updated_at", precision: 6, null: false t.index ["item_id"], name: "index_consumptions_on_item_id" t.index ["patient_id"], name: "index_consumptions_on_patient_id" - t.index ["physician_id"], name: "index_consumptions_on_physician_id" end create_table "items", force: :cascade do |t| @@ -72,9 +73,9 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "patients", force: :cascade do |t| - t.integer "account_id", null: false - t.integer "physician_id", null: false - t.integer "referring_physician_id", null: false + t.bigint "account_id", null: false + t.bigint "physician_id", null: false + t.bigint "referring_physician_id", null: false t.datetime "contacted_at", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false @@ -84,8 +85,8 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "shifts", force: :cascade do |t| - t.integer "care_centre_id", null: false - t.integer "employee_id", null: false + t.bigint "care_centre_id", null: false + t.bigint "employee_id", null: false t.datetime "started_at", null: false t.datetime "ended_at" t.datetime "created_at", precision: 6, null: false @@ -95,11 +96,11 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "staff", force: :cascade do |t| - t.integer "account_id", null: false - t.integer "laboratory_id" + t.bigint "account_id", null: false + t.bigint "laboratory_id" t.string "type" t.datetime "hired_at" - t.text "qualifications" + t.text "qualifications", array: true t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["account_id"], name: "index_staff_on_account_id", unique: true @@ -108,8 +109,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "treatments", force: :cascade do |t| - t.integer "physician_id", null: false - t.integer "patient_id", null: false + t.bigint "patient_id", null: false t.string "name", null: false t.string "number", null: false t.datetime "occurred_at", null: false @@ -117,11 +117,10 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["patient_id"], name: "index_treatments_on_patient_id" - t.index ["physician_id"], name: "index_treatments_on_physician_id" end create_table "visits", force: :cascade do |t| - t.integer "patient_id", null: false + t.bigint "patient_id", null: false t.datetime "scheduled_at", null: false t.text "comments" t.datetime "created_at", precision: 6, null: false @@ -130,7 +129,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do end create_table "volunteers", force: :cascade do |t| - t.integer "account_id", null: false + t.bigint "account_id", null: false t.text "skill", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false @@ -141,16 +140,14 @@ ActiveRecord::Schema.define(version: 2020_03_15_204511) do add_foreign_key "beds", "patients" add_foreign_key "consumptions", "items" add_foreign_key "consumptions", "patients" - add_foreign_key "consumptions", "physicians" add_foreign_key "patients", "accounts" - add_foreign_key "patients", "physicians" - add_foreign_key "patients", "referring_physicians" + add_foreign_key "patients", "staff", column: "physician_id" + add_foreign_key "patients", "staff", column: "referring_physician_id" add_foreign_key "shifts", "care_centres" add_foreign_key "shifts", "staff" add_foreign_key "staff", "accounts" add_foreign_key "staff", "laboratories" add_foreign_key "treatments", "patients" - add_foreign_key "treatments", "physicians" add_foreign_key "visits", "patients" add_foreign_key "volunteers", "accounts" end -- cgit v1.2.3