Froegin keys

This commit is contained in:
2021-10-26 12:44:05 +02:00
parent f76b125f84
commit beec4a00de
8 changed files with 37 additions and 10 deletions

View File

@@ -2,7 +2,7 @@ class CreateJobs < ActiveRecord::Migration[6.1]
def change
create_table :jobs do |t|
t.json :params
t.string :type
t.string :job_type
t.timestamps
end

View File

@@ -1,11 +1,19 @@
class CreateDeviceJobs < ActiveRecord::Migration[6.1]
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 :jobs_id
t.integer :job_id
t.string :status
t.timestamps
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

16
db/schema.rb generated
View File

@@ -10,11 +10,21 @@
#
# 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
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|
t.string "device_id"
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|
t.json "params"
t.string "type"
t.string "job_type"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
add_foreign_key "device_jobs", "devices"
add_foreign_key "device_jobs", "jobs"
end