about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryhirano <yhirano@me.com>2017-05-02 09:14:47 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-02 02:14:47 +0200
commit298796cc7b4fdc075be659fc6aea7ab2543a0f9d (patch)
treef70f563b70284f5458c1897bacd3d8d0371a14f2
parenta4859446abea166ae55806169425646c1bd42f85 (diff)
annotate models (#2697)
* add annotate to Gemfile

* rails g annotate:install

* configure annotate_models

* add schema info to models

* fix rubocop to add frozen_string_literal
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock6
-rw-r--r--app/models/account.rb38
-rw-r--r--app/models/block.rb10
-rw-r--r--app/models/domain_block.rb11
-rw-r--r--app/models/favourite.rb10
-rw-r--r--app/models/follow.rb10
-rw-r--r--app/models/follow_request.rb10
-rw-r--r--app/models/import.rb15
-rw-r--r--app/models/media_attachment.rb18
-rw-r--r--app/models/mention.rb10
-rw-r--r--app/models/mute.rb10
-rw-r--r--app/models/notification.rb12
-rw-r--r--app/models/preview_card.rb24
-rw-r--r--app/models/report.rb14
-rw-r--r--app/models/setting.rb12
-rw-r--r--app/models/status.rb23
-rw-r--r--app/models/stream_entry.rb12
-rw-r--r--app/models/subscription.rb14
-rw-r--r--app/models/tag.rb9
-rw-r--r--app/models/user.rb33
-rw-r--r--app/models/web/setting.rb10
-rw-r--r--lib/tasks/auto_annotate_models.rake44
23 files changed, 355 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index fea35daf1..f946440c6 100644
--- a/Gemfile
+++ b/Gemfile
@@ -90,6 +90,7 @@ group :development do
   gem 'letter_opener_web'
   gem 'bullet'
   gem 'active_record_query_trace'
+  gem 'annotate'
 
   gem 'capistrano', '3.8.0'
   gem 'capistrano-rails'
diff --git a/Gemfile.lock b/Gemfile.lock
index 9f9b6728c..acda0d387 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -43,6 +43,9 @@ GEM
       public_suffix (~> 2.0, >= 2.0.2)
     airbrussh (1.2.0)
       sshkit (>= 1.6.1, != 1.7.0)
+    annotate (2.7.1)
+      activerecord (>= 3.2, < 6.0)
+      rake (>= 10.4, < 12.0)
     arel (7.1.4)
     ast (2.3.0)
     attr_encrypted (3.0.3)
@@ -345,7 +348,7 @@ GEM
       thor (>= 0.18.1, < 2.0)
     rainbow (2.2.2)
       rake
-    rake (12.0.0)
+    rake (11.3.0)
     react-rails (1.11.0)
       babel-transpiler (>= 0.7.0)
       connection_pool
@@ -483,6 +486,7 @@ PLATFORMS
 DEPENDENCIES
   active_record_query_trace
   addressable
+  annotate
   autoprefixer-rails
   aws-sdk (>= 2.0)
   best_in_place (~> 3.0.1)
diff --git a/app/models/account.rb b/app/models/account.rb
index c5fc6d7ab..88f25aa4b 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -1,4 +1,42 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: accounts
+#
+#  id                      :integer          not null, primary key
+#  username                :string           default(""), not null
+#  domain                  :string
+#  secret                  :string           default(""), not null
+#  private_key             :text
+#  public_key              :text             default(""), not null
+#  remote_url              :string           default(""), not null
+#  salmon_url              :string           default(""), not null
+#  hub_url                 :string           default(""), not null
+#  created_at              :datetime         not null
+#  updated_at              :datetime         not null
+#  note                    :text             default(""), not null
+#  display_name            :string           default(""), not null
+#  uri                     :string           default(""), not null
+#  url                     :string
+#  avatar_file_name        :string
+#  avatar_content_type     :string
+#  avatar_file_size        :integer
+#  avatar_updated_at       :datetime
+#  header_file_name        :string
+#  header_content_type     :string
+#  header_file_size        :integer
+#  header_updated_at       :datetime
+#  avatar_remote_url       :string
+#  subscription_expires_at :datetime
+#  silenced                :boolean          default(FALSE), not null
+#  suspended               :boolean          default(FALSE), not null
+#  locked                  :boolean          default(FALSE), not null
+#  header_remote_url       :string           default(""), not null
+#  statuses_count          :integer          default(0), not null
+#  followers_count         :integer          default(0), not null
+#  following_count         :integer          default(0), not null
+#  last_webfingered_at     :datetime
+#
 
 class Account < ApplicationRecord
   include Targetable
diff --git a/app/models/block.rb b/app/models/block.rb
index c978b2200..edb0d2d11 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: blocks
+#
+#  id                :integer          not null, primary key
+#  account_id        :integer          not null
+#  target_account_id :integer          not null
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#
 
 class Block < ApplicationRecord
   include Paginable
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index 6c2ba70f7..99dae9c1d 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -1,4 +1,15 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: domain_blocks
+#
+#  id           :integer          not null, primary key
+#  domain       :string           default(""), not null
+#  created_at   :datetime         not null
+#  updated_at   :datetime         not null
+#  severity     :integer          default("silence")
+#  reject_media :boolean
+#
 
 class DomainBlock < ApplicationRecord
   enum severity: [:silence, :suspend]
diff --git a/app/models/favourite.rb b/app/models/favourite.rb
index 32d54476b..53c79ccea 100644
--- a/app/models/favourite.rb
+++ b/app/models/favourite.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: favourites
+#
+#  id         :integer          not null, primary key
+#  account_id :integer          not null
+#  status_id  :integer          not null
+#  created_at :datetime         not null
+#  updated_at :datetime         not null
+#
 
 class Favourite < ApplicationRecord
   include Paginable
diff --git a/app/models/follow.rb b/app/models/follow.rb
index b6b9dca7c..863710f5d 100644
--- a/app/models/follow.rb
+++ b/app/models/follow.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: follows
+#
+#  id                :integer          not null, primary key
+#  account_id        :integer          not null
+#  target_account_id :integer          not null
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#
 
 class Follow < ApplicationRecord
   include Paginable
diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb
index 20e1332dd..458c3a2cd 100644
--- a/app/models/follow_request.rb
+++ b/app/models/follow_request.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: follow_requests
+#
+#  id                :integer          not null, primary key
+#  account_id        :integer          not null
+#  target_account_id :integer          not null
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#
 
 class FollowRequest < ApplicationRecord
   include Paginable
diff --git a/app/models/import.rb b/app/models/import.rb
index 85f6ca4bd..8c6253d49 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -1,4 +1,19 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: imports
+#
+#  id                :integer          not null, primary key
+#  account_id        :integer          not null
+#  type              :integer          not null
+#  approved          :boolean
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#  data_file_name    :string
+#  data_content_type :string
+#  data_file_size    :integer
+#  data_updated_at   :datetime
+#
 
 class Import < ApplicationRecord
   FILE_TYPES = ['text/plain', 'text/csv'].freeze
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 2ebddcb69..1613346ff 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -1,4 +1,22 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: media_attachments
+#
+#  id                :integer          not null, primary key
+#  status_id         :integer
+#  file_file_name    :string
+#  file_content_type :string
+#  file_file_size    :integer
+#  file_updated_at   :datetime
+#  remote_url        :string           default(""), not null
+#  account_id        :integer
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#  shortcode         :string
+#  type              :integer          default("image"), not null
+#  file_meta         :json
+#
 
 class MediaAttachment < ApplicationRecord
   self.inheritance_column = nil
diff --git a/app/models/mention.rb b/app/models/mention.rb
index 03e76fcc4..a8d243259 100644
--- a/app/models/mention.rb
+++ b/app/models/mention.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: mentions
+#
+#  id         :integer          not null, primary key
+#  account_id :integer
+#  status_id  :integer
+#  created_at :datetime         not null
+#  updated_at :datetime         not null
+#
 
 class Mention < ApplicationRecord
   belongs_to :account, inverse_of: :mentions, required: true
diff --git a/app/models/mute.rb b/app/models/mute.rb
index d0de62ed5..00e5661a7 100644
--- a/app/models/mute.rb
+++ b/app/models/mute.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: mutes
+#
+#  id                :integer          not null, primary key
+#  account_id        :integer          not null
+#  target_account_id :integer          not null
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#
 
 class Mute < ApplicationRecord
   include Paginable
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 302d4382d..5b8f46cad 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -1,4 +1,16 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: notifications
+#
+#  id              :integer          not null, primary key
+#  account_id      :integer
+#  activity_id     :integer
+#  activity_type   :string
+#  created_at      :datetime         not null
+#  updated_at      :datetime         not null
+#  from_account_id :integer
+#
 
 class Notification < ApplicationRecord
   include Paginable
diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb
index 238588157..a57f1252c 100644
--- a/app/models/preview_card.rb
+++ b/app/models/preview_card.rb
@@ -1,4 +1,28 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: preview_cards
+#
+#  id                 :integer          not null, primary key
+#  status_id          :integer
+#  url                :string           default(""), not null
+#  title              :string
+#  description        :string
+#  image_file_name    :string
+#  image_content_type :string
+#  image_file_size    :integer
+#  image_updated_at   :datetime
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  type               :integer          default("link"), not null
+#  html               :text             default(""), not null
+#  author_name        :string           default(""), not null
+#  author_url         :string           default(""), not null
+#  provider_name      :string           default(""), not null
+#  provider_url       :string           default(""), not null
+#  width              :integer          default(0), not null
+#  height             :integer          default(0), not null
+#
 
 class PreviewCard < ApplicationRecord
   IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze
diff --git a/app/models/report.rb b/app/models/report.rb
index d813d0d0d..7c317490b 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -1,4 +1,18 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: reports
+#
+#  id                         :integer          not null, primary key
+#  account_id                 :integer          not null
+#  target_account_id          :integer          not null
+#  status_ids                 :integer          default([]), not null, is an Array
+#  comment                    :text             default(""), not null
+#  action_taken               :boolean          default(FALSE), not null
+#  created_at                 :datetime         not null
+#  updated_at                 :datetime         not null
+#  action_taken_by_account_id :integer
+#
 
 class Report < ApplicationRecord
   belongs_to :account
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 31e1ee198..db16f228b 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -1,4 +1,16 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: settings
+#
+#  id         :integer          not null, primary key
+#  var        :string           not null
+#  value      :text
+#  thing_type :string
+#  thing_id   :integer
+#  created_at :datetime
+#  updated_at :datetime
+#
 
 class Setting < RailsSettings::Base
   source Rails.root.join('config/settings.yml')
diff --git a/app/models/status.rb b/app/models/status.rb
index 3243d1ecb..4808b1a64 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -1,4 +1,27 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: statuses
+#
+#  id                     :integer          not null, primary key
+#  uri                    :string
+#  account_id             :integer          not null
+#  text                   :text             default(""), not null
+#  created_at             :datetime         not null
+#  updated_at             :datetime         not null
+#  in_reply_to_id         :integer
+#  reblog_of_id           :integer
+#  url                    :string
+#  sensitive              :boolean          default(FALSE)
+#  visibility             :integer          default("public"), not null
+#  in_reply_to_account_id :integer
+#  application_id         :integer
+#  spoiler_text           :text             default(""), not null
+#  reply                  :boolean          default(FALSE)
+#  favourites_count       :integer          default(0), not null
+#  reblogs_count          :integer          default(0), not null
+#  language               :string           default("en"), not null
+#
 
 class Status < ApplicationRecord
   include Paginable
diff --git a/app/models/stream_entry.rb b/app/models/stream_entry.rb
index 8aff5ae06..c173e6257 100644
--- a/app/models/stream_entry.rb
+++ b/app/models/stream_entry.rb
@@ -1,4 +1,16 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: stream_entries
+#
+#  id            :integer          not null, primary key
+#  account_id    :integer
+#  activity_id   :integer
+#  activity_type :string
+#  created_at    :datetime         not null
+#  updated_at    :datetime         not null
+#  hidden        :boolean          default(FALSE), not null
+#
 
 class StreamEntry < ApplicationRecord
   include Paginable
diff --git a/app/models/subscription.rb b/app/models/subscription.rb
index 63553e9fe..6a039cf07 100644
--- a/app/models/subscription.rb
+++ b/app/models/subscription.rb
@@ -1,4 +1,18 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: subscriptions
+#
+#  id                          :integer          not null, primary key
+#  callback_url                :string           default(""), not null
+#  secret                      :string
+#  expires_at                  :datetime
+#  confirmed                   :boolean          default(FALSE), not null
+#  account_id                  :integer          not null
+#  created_at                  :datetime         not null
+#  updated_at                  :datetime         not null
+#  last_successful_delivery_at :datetime
+#
 
 class Subscription < ApplicationRecord
   MIN_EXPIRATION = 3600 * 24 * 7
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 6209d7dab..4001e6ed5 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -1,4 +1,13 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: tags
+#
+#  id         :integer          not null, primary key
+#  name       :string           default(""), not null
+#  created_at :datetime         not null
+#  updated_at :datetime         not null
+#
 
 class Tag < ApplicationRecord
   has_and_belongs_to_many :statuses
diff --git a/app/models/user.rb b/app/models/user.rb
index 48e7b8088..f6e080d4e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,4 +1,37 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: users
+#
+#  id                        :integer          not null, primary key
+#  email                     :string           default(""), not null
+#  account_id                :integer          not null
+#  created_at                :datetime         not null
+#  updated_at                :datetime         not null
+#  encrypted_password        :string           default(""), not null
+#  reset_password_token      :string
+#  reset_password_sent_at    :datetime
+#  remember_created_at       :datetime
+#  sign_in_count             :integer          default(0), not null
+#  current_sign_in_at        :datetime
+#  last_sign_in_at           :datetime
+#  current_sign_in_ip        :inet
+#  last_sign_in_ip           :inet
+#  admin                     :boolean          default(FALSE)
+#  confirmation_token        :string
+#  confirmed_at              :datetime
+#  confirmation_sent_at      :datetime
+#  unconfirmed_email         :string
+#  locale                    :string
+#  encrypted_otp_secret      :string
+#  encrypted_otp_secret_iv   :string
+#  encrypted_otp_secret_salt :string
+#  consumed_timestep         :integer
+#  otp_required_for_login    :boolean
+#  last_emailed_at           :datetime
+#  otp_backup_codes          :string           is an Array
+#  allowed_languages         :string           default([]), not null, is an Array
+#
 
 class User < ApplicationRecord
   include Settings::Extend
diff --git a/app/models/web/setting.rb b/app/models/web/setting.rb
index 3d601189b..04a049523 100644
--- a/app/models/web/setting.rb
+++ b/app/models/web/setting.rb
@@ -1,4 +1,14 @@
 # frozen_string_literal: true
+# == Schema Information
+#
+# Table name: web_settings
+#
+#  id         :integer          not null, primary key
+#  user_id    :integer
+#  data       :json
+#  created_at :datetime         not null
+#  updated_at :datetime         not null
+#
 
 class Web::Setting < ApplicationRecord
   belongs_to :user
diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake
new file mode 100644
index 000000000..6c6b0df1b
--- /dev/null
+++ b/lib/tasks/auto_annotate_models.rake
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+if Rails.env.development?
+  task :set_annotation_options do
+    Annotate.set_defaults(
+      'routes'                  => 'false',
+      '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'       => 'false',
+      'show_indexes'            => 'false',
+      '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',
+      'ignore_model_sub_dir'    => 'false',
+      'ignore_columns'          => nil,
+      'ignore_routes'           => nil,
+      'ignore_unknown_models'   => 'false',
+      'hide_limit_column_types' => 'integer,boolean',
+      'skip_on_db_migrate'      => 'false',
+      'format_bare'             => 'true',
+      'format_rdoc'             => 'false',
+      'format_markdown'         => 'false',
+      'sort'                    => 'false',
+      'force'                   => 'false',
+      'trace'                   => 'false',
+      'wrapper_open'            => nil,
+      'wrapper_close'           => nil
+    )
+  end
+
+  Annotate.load_tasks
+end