From a41d500b9f65ec9f4e848effd38dc1ae117e7594 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 27 Nov 2019 11:50:48 +0100 Subject: [PATCH] Create an ApplicationRecord for models to inherit from This is the default for Rails 5+, and also paves the way for multiple database support. --- .rubocop.yml | 3 --- app/models/acl.rb | 2 +- app/models/application_record.rb | 3 +++ app/models/changeset.rb | 2 +- app/models/changeset_comment.rb | 2 +- app/models/changeset_tag.rb | 2 +- app/models/client_application.rb | 2 +- app/models/diary_comment.rb | 2 +- app/models/diary_entry.rb | 2 +- app/models/diary_entry_subscription.rb | 2 +- app/models/friendship.rb | 2 +- app/models/issue.rb | 2 +- app/models/issue_comment.rb | 2 +- app/models/language.rb | 2 +- app/models/message.rb | 2 +- app/models/node.rb | 2 +- app/models/node_tag.rb | 2 +- app/models/note.rb | 2 +- app/models/note_comment.rb | 2 +- app/models/oauth_nonce.rb | 2 +- app/models/oauth_token.rb | 2 +- app/models/old_node.rb | 2 +- app/models/old_node_tag.rb | 2 +- app/models/old_relation.rb | 2 +- app/models/old_relation_member.rb | 2 +- app/models/old_relation_tag.rb | 2 +- app/models/old_way.rb | 2 +- app/models/old_way_node.rb | 2 +- app/models/old_way_tag.rb | 2 +- app/models/redaction.rb | 2 +- app/models/relation.rb | 2 +- app/models/relation_member.rb | 2 +- app/models/relation_tag.rb | 2 +- app/models/report.rb | 2 +- app/models/trace.rb | 2 +- app/models/tracepoint.rb | 2 +- app/models/tracetag.rb | 2 +- app/models/user.rb | 2 +- app/models/user_block.rb | 2 +- app/models/user_preference.rb | 2 +- app/models/user_role.rb | 2 +- app/models/user_token.rb | 2 +- app/models/way.rb | 2 +- app/models/way_node.rb | 2 +- app/models/way_tag.rb | 2 +- 45 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 app/models/application_record.rb diff --git a/.rubocop.yml b/.rubocop.yml index cbd62a052..18bf69b9b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -38,9 +38,6 @@ Naming/FileName: Naming/UncommunicativeMethodParamName: Enabled: false -Rails/ApplicationRecord: - Enabled: false - Rails/CreateTableWithTimestamps: Enabled: false diff --git a/app/models/acl.rb b/app/models/acl.rb index 895ed61e4..06f754c22 100644 --- a/app/models/acl.rb +++ b/app/models/acl.rb @@ -17,7 +17,7 @@ # index_acls_on_mx (mx) # -class Acl < ActiveRecord::Base +class Acl < ApplicationRecord validates :k, :presence => true def self.match(address, options = {}) diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 47f03c795..990eae407 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -25,7 +25,7 @@ # changesets_user_id_fkey (user_id => users.id) # -class Changeset < ActiveRecord::Base +class Changeset < ApplicationRecord require "xml/libxml" belongs_to :user, :counter_cache => true diff --git a/app/models/changeset_comment.rb b/app/models/changeset_comment.rb index 75b1a055b..ceb7d3559 100644 --- a/app/models/changeset_comment.rb +++ b/app/models/changeset_comment.rb @@ -19,7 +19,7 @@ # changeset_comments_changeset_id_fkey (changeset_id => changesets.id) # -class ChangesetComment < ActiveRecord::Base +class ChangesetComment < ApplicationRecord belongs_to :changeset belongs_to :author, :class_name => "User" diff --git a/app/models/changeset_tag.rb b/app/models/changeset_tag.rb index 751029e03..600ace4a6 100644 --- a/app/models/changeset_tag.rb +++ b/app/models/changeset_tag.rb @@ -15,7 +15,7 @@ # changeset_tags_id_fkey (changeset_id => changesets.id) # -class ChangesetTag < ActiveRecord::Base +class ChangesetTag < ApplicationRecord self.primary_keys = "changeset_id", "k" belongs_to :changeset diff --git a/app/models/client_application.rb b/app/models/client_application.rb index ae95e2908..67ff075f1 100644 --- a/app/models/client_application.rb +++ b/app/models/client_application.rb @@ -30,7 +30,7 @@ # client_applications_user_id_fkey (user_id => users.id) # -class ClientApplication < ActiveRecord::Base +class ClientApplication < ApplicationRecord belongs_to :user has_many :tokens, :class_name => "OauthToken", :dependent => :delete_all has_many :access_tokens diff --git a/app/models/diary_comment.rb b/app/models/diary_comment.rb index 4ae21be88..05f5044c5 100644 --- a/app/models/diary_comment.rb +++ b/app/models/diary_comment.rb @@ -22,7 +22,7 @@ # diary_comments_user_id_fkey (user_id => users.id) # -class DiaryComment < ActiveRecord::Base +class DiaryComment < ApplicationRecord belongs_to :user belongs_to :diary_entry diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index 4affe8b59..4ff1eeb35 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -26,7 +26,7 @@ # diary_entries_user_id_fkey (user_id => users.id) # -class DiaryEntry < ActiveRecord::Base +class DiaryEntry < ApplicationRecord belongs_to :user, :counter_cache => true belongs_to :language, :foreign_key => "language_code" diff --git a/app/models/diary_entry_subscription.rb b/app/models/diary_entry_subscription.rb index 6e9a103ad..ed6de79e4 100644 --- a/app/models/diary_entry_subscription.rb +++ b/app/models/diary_entry_subscription.rb @@ -15,7 +15,7 @@ # diary_entry_subscriptions_user_id_fkey (user_id => users.id) # -class DiaryEntrySubscription < ActiveRecord::Base +class DiaryEntrySubscription < ApplicationRecord self.primary_keys = "user_id", "diary_entry_id" belongs_to :user diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 27b25aee1..476821b47 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -17,7 +17,7 @@ # friends_user_id_fkey (user_id => users.id) # -class Friendship < ActiveRecord::Base +class Friendship < ApplicationRecord self.table_name = "friends" belongs_to :befriender, :class_name => "User", :foreign_key => :user_id diff --git a/app/models/issue.rb b/app/models/issue.rb index f18581b5f..14c5f8231 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -30,7 +30,7 @@ # issues_updated_by_fkey (updated_by => users.id) # -class Issue < ActiveRecord::Base +class Issue < ApplicationRecord belongs_to :reportable, :polymorphic => true belongs_to :reported_user, :class_name => "User", :foreign_key => :reported_user_id belongs_to :user_resolved, :class_name => "User", :foreign_key => :resolved_by diff --git a/app/models/issue_comment.rb b/app/models/issue_comment.rb index 0841295e1..69aa8bde9 100644 --- a/app/models/issue_comment.rb +++ b/app/models/issue_comment.rb @@ -20,7 +20,7 @@ # issue_comments_user_id_fkey (user_id => users.id) # -class IssueComment < ActiveRecord::Base +class IssueComment < ApplicationRecord belongs_to :issue belongs_to :user diff --git a/app/models/language.rb b/app/models/language.rb index bb1aa4bd2..cdf85a52b 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -7,7 +7,7 @@ # native_name :string # -class Language < ActiveRecord::Base +class Language < ApplicationRecord self.primary_key = "code" has_many :diary_entries, :foreign_key => "language" diff --git a/app/models/message.rb b/app/models/message.rb index 4ab129e91..44b1d8745 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -24,7 +24,7 @@ # messages_to_user_id_fkey (to_user_id => users.id) # -class Message < ActiveRecord::Base +class Message < ApplicationRecord belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id diff --git a/app/models/node.rb b/app/models/node.rb index 2e71813ff..4d48112fc 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -21,7 +21,7 @@ # current_nodes_changeset_id_fkey (changeset_id => changesets.id) # -class Node < ActiveRecord::Base +class Node < ApplicationRecord require "xml/libxml" include GeoRecord diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index 86404599b..fa21b1ff6 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -11,7 +11,7 @@ # current_node_tags_id_fkey (node_id => current_nodes.id) # -class NodeTag < ActiveRecord::Base +class NodeTag < ApplicationRecord self.table_name = "current_node_tags" self.primary_keys = "node_id", "k" diff --git a/app/models/note.rb b/app/models/note.rb index fa9d0b1ae..ec57b770b 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -18,7 +18,7 @@ # notes_updated_at_idx (updated_at) # -class Note < ActiveRecord::Base +class Note < ApplicationRecord include GeoRecord has_many :comments, -> { left_joins(:author).where(:visible => true, :users => { :status => [nil, "active", "confirmed"] }).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index 448703ffa..9611cfe3a 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -23,7 +23,7 @@ # note_comments_note_id_fkey (note_id => notes.id) # -class NoteComment < ActiveRecord::Base +class NoteComment < ApplicationRecord belongs_to :note, :foreign_key => :note_id, :touch => true belongs_to :author, :class_name => "User", :foreign_key => :author_id diff --git a/app/models/oauth_nonce.rb b/app/models/oauth_nonce.rb index 9d2773e8f..5f0920a96 100644 --- a/app/models/oauth_nonce.rb +++ b/app/models/oauth_nonce.rb @@ -15,7 +15,7 @@ # Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique. # Thus you can use the same nonce with a different timestamp and viceversa. -class OauthNonce < ActiveRecord::Base +class OauthNonce < ApplicationRecord validates :timestamp, :presence => true validates :nonce, :presence => true, :uniqueness => { :scope => :timestamp } diff --git a/app/models/oauth_token.rb b/app/models/oauth_token.rb index 5eeda48ba..affdcdeb8 100644 --- a/app/models/oauth_token.rb +++ b/app/models/oauth_token.rb @@ -35,7 +35,7 @@ # oauth_tokens_user_id_fkey (user_id => users.id) # -class OauthToken < ActiveRecord::Base +class OauthToken < ApplicationRecord belongs_to :client_application belongs_to :user diff --git a/app/models/old_node.rb b/app/models/old_node.rb index bdf8cb47e..12099498e 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -24,7 +24,7 @@ # nodes_redaction_id_fkey (redaction_id => redactions.id) # -class OldNode < ActiveRecord::Base +class OldNode < ApplicationRecord include GeoRecord include ConsistencyValidations include ObjectMetadata diff --git a/app/models/old_node_tag.rb b/app/models/old_node_tag.rb index a3e1c3aaf..f2cba896c 100644 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@ -12,7 +12,7 @@ # node_tags_id_fkey (node_id => nodes.node_id) # -class OldNodeTag < ActiveRecord::Base +class OldNodeTag < ApplicationRecord self.table_name = "node_tags" self.primary_keys = "node_id", "version", "k" diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 109f7d968..c0025653f 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -20,7 +20,7 @@ # relations_redaction_id_fkey (redaction_id => redactions.id) # -class OldRelation < ActiveRecord::Base +class OldRelation < ApplicationRecord include ConsistencyValidations include ObjectMetadata diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index f8d4a359f..1714f3c85 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -18,7 +18,7 @@ # relation_members_id_fkey (relation_id => relations.relation_id) # -class OldRelationMember < ActiveRecord::Base +class OldRelationMember < ApplicationRecord self.table_name = "relation_members" self.primary_keys = "relation_id", "version", "sequence_id" diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index c674f708b..d6e6e19c2 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -12,7 +12,7 @@ # relation_tags_id_fkey (relation_id => relations.relation_id) # -class OldRelationTag < ActiveRecord::Base +class OldRelationTag < ApplicationRecord self.table_name = "relation_tags" self.primary_keys = "relation_id", "version", "k" diff --git a/app/models/old_way.rb b/app/models/old_way.rb index 31e230c38..b515322e3 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -20,7 +20,7 @@ # ways_redaction_id_fkey (redaction_id => redactions.id) # -class OldWay < ActiveRecord::Base +class OldWay < ApplicationRecord include ConsistencyValidations include ObjectMetadata diff --git a/app/models/old_way_node.rb b/app/models/old_way_node.rb index 836e76e47..d89227936 100644 --- a/app/models/old_way_node.rb +++ b/app/models/old_way_node.rb @@ -16,7 +16,7 @@ # way_nodes_id_fkey (way_id => ways.way_id) # -class OldWayNode < ActiveRecord::Base +class OldWayNode < ApplicationRecord self.table_name = "way_nodes" self.primary_keys = "way_id", "version", "sequence_id" diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index ae4ad605e..90bf704b6 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -12,7 +12,7 @@ # way_tags_id_fkey (way_id => ways.way_id) # -class OldWayTag < ActiveRecord::Base +class OldWayTag < ApplicationRecord self.table_name = "way_tags" self.primary_keys = "way_id", "version", "k" diff --git a/app/models/redaction.rb b/app/models/redaction.rb index d9b2a5579..f4eedde0a 100644 --- a/app/models/redaction.rb +++ b/app/models/redaction.rb @@ -24,7 +24,7 @@ # record's title and description fields, which can be # displayed linked from the redacted records. # -class Redaction < ActiveRecord::Base +class Redaction < ApplicationRecord belongs_to :user has_many :old_nodes diff --git a/app/models/relation.rb b/app/models/relation.rb index a73d63183..3f812d1b1 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -17,7 +17,7 @@ # current_relations_changeset_id_fkey (changeset_id => changesets.id) # -class Relation < ActiveRecord::Base +class Relation < ApplicationRecord require "xml/libxml" include ConsistencyValidations diff --git a/app/models/relation_member.rb b/app/models/relation_member.rb index 7c399c3a8..7f07dda9b 100644 --- a/app/models/relation_member.rb +++ b/app/models/relation_member.rb @@ -17,7 +17,7 @@ # current_relation_members_id_fkey (relation_id => current_relations.id) # -class RelationMember < ActiveRecord::Base +class RelationMember < ApplicationRecord self.table_name = "current_relation_members" self.primary_keys = "relation_id", "sequence_id" diff --git a/app/models/relation_tag.rb b/app/models/relation_tag.rb index b186f505d..ad9a93266 100644 --- a/app/models/relation_tag.rb +++ b/app/models/relation_tag.rb @@ -11,7 +11,7 @@ # current_relation_tags_id_fkey (relation_id => current_relations.id) # -class RelationTag < ActiveRecord::Base +class RelationTag < ApplicationRecord self.table_name = "current_relation_tags" self.primary_keys = "relation_id", "k" diff --git a/app/models/report.rb b/app/models/report.rb index 9bbf221df..9afedb04e 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -21,7 +21,7 @@ # reports_user_id_fkey (user_id => users.id) # -class Report < ActiveRecord::Base +class Report < ApplicationRecord belongs_to :issue, :counter_cache => true belongs_to :user diff --git a/app/models/trace.rb b/app/models/trace.rb index f1cd72acd..d500784af 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -25,7 +25,7 @@ # gpx_files_user_id_fkey (user_id => users.id) # -class Trace < ActiveRecord::Base +class Trace < ApplicationRecord self.table_name = "gpx_files" belongs_to :user, :counter_cache => true diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index 6473c9430..6352824fd 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -20,7 +20,7 @@ # gps_points_gpx_id_fkey (gpx_id => gpx_files.id) # -class Tracepoint < ActiveRecord::Base +class Tracepoint < ApplicationRecord include GeoRecord self.table_name = "gps_points" diff --git a/app/models/tracetag.rb b/app/models/tracetag.rb index 8d2f4fffa..f13f7269f 100644 --- a/app/models/tracetag.rb +++ b/app/models/tracetag.rb @@ -16,7 +16,7 @@ # gpx_file_tags_gpx_id_fkey (gpx_id => gpx_files.id) # -class Tracetag < ActiveRecord::Base +class Tracetag < ApplicationRecord self.table_name = "gpx_file_tags" belongs_to :trace, :foreign_key => "gpx_id" diff --git a/app/models/user.rb b/app/models/user.rb index 36ae0b55c..609982389 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,7 +43,7 @@ # users_home_idx (home_tile) # -class User < ActiveRecord::Base +class User < ApplicationRecord require "xml/libxml" self.ignored_columns = ["nearby"] diff --git a/app/models/user_block.rb b/app/models/user_block.rb index 92cee16cd..60f680ac3 100644 --- a/app/models/user_block.rb +++ b/app/models/user_block.rb @@ -24,7 +24,7 @@ # user_blocks_user_id_fkey (user_id => users.id) # -class UserBlock < ActiveRecord::Base +class UserBlock < ApplicationRecord validate :moderator_permissions validates :reason, :characters => true diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 37bab38b0..d5cad3978 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -11,7 +11,7 @@ # user_preferences_user_id_fkey (user_id => users.id) # -class UserPreference < ActiveRecord::Base +class UserPreference < ApplicationRecord self.primary_keys = "user_id", "k" belongs_to :user diff --git a/app/models/user_role.rb b/app/models/user_role.rb index f3d48cade..a081361a7 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -19,7 +19,7 @@ # user_roles_user_id_fkey (user_id => users.id) # -class UserRole < ActiveRecord::Base +class UserRole < ApplicationRecord belongs_to :user belongs_to :granter, :class_name => "User" diff --git a/app/models/user_token.rb b/app/models/user_token.rb index 844357d8d..8c9bf4aeb 100644 --- a/app/models/user_token.rb +++ b/app/models/user_token.rb @@ -18,7 +18,7 @@ # user_tokens_user_id_fkey (user_id => users.id) # -class UserToken < ActiveRecord::Base +class UserToken < ApplicationRecord belongs_to :user after_initialize :set_defaults diff --git a/app/models/way.rb b/app/models/way.rb index 3284c47f3..d0d1e2a2e 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -17,7 +17,7 @@ # current_ways_changeset_id_fkey (changeset_id => changesets.id) # -class Way < ActiveRecord::Base +class Way < ApplicationRecord require "xml/libxml" include ConsistencyValidations diff --git a/app/models/way_node.rb b/app/models/way_node.rb index 0788a631c..0626fb240 100644 --- a/app/models/way_node.rb +++ b/app/models/way_node.rb @@ -16,7 +16,7 @@ # current_way_nodes_node_id_fkey (node_id => current_nodes.id) # -class WayNode < ActiveRecord::Base +class WayNode < ApplicationRecord self.table_name = "current_way_nodes" self.primary_keys = "way_id", "sequence_id" diff --git a/app/models/way_tag.rb b/app/models/way_tag.rb index 6637c1585..0d32d8c41 100644 --- a/app/models/way_tag.rb +++ b/app/models/way_tag.rb @@ -11,7 +11,7 @@ # current_way_tags_id_fkey (way_id => current_ways.id) # -class WayTag < ActiveRecord::Base +class WayTag < ApplicationRecord self.table_name = "current_way_tags" self.primary_keys = "way_id", "k" -- 2.39.5