Create Readout model

This commit is contained in:
cryptogopher 2025-01-22 00:14:15 +01:00
parent 6300273186
commit 3d7daa8944
3 changed files with 37 additions and 1 deletions

5
app/models/readout.rb Normal file
View File

@ -0,0 +1,5 @@
class Readout < ApplicationRecord
belongs_to :user
belongs_to :quantity
belongs_to :unit
end

View File

@ -0,0 +1,15 @@
class CreateReadouts < ActiveRecord::Migration[7.2]
def change
create_table :readouts do |t|
t.references :user, null: false, foreign_key: true
t.references :quantity, null: false, foreign_key: true
t.references :unit, foreign_key: true
t.decimal :value, null: false, precision: 30, scale: 15
#t.references :collector, foreign_key: true
#t.references :device, foreign_key: true
t.timestamps null: false
end
add_index :readouts, [:quantity_id, :created_at], unique: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2025_01_04_194343) do
ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
create_table "quantities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "user_id"
t.string "name", limit: 31, null: false
@ -24,6 +24,19 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_04_194343) do
t.index ["user_id"], name: "index_quantities_on_user_id"
end
create_table "readouts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "quantity_id", null: false
t.bigint "unit_id"
t.decimal "value", precision: 30, scale: 15, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["quantity_id", "created_at"], name: "index_readouts_on_quantity_id_and_created_at", unique: true
t.index ["quantity_id"], name: "index_readouts_on_quantity_id"
t.index ["unit_id"], name: "index_readouts_on_unit_id"
t.index ["user_id"], name: "index_readouts_on_user_id"
end
create_table "units", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "user_id"
t.string "symbol", limit: 15, null: false
@ -57,6 +70,9 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_04_194343) do
add_foreign_key "quantities", "quantities", column: "parent_id"
add_foreign_key "quantities", "users"
add_foreign_key "readouts", "quantities"
add_foreign_key "readouts", "units"
add_foreign_key "readouts", "users"
add_foreign_key "units", "units", column: "base_id"
add_foreign_key "units", "users"
end