Froegin keys
This commit is contained in:
@@ -46,6 +46,6 @@ class DeviceJobsController < ApplicationController
|
|||||||
|
|
||||||
# Only allow a list of trusted parameters through.
|
# Only allow a list of trusted parameters through.
|
||||||
def device_job_params
|
def device_job_params
|
||||||
params.require(:device_job).permit(:device_id, :jobs_id, :status)
|
params.require(:device_job).permit(:device_id, :job_id, :status)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,6 +46,6 @@ class JobsController < ApplicationController
|
|||||||
|
|
||||||
# Only allow a list of trusted parameters through.
|
# Only allow a list of trusted parameters through.
|
||||||
def job_params
|
def job_params
|
||||||
params.require(:job).permit(:job_id, :params, :type)
|
params.require(:job).permit(:job_id, :params, :job_type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,7 @@
|
|||||||
class DeviceJob < ApplicationRecord
|
class DeviceJob < ApplicationRecord
|
||||||
end
|
# self.primary_key = :jobs_id, :device_id
|
||||||
|
belongs_to :job
|
||||||
|
belongs_to :device
|
||||||
|
# :foreign_key => [:user_id, :group_id]
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
class Job < ApplicationRecord
|
class Job < ApplicationRecord
|
||||||
|
|
||||||
|
has_many :device_jobs
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class CreateJobs < ActiveRecord::Migration[6.1]
|
|||||||
def change
|
def change
|
||||||
create_table :jobs do |t|
|
create_table :jobs do |t|
|
||||||
t.json :params
|
t.json :params
|
||||||
t.string :type
|
t.string :job_type
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
class CreateDeviceJobs < ActiveRecord::Migration[6.1]
|
class CreateDeviceJobs < ActiveRecord::Migration[6.1]
|
||||||
def change
|
def change
|
||||||
create_table :device_jobs do |t|
|
create_table :device_jobs, id: false do |t|
|
||||||
|
# t.references :job_id, references: :job, foreign_key: true # the owner
|
||||||
|
# t.references :device_id, references: :device, foreign_key: true # the invitee
|
||||||
t.integer :device_id
|
t.integer :device_id
|
||||||
t.integer :jobs_id
|
t.integer :job_id
|
||||||
t.string :status
|
t.string :status
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
add_index :device_jobs, :job_id
|
||||||
|
add_foreign_key :device_jobs, :jobs, column: :job_id
|
||||||
|
add_index :device_jobs, :device_id
|
||||||
|
add_foreign_key :device_jobs, :devices, column: :device_id
|
||||||
|
# execute "ALTER TABLE device_jobs ADD PRIMARY KEY (device_id, jobs_id);"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
16
db/schema.rb
generated
16
db/schema.rb
generated
@@ -10,11 +10,21 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_10_20_101118) do
|
ActiveRecord::Schema.define(version: 2021_10_21_061911) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
create_table "device_jobs", id: false, force: :cascade do |t|
|
||||||
|
t.integer "device_id"
|
||||||
|
t.integer "job_id"
|
||||||
|
t.string "status"
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.index ["device_id"], name: "index_device_jobs_on_device_id"
|
||||||
|
t.index ["job_id"], name: "index_device_jobs_on_job_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "devices", force: :cascade do |t|
|
create_table "devices", force: :cascade do |t|
|
||||||
t.string "device_id"
|
t.string "device_id"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
@@ -23,9 +33,11 @@ ActiveRecord::Schema.define(version: 2021_10_20_101118) do
|
|||||||
|
|
||||||
create_table "jobs", force: :cascade do |t|
|
create_table "jobs", force: :cascade do |t|
|
||||||
t.json "params"
|
t.json "params"
|
||||||
t.string "type"
|
t.string "job_type"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_foreign_key "device_jobs", "devices"
|
||||||
|
add_foreign_key "device_jobs", "jobs"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
test "should create job" do
|
test "should create job" do
|
||||||
assert_difference('Job.count') do
|
assert_difference('Job.count') do
|
||||||
post jobs_url, params: { job: { job_id: @job.job_id, params: @job.params, type: @job.type } }, as: :json
|
post jobs_url, params: { job: { job_id: @job.job_id, params: @job.params, job_type: @job.job_type } }, as: :json
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response 201
|
assert_response 201
|
||||||
@@ -24,7 +24,7 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should update job" do
|
test "should update job" do
|
||||||
patch job_url(@job), params: { job: { job_id: @job.job_id, params: @job.params, type: @job.type } }, as: :json
|
patch job_url(@job), params: { job: { job_id: @job.job_id, params: @job.params, job_type: @job.job_type } }, as: :json
|
||||||
assert_response 200
|
assert_response 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user