diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | app/models/agent.rb | 1 | ||||
-rw-r--r-- | app/models/resource.rb | 6 | ||||
-rw-r--r-- | db/migrate/20201006140511_create_resources.rb | 13 | ||||
-rw-r--r-- | db/schema.rb | 10 |
6 files changed, 34 insertions, 1 deletions
@@ -28,6 +28,8 @@ gem 'jbuilder', '~> 2.7' gem 'bitfields' # Use Discourse API gem 'discourse_api' +# Enforce stable UUIDs for models +gem 'uuid_parameter', '~> 0.2.5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 224b6dc..7a464f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -178,6 +178,8 @@ GEM turbolinks-source (5.2.0) tzinfo (1.2.7) thread_safe (~> 0.1) + uuid_parameter (0.2.6) + rails (>= 5.2.1) web-console (4.0.4) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -213,6 +215,7 @@ DEPENDENCIES spring-watcher-listen (~> 2.0.0) turbolinks (~> 5) tzinfo-data + uuid_parameter (~> 0.2.5) web-console (>= 3.3.0) webpacker (~> 4.0) diff --git a/app/models/agent.rb b/app/models/agent.rb index bb33c1b..07e0b8e 100644 --- a/app/models/agent.rb +++ b/app/models/agent.rb @@ -1,4 +1,5 @@ class Agent < ApplicationRecord has_many :agencies has_many :members, through: :agencies, source: :user + has_many :resources end diff --git a/app/models/resource.rb b/app/models/resource.rb new file mode 100644 index 0000000..ba3dd1f --- /dev/null +++ b/app/models/resource.rb @@ -0,0 +1,6 @@ +class Resource < ApplicationRecord + # Universally Unique Identifier :uuid + include UUIDParameter + + belongs_to :agent +end diff --git a/db/migrate/20201006140511_create_resources.rb b/db/migrate/20201006140511_create_resources.rb new file mode 100644 index 0000000..761d5bc --- /dev/null +++ b/db/migrate/20201006140511_create_resources.rb @@ -0,0 +1,13 @@ +class CreateResources < ActiveRecord::Migration[6.0] + def change + create_table :resources do |t| + t.uuid :uuid + t.jsonb :feature + t.references :agent, null: false, foreign_key: true + + t.timestamps + end + add_index :resources, [:uuid], unique: true + add_index :resources, [:agent_id] + end +end diff --git a/db/schema.rb b/db/schema.rb index ef4f4cd..8433cd9 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.define(version: 2020_10_05_155004) do +ActiveRecord::Schema.define(version: 2020_10_06_140511) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -34,6 +34,14 @@ ActiveRecord::Schema.define(version: 2020_10_05_155004) do t.index ["uuid"], name: "index_agents_on_uuid", unique: true end + create_table "resources", force: :cascade do |t| + t.uuid "uuid" + t.jsonb "feature" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["uuid"], name: "index_resources_on_uuid", unique: true + end + create_table "users", force: :cascade do |t| t.string "name" t.string "username" |