From db7b3525e9406c369b9a8abf7f7844540d5192cd Mon Sep 17 00:00:00 2001 From: Maki Date: Mon, 19 Jul 2021 11:56:49 -0300 Subject: [PATCH] modelos --- app/models/measurement.rb | 3 ++ app/models/sensor.rb | 3 ++ config/database.yml | 1 + db/migrate/20210719142217_create_sensor.rb | 9 +++++ .../20210719142723_create_measurement.rb | 15 ++++++++ db/schema.rb | 38 +++++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 app/models/measurement.rb create mode 100644 app/models/sensor.rb create mode 100644 db/migrate/20210719142217_create_sensor.rb create mode 100644 db/migrate/20210719142723_create_measurement.rb create mode 100644 db/schema.rb diff --git a/app/models/measurement.rb b/app/models/measurement.rb new file mode 100644 index 0000000..7edfc38 --- /dev/null +++ b/app/models/measurement.rb @@ -0,0 +1,3 @@ +class Measurement < ApplicationRecord + belongs_to :sensor +end diff --git a/app/models/sensor.rb b/app/models/sensor.rb new file mode 100644 index 0000000..cea4c07 --- /dev/null +++ b/app/models/sensor.rb @@ -0,0 +1,3 @@ +class Sensor < ApplicationRecord + has_many :measurements +end diff --git a/config/database.yml b/config/database.yml index 10fb7ab..22167cd 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,6 +23,7 @@ default: &default development: <<: *default + host: postgresql.sutty.local database: ectomobile_development # The specified database role being used to connect to postgres. diff --git a/db/migrate/20210719142217_create_sensor.rb b/db/migrate/20210719142217_create_sensor.rb new file mode 100644 index 0000000..b1746db --- /dev/null +++ b/db/migrate/20210719142217_create_sensor.rb @@ -0,0 +1,9 @@ +class CreateSensor < ActiveRecord::Migration[6.1] + def change + create_table :sensors do |t| + + t.string :nombre, unique: true, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20210719142723_create_measurement.rb b/db/migrate/20210719142723_create_measurement.rb new file mode 100644 index 0000000..e4a6471 --- /dev/null +++ b/db/migrate/20210719142723_create_measurement.rb @@ -0,0 +1,15 @@ +class CreateMeasurement < ActiveRecord::Migration[6.1] + def change + create_table :measurements do |t| + + t.decimal :temperature + t.decimal :level + t.decimal :ph + t.decimal :turbidity + t.decimal :conductivity + t.decimal :flow + t.belongs_to :sensor, index: true + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..f4acf5c --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,38 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2021_07_19_142723) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "measurements", force: :cascade do |t| + t.decimal "temperature" + t.decimal "level" + t.decimal "ph" + t.decimal "turbidity" + t.decimal "conductivity" + t.decimal "flow" + t.bigint "sensor_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["sensor_id"], name: "index_measurements_on_sensor_id" + end + + create_table "sensors", force: :cascade do |t| + t.string "nombre" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["nombre"], name: "index_sensors_on_nombre" + end + +end