Skip to content

Commit

Permalink
Merge pull request #6 from BrightCoders-Institute/sprint2-issue-1#Act…
Browse files Browse the repository at this point in the history
…ive-Storage

Implement Active Storage
  • Loading branch information
angel23v authored Mar 7, 2024
2 parents 500ef28 + 2b1d556 commit a8639fd
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -70,3 +72,5 @@ group :test do
gem "capybara"
gem "selenium-webdriver"
end

gem "image_processing", ">= 1.2"
34 changes: 33 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -282,7 +314,7 @@ DEPENDENCIES
web-console

RUBY VERSION
ruby 3.1.3p185
ruby 3.1.2p20

BUNDLED WITH
2.5.5
1 change: 1 addition & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class Comment < ApplicationRecord
belongs_to :user
belongs_to :post
belongs_to :parent_comment
has_one_attached :image_comment
end
1 change: 1 addition & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Message < ApplicationRecord
belongs_to :user
belongs_to :message_parent
has_one_attached :image_message
end
1 change: 1 addition & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Post < ApplicationRecord
belongs_to :user
has_one_attached :post_image
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions config/storage.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
37 changes: 34 additions & 3 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8639fd

Please sign in to comment.