# 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 `rails
# db:schema:load`. When creating a new database, `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_03_31_084531) do

  create_table "clients", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "name", null: false
    t.string "contact"
    t.integer "status", default: 0
    t.string "creatd_by"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "data_overviews", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "item"
    t.integer "value"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "value2"
    t.integer "value3"
    t.integer "value4"
    t.integer "value5"
  end

  create_table "device_aging_tests", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
    t.string "mac"
    t.string "app_version"
    t.string "uname_info"
    t.string "lan_ip"
    t.string "ip"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "test_duration", default: 0
    t.string "uboot_md5", default: ""
    t.index ["mac"], name: "index_device_aging_tests_on_mac"
  end

  create_table "device_log_histories", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.bigint "device_log_id"
    t.string "mac", limit: 12, null: false
    t.datetime "hwtime"
    t.datetime "sys_time"
    t.string "request_ip"
    t.datetime "created_at", null: false
    t.string "software_version"
    t.index ["device_log_id"], name: "index_device_log_histories_on_device_log_id"
    t.index ["mac"], name: "index_device_log_histories_on_mac"
  end

  create_table "device_logs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "mac", limit: 12, null: false
    t.datetime "last_hwtime"
    t.datetime "last_sys_time"
    t.string "last_request_ip"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "software_version"
    t.integer "logs_count", default: 0
    t.index ["mac"], name: "index_device_logs_on_mac", unique: true
  end

  create_table "device_test_histories", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.bigint "device_test_id"
    t.string "mac"
    t.string "sn"
    t.string "ip"
    t.integer "result"
    t.text "log"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "test_type", default: 0
    t.string "app_version", default: ""
    t.string "vendor", default: "N/A"
    t.index ["device_test_id"], name: "index_device_test_histories_on_device_test_id"
  end

  create_table "device_tests", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "mac"
    t.string "sn"
    t.string "ip"
    t.integer "result"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "datetime_set", default: 0
    t.integer "screen_fixed", default: 0
    t.string "app_version", default: ""
    t.string "vendor", default: "N/A"
    t.integer "aging_test_count", default: 0
    t.index ["mac", "sn"], name: "index_device_tests_on_mac_and_sn"
    t.index ["mac"], name: "index_device_tests_on_mac"
    t.index ["sn"], name: "index_device_tests_on_sn"
  end

  create_table "devices", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "device_id"
    t.string "fireware_version"
    t.string "machine_model"
    t.string "bom_code"
    t.string "category"
    t.datetime "mfd"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.datetime "last_online_at"
    t.string "owner_name"
    t.string "owner_tel"
    t.string "country"
    t.string "province"
    t.boolean "is_old_version", default: false
  end

  create_table "hardware_test_logs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "mac"
    t.string "sn"
    t.string "ip"
    t.text "log"
    t.bigint "hardware_id"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["hardware_id"], name: "index_hardware_test_logs_on_hardware_id"
  end

  create_table "hardwares", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "sn"
    t.string "cpu"
    t.string "mac"
    t.string "oskernal"
    t.string "os"
    t.string "raminfo"
    t.string "modelname"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "uid"
    t.string "emmc"
    t.integer "test_count"
    t.integer "sn_changed_count", default: 0
    t.index ["mac"], name: "index_hardwares_on_mac", unique: true
    t.index ["sn"], name: "index_hardwares_on_sn", unique: true
  end

  create_table "mac_sources", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "mac_id", null: false
    t.string "uid", default: "", null: false
    t.string "sn"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["mac_id"], name: "index_mac_sources_on_mac_id", unique: true
  end

  create_table "materiel_items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.bigint "materiel_id", null: false
    t.string "sn", null: false
    t.string "name", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["materiel_id"], name: "index_materiel_items_on_materiel_id"
  end

  create_table "materiels", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "sn", null: false
    t.string "name", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "spec", limit: 40, default: ""
    t.string "created_by", limit: 40, default: ""
    t.index ["sn"], name: "index_materiels_on_sn", unique: true
  end

  create_table "order_items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.bigint "order_id", null: false
    t.bigint "materiel_id", null: false
    t.integer "quanlity"
    t.integer "current_quanlity"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["materiel_id"], name: "index_order_items_on_materiel_id"
    t.index ["order_id"], name: "index_order_items_on_order_id"
  end

  create_table "orders", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "sn", null: false
    t.integer "client_id", null: false
    t.datetime "due_date"
    t.datetime "confirmed_at"
    t.datetime "finished_at"
    t.string "created_by"
    t.integer "status", null: false
    t.text "remark"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["sn"], name: "index_orders_on_sn", unique: true
  end

  create_table "product_records", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "product_sn"
    t.bigint "product_id", null: false
    t.integer "shipping_box_id"
    t.string "type"
    t.integer "status"
    t.string "created_by"
    t.text "remark"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "lot_no"
    t.datetime "done_at"
    t.string "done_by", limit: 32
    t.string "location", default: ""
    t.index ["product_id"], name: "index_product_records_on_product_id"
    t.index ["type"], name: "index_product_records_on_type"
  end

  create_table "products", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "sn"
    t.bigint "materiel_id", null: false
    t.integer "status"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "lot_no"
    t.string "materiel_sn"
    t.string "location", default: ""
    t.index ["materiel_id"], name: "index_products_on_materiel_id"
  end

  create_table "roles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "name"
    t.text "permissions"
    t.integer "position"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "settings", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "var", null: false
    t.text "value"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["var"], name: "index_settings_on_var", unique: true
  end

  create_table "shipping_boxes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "part_no"
    t.string "lot_no"
    t.integer "qty"
    t.string "box_id"
    t.string "po"
    t.string "supplier"
    t.integer "status"
    t.datetime "shipping_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "client_id"
    t.string "created_by", default: ""
    t.index ["client_id"], name: "index_shipping_boxes_on_client_id"
  end

  create_table "sn_sources", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "category", null: false
    t.string "sn", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["sn"], name: "index_sn_sources_on_sn", unique: true
  end

  create_table "user_diseases", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.integer "user_id", null: false
    t.integer "disease_category_id", null: false
    t.text "remark"
    t.string "created_by"
    t.string "updated_by"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "true_name"
    t.integer "gender", default: 1, null: false
    t.datetime "birthday"
    t.string "tel"
    t.string "mobile"
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer "sign_in_count", default: 0, null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string "current_sign_in_ip"
    t.string "last_sign_in_ip"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "device_id", default: "000000", null: false
    t.string "username", default: "000000", null: false
    t.string "avatar"
    t.integer "role_id"
    t.string "company", default: ""
    t.integer "client_id"
    t.boolean "is_enabled", default: false
    t.index ["client_id"], name: "index_users_on_client_id"
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

  add_foreign_key "order_items", "materiels"
  add_foreign_key "order_items", "orders"
  add_foreign_key "product_records", "products"
  add_foreign_key "products", "materiels"
end
