diff --git a/app/models/readout.rb b/app/models/readout.rb new file mode 100644 index 0000000..f8855be --- /dev/null +++ b/app/models/readout.rb @@ -0,0 +1,5 @@ +class Readout < ApplicationRecord + belongs_to :user + belongs_to :quantity + belongs_to :unit +end diff --git a/db/migrate/20250121230456_create_readouts.rb b/db/migrate/20250121230456_create_readouts.rb new file mode 100644 index 0000000..6a9b460 --- /dev/null +++ b/db/migrate/20250121230456_create_readouts.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 552f1b2..9b5c8ba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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