This commit is contained in:
Maki 2021-07-19 11:56:49 -03:00
parent 4f02f8e728
commit db7b3525e9
6 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,3 @@
class Measurement < ApplicationRecord
belongs_to :sensor
end

3
app/models/sensor.rb Normal file
View file

@ -0,0 +1,3 @@
class Sensor < ApplicationRecord
has_many :measurements
end

View file

@ -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.

View file

@ -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

View file

@ -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

38
db/schema.rb generated Normal file
View file

@ -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