diff --git a/Gemfile b/Gemfile index 4ff92ef..5202088 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,8 @@ gem "pg", "~> 1.1" # Use the Puma web server [https://github.com/puma/puma] gem "puma", ">= 5.0" +gem 'rubocop', '~> 1.62', require: false + # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] gem "importmap-rails" @@ -70,3 +72,5 @@ group :test do gem "capybara" gem "selenium-webdriver" end + +gem "image_processing", ">= 1.2" diff --git a/Gemfile.lock b/Gemfile.lock index 43f6517..91e11b2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) base64 (0.2.0) bcrypt (3.1.20) bigdecimal (3.1.6) @@ -109,10 +110,14 @@ GEM drb (2.2.1) error_highlight (0.6.0) erubi (1.12.0) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) @@ -124,6 +129,8 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + json (2.7.1) + language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -134,6 +141,7 @@ GEM net-smtp marcel (1.0.4) matrix (0.4.2) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.22.2) msgpack (1.7.2) @@ -160,6 +168,10 @@ GEM racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) + parallel (1.24.0) + parser (3.3.0.5) + ast (~> 2.4.1) + racc orm_adapter (0.5.0) pg (1.5.4) psych (5.1.2) @@ -205,6 +217,7 @@ GEM rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) + rainbow (3.1.1) rake (13.1.0) rdoc (6.6.2) psych (>= 4.0.0) @@ -215,6 +228,22 @@ GEM actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) + rubocop (1.62.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) + ruby-progressbar (1.13.0) + ruby-vips (2.2.1) + ffi (~> 1.12) rubyzip (2.3.2) selenium-webdriver (4.18.1) base64 (~> 0.2) @@ -239,6 +268,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.1) @@ -269,11 +299,13 @@ DEPENDENCIES debug devise error_highlight (>= 0.4.0) + image_processing (>= 1.2) importmap-rails jbuilder pg (~> 1.1) puma (>= 5.0) rails (~> 7.1.3) + rubocop (~> 1.62) selenium-webdriver sprockets-rails stimulus-rails @@ -282,7 +314,7 @@ DEPENDENCIES web-console RUBY VERSION - ruby 3.1.3p185 + ruby 3.1.2p20 BUNDLED WITH 2.5.5 diff --git a/app/models/comment.rb b/app/models/comment.rb index bc1dd7e..9089415 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -2,4 +2,5 @@ class Comment < ApplicationRecord belongs_to :user belongs_to :post belongs_to :parent_comment + has_one_attached :image_comment end diff --git a/app/models/message.rb b/app/models/message.rb index 248b2cb..86fdf10 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,4 +1,5 @@ class Message < ApplicationRecord belongs_to :user belongs_to :message_parent + has_one_attached :image_message end diff --git a/app/models/post.rb b/app/models/post.rb index 95d45da..52c9e2c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,3 +1,4 @@ class Post < ApplicationRecord belongs_to :user + has_one_attached :post_image end diff --git a/app/models/user.rb b/app/models/user.rb index 4756799..fad45af 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord + has_one_attached :image_profile # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, diff --git a/config/environments/development.rb b/config/environments/development.rb index 2e7fb48..5d49c74 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -64,6 +64,8 @@ # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true + # Store files locally. + config.active_storage.service = :local # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/config/environments/production.rb b/config/environments/production.rb index c72da38..30180c9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -23,6 +23,10 @@ # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. # config.public_file_server.enabled = false + # Store files on Amazon S3. + config.active_storage.service = :amazon + + # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass diff --git a/config/environments/test.rb b/config/environments/test.rb index adbb4a6..77cf6da 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -56,6 +56,9 @@ # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/config/storage.yml b/config/storage.yml index 4942ab6..aa24eb6 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -1,10 +1,17 @@ +local: + service: Disk + root: <%= Rails.root.join("storage") %> + test: service: Disk root: <%= Rails.root.join("tmp/storage") %> -local: - service: Disk - root: <%= Rails.root.join("storage") %> +amazon: + service: S3 + access_key_id: "" + secret_access_key: "" + bucket: "" + region: "" # e.g. 'us-east-1' # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) # amazon: diff --git a/db/migrate/20240305235341_create_active_storage_tables.active_storage.rb b/db/migrate/20240305235341_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..e4706aa --- /dev/null +++ b/db/migrate/20240305235341_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/schema.rb b/db/schema.rb index c99482b..15e88d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,10 +10,39 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_03_06_013400) do +ActiveRecord::Schema[7.1].define(version: 2024_03_05_235341) do + # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + 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.text "body" t.bigint "user_id", null: false @@ -27,8 +56,8 @@ end create_table "followers", force: :cascade do |t| - t.bigint "user_id", null: false - t.bigint "follower_user_id", null: false + t.bigint "user_id" + t.bigint "follower_user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["follower_user_id"], name: "index_followers_on_follower_user_id" @@ -98,6 +127,8 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", 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", "comments", column: "parent_comment_id" add_foreign_key "comments", "posts" add_foreign_key "comments", "users"