From 8f691b566ffbc79f1d2d7a3f67d8607cc03a789c Mon Sep 17 00:00:00 2001 From: hellekin Date: Thu, 8 Oct 2020 16:51:30 +0200 Subject: Add model foundation for classifications Taxonomy > Category > Section This commit adds models for it. https://doc.incommon.cc/#classifications --- db/migrate/20201008132251_create_taxonomies.rb | 16 ++++++++++ db/migrate/20201008132731_create_categories.rb | 15 +++++++++ db/migrate/20201008133300_create_sections.rb | 14 ++++++++ db/schema.rb | 44 +++++++++++++++++++++++++- db/seeds.rb | 10 ++++++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20201008132251_create_taxonomies.rb create mode 100644 db/migrate/20201008132731_create_categories.rb create mode 100644 db/migrate/20201008133300_create_sections.rb (limited to 'db') diff --git a/db/migrate/20201008132251_create_taxonomies.rb b/db/migrate/20201008132251_create_taxonomies.rb new file mode 100644 index 0000000..8c746b1 --- /dev/null +++ b/db/migrate/20201008132251_create_taxonomies.rb @@ -0,0 +1,16 @@ +class CreateTaxonomies < ActiveRecord::Migration[6.0] + def change + create_table :taxonomies do |t| + t.string :name, limit: 64 + t.string :summary, limit: 64 + t.text :description + t.uuid :uuid + t.integer :categories_count, default: 0 + t.references :agent, null: false, foreign_key: true + + t.timestamps + end + add_index :taxonomies, :name, unique: true + add_index :taxonomies, :uuid, unique: true + end +end diff --git a/db/migrate/20201008132731_create_categories.rb b/db/migrate/20201008132731_create_categories.rb new file mode 100644 index 0000000..eb5a6fa --- /dev/null +++ b/db/migrate/20201008132731_create_categories.rb @@ -0,0 +1,15 @@ +class CreateCategories < ActiveRecord::Migration[6.0] + def change + create_table :categories do |t| + t.string :name, limit: 64 + t.string :summary, limit: 136 + t.text :description + t.references :taxonomy, null: false, foreign_key: true + t.string :color, limit: 25 + t.integer :rank + t.integer :sections_count, default: 0 + + t.timestamps + end + end +end diff --git a/db/migrate/20201008133300_create_sections.rb b/db/migrate/20201008133300_create_sections.rb new file mode 100644 index 0000000..c71c055 --- /dev/null +++ b/db/migrate/20201008133300_create_sections.rb @@ -0,0 +1,14 @@ +class CreateSections < ActiveRecord::Migration[6.0] + def change + create_table :sections do |t| + t.string :name, limit: 64 + t.string :summary, limit: 136 + t.text :description + t.references :category, null: false, foreign_key: true + t.string :color, limit: 25 + t.integer :rank, default: 0 + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fbd0924..5a8bba7 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_06_140511) do +ActiveRecord::Schema.define(version: 2020_10_08_133300) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -35,6 +35,19 @@ ActiveRecord::Schema.define(version: 2020_10_06_140511) do t.index ["uuid"], name: "index_agents_on_uuid", unique: true end + create_table "categories", force: :cascade do |t| + t.string "name", limit: 64 + t.string "summary", limit: 136 + t.text "description" + t.bigint "taxonomy_id", null: false + t.string "color", limit: 25 + t.integer "rank" + t.integer "sections_count", default: 0 + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["taxonomy_id"], name: "index_categories_on_taxonomy_id" + end + create_table "resources", force: :cascade do |t| t.uuid "uuid" t.jsonb "feature" @@ -45,6 +58,32 @@ ActiveRecord::Schema.define(version: 2020_10_06_140511) do t.index ["uuid"], name: "index_resources_on_uuid", unique: true end + create_table "sections", force: :cascade do |t| + t.string "name", limit: 64 + t.string "summary", limit: 136 + t.text "description" + t.bigint "category_id", null: false + t.string "color", limit: 25 + t.integer "rank", default: 0 + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["category_id"], name: "index_sections_on_category_id" + end + + create_table "taxonomies", force: :cascade do |t| + t.string "name", limit: 64 + t.string "summary", limit: 64 + t.text "description" + t.uuid "uuid" + t.integer "categories_count", default: 0 + t.bigint "agent_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["agent_id"], name: "index_taxonomies_on_agent_id" + t.index ["name"], name: "index_taxonomies_on_name", unique: true + t.index ["uuid"], name: "index_taxonomies_on_uuid", unique: true + end + create_table "users", force: :cascade do |t| t.string "name" t.string "username" @@ -59,5 +98,8 @@ ActiveRecord::Schema.define(version: 2020_10_06_140511) do add_foreign_key "agencies", "agents" add_foreign_key "agencies", "users" + add_foreign_key "categories", "taxonomies" add_foreign_key "resources", "agents" + add_foreign_key "sections", "categories" + add_foreign_key "taxonomies", "agents" end diff --git a/db/seeds.rb b/db/seeds.rb index 3ee3a11..8a4c670 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -16,3 +16,13 @@ Agent.find_or_create_by(name: agent_name, uuid: uuid) end +dewey = Agent.find_by(uuid: '6347f151-6782-437c-8bae-55730672a76f') or die('Dewey Agent should be available by now!') + +# Create a default taxonomy +Taxonomy.find_or_create_by( + name: 'Dewey Maps Taxonomy', + summary: 'Original taxonomy used in Belgique, Mode d\'Emploi', + description: '## Dewey Maps Taxonomy', + uuid: '2519915f-d19c-4281-b758-f5ddb889d7fa', + agent_id: dewey.id +) -- cgit v1.2.3