forked from fixin.me/fixin.me
Create Readout model
This commit is contained in:
parent
6300273186
commit
3d7daa8944
5
app/models/readout.rb
Normal file
5
app/models/readout.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class Readout < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :quantity
|
||||
belongs_to :unit
|
||||
end
|
15
db/migrate/20250121230456_create_readouts.rb
Normal file
15
db/migrate/20250121230456_create_readouts.rb
Normal 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
|
18
db/schema.rb
18
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user