FIX: Change default for IncomingEmail#created_via to 0 (unknown) and make NOT NULL (#11782)
Follow up to https://review.discourse.org/t/dev-add-created-via-column-to-incomingemail-pr-11751/18366/6
This commit is contained in:
parent
9d287f5ff9
commit
9ee8a01c3a
|
@ -6,6 +6,8 @@ class IncomingEmail < ActiveRecord::Base
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to :group, foreign_key: :imap_group_id, class_name: 'Group'
|
belongs_to :group, foreign_key: :imap_group_id, class_name: 'Group'
|
||||||
|
|
||||||
|
validates :created_via, presence: true
|
||||||
|
|
||||||
scope :errored, -> { where("NOT is_bounce AND error IS NOT NULL") }
|
scope :errored, -> { where("NOT is_bounce AND error IS NOT NULL") }
|
||||||
|
|
||||||
scope :addressed_to, -> (email) do
|
scope :addressed_to, -> (email) do
|
||||||
|
@ -33,6 +35,7 @@ class IncomingEmail < ActiveRecord::Base
|
||||||
|
|
||||||
def self.created_via_types
|
def self.created_via_types
|
||||||
@types ||= Enum.new(
|
@types ||= Enum.new(
|
||||||
|
unknown: 0,
|
||||||
handle_mail: 1,
|
handle_mail: 1,
|
||||||
pop3_poll: 2,
|
pop3_poll: 2,
|
||||||
imap: 3,
|
imap: 3,
|
||||||
|
@ -106,7 +109,7 @@ end
|
||||||
# imap_uid :integer
|
# imap_uid :integer
|
||||||
# imap_sync :boolean
|
# imap_sync :boolean
|
||||||
# imap_group_id :bigint
|
# imap_group_id :bigint
|
||||||
# created_via :integer
|
# created_via :integer default(0), not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ChangeIncomingEmailCreatedAtNull < ActiveRecord::Migration[6.0]
|
||||||
|
def up
|
||||||
|
# 0 signifies unknown
|
||||||
|
DB.exec("UPDATE incoming_emails SET created_via = 0 WHERE created_via IS NULL")
|
||||||
|
change_column_default :incoming_emails, :created_via, 0
|
||||||
|
change_column_null :incoming_emails, :created_via, false
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
change_column_null :incoming_emails, :created_via, true
|
||||||
|
end
|
||||||
|
end
|
|
@ -153,7 +153,7 @@ module Email
|
||||||
imap_uid: @opts[:imap_uid],
|
imap_uid: @opts[:imap_uid],
|
||||||
imap_group_id: @opts[:imap_group_id],
|
imap_group_id: @opts[:imap_group_id],
|
||||||
imap_sync: false,
|
imap_sync: false,
|
||||||
created_via: @opts[:source].present? ? IncomingEmail.created_via_types[@opts[:source]] : nil
|
created_via: IncomingEmail.created_via_types[@opts[:source] || :unknown]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ Fabricator(:incoming_email) do
|
||||||
from_address "foo@example.com"
|
from_address "foo@example.com"
|
||||||
to_addresses "someone@else.com"
|
to_addresses "someone@else.com"
|
||||||
imap_sync false
|
imap_sync false
|
||||||
|
created_via 0
|
||||||
|
|
||||||
raw <<~RAW
|
raw <<~RAW
|
||||||
Return-Path: <foo@example.com>
|
Return-Path: <foo@example.com>
|
||||||
|
|
Loading…
Reference in New Issue