From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- db/migrate/20240224162412_create_things.rb | 23 ++++ db/migrate/20240224164039_create_users.rb | 10 ++ db/migrate/20240224165311_create_comments.rb | 10 ++ ..._create_active_storage_tables.active_storage.rb | 57 +++++++++ ...165704_create_action_text_tables.action_text.rb | 26 ++++ db/migrate/20240224220515_create_tags.rb | 9 ++ db/migrate/20240225070152_create_tag_references.rb | 10 ++ db/migrate/20240225071927_create_searches.rb | 11 ++ db/migrate/20240225100002_add_note_to_things.rb | 5 + .../20240226063134_add_uniqueness_index_search.rb | 8 ++ .../20240227085442_add_last_search_id_to_users.rb | 5 + db/migrate/20240227145317_add_authors_to_thing.rb | 6 + .../20240301154452_add_shared_to_searches.rb | 5 + .../20240307220309_add_where_is_it_to_things.rb | 5 + ...13133513_change_access_and_bought_at_to_date.rb | 6 + db/schema.rb | 131 +++++++++++++++++++++ db/seeds.rb | 118 +++++++++++++++++++ 17 files changed, 445 insertions(+) create mode 100644 db/migrate/20240224162412_create_things.rb create mode 100644 db/migrate/20240224164039_create_users.rb create mode 100644 db/migrate/20240224165311_create_comments.rb create mode 100644 db/migrate/20240224165703_create_active_storage_tables.active_storage.rb create mode 100644 db/migrate/20240224165704_create_action_text_tables.action_text.rb create mode 100644 db/migrate/20240224220515_create_tags.rb create mode 100644 db/migrate/20240225070152_create_tag_references.rb create mode 100644 db/migrate/20240225071927_create_searches.rb create mode 100644 db/migrate/20240225100002_add_note_to_things.rb create mode 100644 db/migrate/20240226063134_add_uniqueness_index_search.rb create mode 100644 db/migrate/20240227085442_add_last_search_id_to_users.rb create mode 100644 db/migrate/20240227145317_add_authors_to_thing.rb create mode 100644 db/migrate/20240301154452_add_shared_to_searches.rb create mode 100644 db/migrate/20240307220309_add_where_is_it_to_things.rb create mode 100644 db/migrate/20240313133513_change_access_and_bought_at_to_date.rb create mode 100644 db/schema.rb create mode 100644 db/seeds.rb (limited to 'db') diff --git a/db/migrate/20240224162412_create_things.rb b/db/migrate/20240224162412_create_things.rb new file mode 100644 index 0000000..5fca815 --- /dev/null +++ b/db/migrate/20240224162412_create_things.rb @@ -0,0 +1,23 @@ +class CreateThings < ActiveRecord::Migration[7.1] + def change + create_table :things do |t| + t.string :target + t.string :title, null: false, index: { unique: true } + t.string :publisher + t.string :address + t.integer :year + t.string :url + t.datetime :access + t.string :location + t.string :insideof + t.string :pages + t.references :user, null: false, foreign_key: true + t.integer :rate + t.integer :status + t.integer :kind + t.datetime :bought_at + + t.timestamps + end + end +end diff --git a/db/migrate/20240224164039_create_users.rb b/db/migrate/20240224164039_create_users.rb new file mode 100644 index 0000000..cfd4944 --- /dev/null +++ b/db/migrate/20240224164039_create_users.rb @@ -0,0 +1,10 @@ +class CreateUsers < ActiveRecord::Migration[7.1] + def change + create_table :users do |t| + t.string :username, null: false, index: { unique: true } + t.string :password_digest + + t.timestamps + end + end +end diff --git a/db/migrate/20240224165311_create_comments.rb b/db/migrate/20240224165311_create_comments.rb new file mode 100644 index 0000000..49cb989 --- /dev/null +++ b/db/migrate/20240224165311_create_comments.rb @@ -0,0 +1,10 @@ +class CreateComments < ActiveRecord::Migration[7.1] + def change + create_table :comments do |t| + t.references :thing, null: false, foreign_key: true + t.text :content + + t.timestamps + end + end +end diff --git a/db/migrate/20240224165703_create_active_storage_tables.active_storage.rb b/db/migrate/20240224165703_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..e4706aa --- /dev/null +++ b/db/migrate/20240224165703_create_active_storage_tables.active_storage.rb @@ -0,0 +1,57 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[7.0] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :active_storage_blobs, id: primary_key_type do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :key ], unique: true + end + + create_table :active_storage_attachments, id: primary_key_type do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + t.references :blob, null: false, type: foreign_key_type + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + + create_table :active_storage_variant_records, id: primary_key_type do |t| + t.belongs_to :blob, null: false, index: false, type: foreign_key_type + t.string :variation_digest, null: false + + t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/migrate/20240224165704_create_action_text_tables.action_text.rb b/db/migrate/20240224165704_create_action_text_tables.action_text.rb new file mode 100644 index 0000000..1be48d7 --- /dev/null +++ b/db/migrate/20240224165704_create_action_text_tables.action_text.rb @@ -0,0 +1,26 @@ +# This migration comes from action_text (originally 20180528164100) +class CreateActionTextTables < ActiveRecord::Migration[6.0] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :action_text_rich_texts, id: primary_key_type do |t| + t.string :name, null: false + t.text :body, size: :long + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + + t.timestamps + + t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/migrate/20240224220515_create_tags.rb b/db/migrate/20240224220515_create_tags.rb new file mode 100644 index 0000000..7db0657 --- /dev/null +++ b/db/migrate/20240224220515_create_tags.rb @@ -0,0 +1,9 @@ +class CreateTags < ActiveRecord::Migration[7.1] + def change + create_table :tags do |t| + t.string :name, null: false, index: { unique: true } + + t.timestamps + end + end +end diff --git a/db/migrate/20240225070152_create_tag_references.rb b/db/migrate/20240225070152_create_tag_references.rb new file mode 100644 index 0000000..ba945a8 --- /dev/null +++ b/db/migrate/20240225070152_create_tag_references.rb @@ -0,0 +1,10 @@ +class CreateTagReferences < ActiveRecord::Migration[7.1] + def change + create_table :tag_references do |t| + t.references :tag, null: false, foreign_key: true + t.references :taggable, null: false, polymorphic: true + + t.timestamps + end + end +end diff --git a/db/migrate/20240225071927_create_searches.rb b/db/migrate/20240225071927_create_searches.rb new file mode 100644 index 0000000..a2a42e7 --- /dev/null +++ b/db/migrate/20240225071927_create_searches.rb @@ -0,0 +1,11 @@ +class CreateSearches < ActiveRecord::Migration[7.1] + def change + create_table :searches do |t| + t.string :name + t.string :body + t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20240225100002_add_note_to_things.rb b/db/migrate/20240225100002_add_note_to_things.rb new file mode 100644 index 0000000..b0c0f40 --- /dev/null +++ b/db/migrate/20240225100002_add_note_to_things.rb @@ -0,0 +1,5 @@ +class AddNoteToThings < ActiveRecord::Migration[7.1] + def change + add_column :things, :note, :string + end +end diff --git a/db/migrate/20240226063134_add_uniqueness_index_search.rb b/db/migrate/20240226063134_add_uniqueness_index_search.rb new file mode 100644 index 0000000..77247df --- /dev/null +++ b/db/migrate/20240226063134_add_uniqueness_index_search.rb @@ -0,0 +1,8 @@ +class AddUniquenessIndexSearch < ActiveRecord::Migration[7.1] + def change + add_index :searches, :name, unique: true + add_index :searches, :body, unique: true + + add_index :things, :target, unique: true + end +end diff --git a/db/migrate/20240227085442_add_last_search_id_to_users.rb b/db/migrate/20240227085442_add_last_search_id_to_users.rb new file mode 100644 index 0000000..be58999 --- /dev/null +++ b/db/migrate/20240227085442_add_last_search_id_to_users.rb @@ -0,0 +1,5 @@ +class AddLastSearchIdToUsers < ActiveRecord::Migration[7.1] + def change + add_column :users, :last_search_id, :integer + end +end diff --git a/db/migrate/20240227145317_add_authors_to_thing.rb b/db/migrate/20240227145317_add_authors_to_thing.rb new file mode 100644 index 0000000..0c26b81 --- /dev/null +++ b/db/migrate/20240227145317_add_authors_to_thing.rb @@ -0,0 +1,6 @@ +class AddAuthorsToThing < ActiveRecord::Migration[7.1] + def change + add_column :things, :authors, :string, null: false + add_column :things, :editors, :boolean, default: false + end +end diff --git a/db/migrate/20240301154452_add_shared_to_searches.rb b/db/migrate/20240301154452_add_shared_to_searches.rb new file mode 100644 index 0000000..4950c23 --- /dev/null +++ b/db/migrate/20240301154452_add_shared_to_searches.rb @@ -0,0 +1,5 @@ +class AddSharedToSearches < ActiveRecord::Migration[7.1] + def change + add_column :searches, :shared, :boolean, default: false + end +end diff --git a/db/migrate/20240307220309_add_where_is_it_to_things.rb b/db/migrate/20240307220309_add_where_is_it_to_things.rb new file mode 100644 index 0000000..6d18307 --- /dev/null +++ b/db/migrate/20240307220309_add_where_is_it_to_things.rb @@ -0,0 +1,5 @@ +class AddWhereIsItToThings < ActiveRecord::Migration[7.1] + def change + add_column :things, :where_is_it, :string + end +end diff --git a/db/migrate/20240313133513_change_access_and_bought_at_to_date.rb b/db/migrate/20240313133513_change_access_and_bought_at_to_date.rb new file mode 100644 index 0000000..ea2f5bd --- /dev/null +++ b/db/migrate/20240313133513_change_access_and_bought_at_to_date.rb @@ -0,0 +1,6 @@ +class ChangeAccessAndBoughtAtToDate < ActiveRecord::Migration[7.1] + def change + change_column :things, :access, :date + change_column :things, :bought_at, :date + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..967b074 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,131 @@ +# 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 `bin/rails +# db:schema:load`. When creating a new database, `bin/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[7.1].define(version: 2024_03_13_133513) do + create_table "action_text_rich_texts", force: :cascade do |t| + t.string "name", null: false + t.text "body" + t.string "record_type", null: false + t.bigint "record_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true + end + + create_table "active_storage_attachments", force: :cascade do |t| + t.string "name", null: false + t.string "record_type", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false + t.datetime "created_at", null: false + t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true + end + + create_table "active_storage_blobs", force: :cascade do |t| + t.string "key", null: false + t.string "filename", null: false + t.string "content_type" + t.text "metadata" + t.string "service_name", null: false + t.bigint "byte_size", null: false + t.string "checksum" + t.datetime "created_at", null: false + t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true + end + + create_table "active_storage_variant_records", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + + create_table "comments", force: :cascade do |t| + t.integer "thing_id", null: false + t.text "content" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["thing_id"], name: "index_comments_on_thing_id" + end + + create_table "searches", force: :cascade do |t| + t.string "name" + t.string "body" + t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "shared", default: false + t.index ["body"], name: "index_searches_on_body", unique: true + t.index ["name"], name: "index_searches_on_name", unique: true + t.index ["user_id"], name: "index_searches_on_user_id" + end + + create_table "tag_references", force: :cascade do |t| + t.integer "tag_id", null: false + t.string "taggable_type", null: false + t.integer "taggable_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["tag_id"], name: "index_tag_references_on_tag_id" + t.index ["taggable_type", "taggable_id"], name: "index_tag_references_on_taggable" + end + + create_table "tags", force: :cascade do |t| + t.string "name", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["name"], name: "index_tags_on_name", unique: true + end + + create_table "things", force: :cascade do |t| + t.string "target" + t.string "title", null: false + t.string "publisher" + t.string "address" + t.integer "year" + t.string "url" + t.date "access" + t.string "location" + t.string "insideof" + t.string "pages" + t.integer "user_id", null: false + t.integer "rate" + t.integer "status" + t.integer "kind" + t.date "bought_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "note" + t.string "authors", null: false + t.boolean "editors", default: false + t.string "where_is_it" + t.index ["target"], name: "index_things_on_target", unique: true + t.index ["title"], name: "index_things_on_title", unique: true + t.index ["user_id"], name: "index_things_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "username", null: false + t.string "password_digest" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "last_search_id" + t.index ["username"], name: "index_users_on_username", unique: true + end + + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" + add_foreign_key "comments", "things" + add_foreign_key "searches", "users" + add_foreign_key "tag_references", "tags" + add_foreign_key "things", "users" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..6e07c8b --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,118 @@ +# frozen_string_literal: true + +return unless Rails.env == 'development' + +u = User.find_by(username: 'user') +unless u + u = User.new(username: 'user', password: '12341234', password_confirmation: '12341234') + u.save! +end + +## +# Books, articles, whatever. + +[ + { + target: 'Rossich2006', + title: 'Poesia catalana del barroc. Antologia', + authors: 'Albert Rossich, Pep Valsalobre', + publisher: 'Edicions Vitel·la', + address: "Bellcaire d'Empordà", + year: 2006, + kind: Thing.kinds[:poetry], + status: Thing.statuses[:read], + rate: 10, + user: u + }, + { + target: 'OvidiMetamorfosisParramon', + title: 'Metamorfosis', + authors: 'Ovidi', + publisher: 'Quaderns Crema', + address: 'Barcelona', + note: 'Traducció en versos a càrrec de Jordi Parramon', + year: 2000, + kind: Thing.kinds[:poetry], + status: Thing.statuses[:read], + rate: 10, + user: u + }, + { + target: 'Rossich2023', + title: "Sou lo que podeu mostrar que haveu begut d'aquesta font", + authors: 'Eulàlia Miralles, Marc Sogues, Pep Valsalobre', + editors: true, + publisher: 'Editorial Afers', + address: 'Catarroja - Barcelona', + note: 'Homenatge al professor Albert Rossich', + year: 2023, + kind: Thing.kinds[:essay], + status: Thing.statuses[:notread], + rate: 10, + user: u + }, + { + target: 'EuripidesIX2', + title: "Tragèdies. IX, 2", + authors: 'Eurípides', + publisher: 'Fundació Bernat Metge', + address: 'Barcelona', + note: 'Ifigènia a Àulida', + year: 2023, + kind: Thing.kinds[:theater], + status: Thing.statuses[:notread], + rate: 10, + user: u + }, + { + target: 'RodoredaContes', + title: "Tots els contes", + authors: 'Mercè Rodoreda', + publisher: 'Edicions 62 - labutxaca', + address: 'Barcelona', + note: 'Segona edició', + year: 2017, + kind: Thing.kinds[:shorts], + status: Thing.statuses[:read], + rate: 8, + user: u + }, + { + target: 'CussaEmperador', + title: 'El primer emperador i la reina Lluna', + authors: 'Jordi Cussà', + publisher: 'Comanegra', + address: 'Barcelona', + note: '', + year: 2020, + kind: Thing.kinds[:novel], + status: Thing.statuses[:read], + rate: 9, + user: u + } +].each { |params| Thing.find_or_create_by!(params) } + +## +# Comments + +Thing.find_by(target: 'Rossich2006').comments.find_or_create_by!(content: 'Primer comentari a Rossich') +Thing.find_by(target: 'Rossich2006').comments.find_or_create_by!(content: 'Segon comentari a Rossich') + +## +# Tags + +['Per llegir', 'Moderna', 'Clàssiques', 'TFG'].each { |t| Tag.find_or_create_by!(name: t) } + +## +# Tag references + +Thing.find_by(target: 'Rossich2006').tag_references.find_or_create_by!(tag: Tag.find_by(name: 'Moderna')) +Thing.find_by(target: 'Rossich2006').tag_references.find_or_create_by!(tag: Tag.find_by(name: 'TFG')) +Thing.find_by(target: 'OvidiMetamorfosisParramon').tag_references.find_or_create_by!(tag: Tag.find_by(name: 'Clàssiques')) +Thing.find_by(target: 'OvidiMetamorfosisParramon').tag_references.find_or_create_by!(tag: Tag.find_by(name: 'TFG')) +Comment.find(1).tag_references.find_or_create_by!(tag: Tag.find_by(name: 'TFG')) + +## +# Searches + +Search.find_or_create_by!(name: 'tfg', body: 'tag:"TFG"', user: u) -- cgit v1.2.3