diff --git a/.rubocop.yml b/.rubocop.yml index 1f6d1bd24..d4e88a35b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -29,3 +29,4 @@ AllCops: - public/**/* - vendor/**/* - node_modules/**/* + - lib/tasks/auto_annotate_models.rake diff --git a/Gemfile b/Gemfile index e3acfc15a..16e422c13 100644 --- a/Gemfile +++ b/Gemfile @@ -71,6 +71,7 @@ gem 'sidekiq' gem 'uglifier' group :development do + gem 'annotate' gem 'bullet' gem 'letter_opener' gem 'web-console' diff --git a/Gemfile.lock b/Gemfile.lock index ee0e36ed3..02ad10699 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,9 @@ GEM activerecord (>= 5.0, < 6.1) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) + annotate (3.0.3) + activerecord (>= 3.2, < 7.0) + rake (>= 10.4, < 14.0) ast (2.4.0) attr_extras (6.2.1) aws-eventstream (1.0.3) @@ -431,6 +434,7 @@ PLATFORMS DEPENDENCIES action-cable-testing acts-as-taggable-on + annotate attr_extras bootsnap brakeman diff --git a/app/models/account.rb b/app/models/account.rb index 0dc634213..e9e214c2f 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: accounts +# +# id :integer not null, primary key +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# + class Account < ApplicationRecord include Events::Types diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 405ba6cc5..598c19c43 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,3 +1,21 @@ +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# coordinates_lat :float default(0.0) +# coordinates_long :float default(0.0) +# extension :string +# external_url :string +# fallback_title :string +# file :string +# file_type :integer default("image") +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# message_id :integer not null +# + require 'uri' require 'open-uri' class Attachment < ApplicationRecord diff --git a/app/models/canned_response.rb b/app/models/canned_response.rb index ff5665b73..7c4742f97 100644 --- a/app/models/canned_response.rb +++ b/app/models/canned_response.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: canned_responses +# +# id :integer not null, primary key +# content :text +# short_code :string +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# + class CannedResponse < ApplicationRecord validates_presence_of :content validates_presence_of :short_code diff --git a/app/models/channel/facebook_page.rb b/app/models/channel/facebook_page.rb index ecfd3fb84..caf1f4082 100644 --- a/app/models/channel/facebook_page.rb +++ b/app/models/channel/facebook_page.rb @@ -1,3 +1,22 @@ +# == Schema Information +# +# Table name: channel_facebook_pages +# +# id :integer not null, primary key +# avatar :string +# name :string not null +# page_access_token :string not null +# user_access_token :string not null +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# page_id :string not null +# +# Indexes +# +# index_channel_facebook_pages_on_page_id (page_id) +# + module Channel class FacebookPage < ApplicationRecord self.table_name = 'channel_facebook_pages' diff --git a/app/models/channel/web_widget.rb b/app/models/channel/web_widget.rb index 9c082a3df..60e0d5737 100644 --- a/app/models/channel/web_widget.rb +++ b/app/models/channel/web_widget.rb @@ -1,3 +1,21 @@ +# == Schema Information +# +# Table name: channel_web_widgets +# +# id :integer not null, primary key +# website_name :string +# website_token :string +# website_url :string +# widget_color :string default("#1f93ff") +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer +# +# Indexes +# +# index_channel_web_widgets_on_website_token (website_token) UNIQUE +# + module Channel class WebWidget < ApplicationRecord self.table_name = 'channel_web_widgets' diff --git a/app/models/contact.rb b/app/models/contact.rb index e52645bca..9681ab8c9 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -1,3 +1,23 @@ +# == Schema Information +# +# Table name: contacts +# +# id :integer not null, primary key +# avatar :string +# email :string +# name :string +# phone_number :string +# pubsub_token :string +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# +# Indexes +# +# index_contacts_on_account_id (account_id) +# index_contacts_on_pubsub_token (pubsub_token) UNIQUE +# + class Contact < ApplicationRecord include Pubsubable validates :account_id, presence: true diff --git a/app/models/contact_inbox.rb b/app/models/contact_inbox.rb index 2877ef2d1..42c0584a9 100644 --- a/app/models/contact_inbox.rb +++ b/app/models/contact_inbox.rb @@ -1,3 +1,27 @@ +# == Schema Information +# +# Table name: contact_inboxes +# +# id :bigint not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# contact_id :bigint +# inbox_id :bigint +# source_id :string not null +# +# Indexes +# +# index_contact_inboxes_on_contact_id (contact_id) +# index_contact_inboxes_on_inbox_id (inbox_id) +# index_contact_inboxes_on_inbox_id_and_source_id (inbox_id,source_id) UNIQUE +# index_contact_inboxes_on_source_id (source_id) +# +# Foreign Keys +# +# fk_rails_... (contact_id => contacts.id) +# fk_rails_... (inbox_id => inboxes.id) +# + class ContactInbox < ApplicationRecord validates :inbox_id, presence: true validates :contact_id, presence: true diff --git a/app/models/conversation.rb b/app/models/conversation.rb index eda85ea15..88e4cbe16 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -1,3 +1,27 @@ +# == Schema Information +# +# Table name: conversations +# +# id :integer not null, primary key +# additional_attributes :jsonb +# agent_last_seen_at :datetime +# locked :boolean default(FALSE) +# status :integer default("open"), not null +# user_last_seen_at :datetime +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# assignee_id :integer +# contact_id :bigint +# display_id :integer not null +# inbox_id :integer not null +# +# Indexes +# +# index_conversations_on_account_id (account_id) +# index_conversations_on_account_id_and_display_id (account_id,display_id) UNIQUE +# + class Conversation < ApplicationRecord include Events::Types diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 13ffb2cb4..660e5e429 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -1,5 +1,22 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: inboxes +# +# id :integer not null, primary key +# channel_type :string +# name :string not null +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# channel_id :integer not null +# +# Indexes +# +# index_inboxes_on_account_id (account_id) +# + class Inbox < ApplicationRecord validates :account_id, presence: true diff --git a/app/models/inbox_member.rb b/app/models/inbox_member.rb index aac068c33..4c1e14159 100644 --- a/app/models/inbox_member.rb +++ b/app/models/inbox_member.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: inbox_members +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# inbox_id :integer not null +# user_id :integer not null +# +# Indexes +# +# index_inbox_members_on_inbox_id (inbox_id) +# + class InboxMember < ApplicationRecord validates :inbox_id, presence: true validates :user_id, presence: true diff --git a/app/models/message.rb b/app/models/message.rb index da75f4eb7..35a7269c9 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,3 +1,25 @@ +# == Schema Information +# +# Table name: messages +# +# id :integer not null, primary key +# content :text +# message_type :integer not null +# private :boolean default(FALSE) +# status :integer default("sent") +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# conversation_id :integer not null +# fb_id :string +# inbox_id :integer not null +# user_id :integer +# +# Indexes +# +# index_messages_on_conversation_id (conversation_id) +# + class Message < ApplicationRecord include Events::Types diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 1e15a7335..8a3afebe3 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,3 +1,19 @@ +# == Schema Information +# +# Table name: subscriptions +# +# id :integer not null, primary key +# billing_plan :string default("trial") +# expiry :datetime +# payment_source_added :boolean default(FALSE) +# pricing_version :string +# state :integer default("trial") +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer +# stripe_customer_id :string +# + class Subscription < ApplicationRecord include Events::Types diff --git a/app/models/telegram_bot.rb b/app/models/telegram_bot.rb index e414fc493..2d8706753 100644 --- a/app/models/telegram_bot.rb +++ b/app/models/telegram_bot.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: telegram_bots +# +# id :integer not null, primary key +# auth_key :string +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer +# + class TelegramBot < ApplicationRecord belongs_to :account has_one :inbox, as: :channel, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 2392bd5f1..30fc387de 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,48 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# confirmation_sent_at :datetime +# confirmation_token :string +# confirmed_at :datetime +# current_sign_in_at :datetime +# current_sign_in_ip :string +# email :string +# encrypted_password :string default(""), not null +# image :string +# last_sign_in_at :datetime +# last_sign_in_ip :string +# name :string not null +# nickname :string +# provider :string default("email"), not null +# pubsub_token :string +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# role :integer default("agent") +# sign_in_count :integer default(0), not null +# tokens :json +# uid :string default(""), not null +# unconfirmed_email :string +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# inviter_id :bigint +# +# Indexes +# +# index_users_on_email (email) +# index_users_on_inviter_id (inviter_id) +# index_users_on_pubsub_token (pubsub_token) UNIQUE +# index_users_on_reset_password_token (reset_password_token) UNIQUE +# index_users_on_uid_and_provider (uid,provider) UNIQUE +# +# Foreign Keys +# +# fk_rails_... (inviter_id => users.id) ON DELETE => nullify +# + class User < ApplicationRecord # Include default devise modules. include DeviseTokenAuth::Concerns::User diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 000000000..98c8d344e --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,57 @@ +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +if Rails.env.development? + require 'annotate' + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + 'additional_file_patterns' => [], + 'routes' => 'false', + 'models' => 'true', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'show_foreign_keys' => 'true', + 'show_complete_foreign_keys' => 'false', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'true', + 'exclude_fixtures' => 'true', + 'exclude_factories' => 'true', + 'exclude_serializers' => 'true', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'exclude_sti_subclasses' => 'false', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => 'integer,bigint,boolean', + 'hide_default_column_types' => 'json,jsonb,hstore', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'frozen' => 'false', + 'classified_sort' => 'true', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil, + 'with_comment' => 'true' + ) + end + + Annotate.load_tasks +end