Move emails & domains to citext, CC fixes

This commit is contained in:
Alex Sherman 2020-06-10 14:14:03 +05:00
parent 438a2e05ab
commit f8eea08357
5 changed files with 34 additions and 12 deletions

View file

@ -2,10 +2,7 @@ class VerifyEmailsJob < Que::Job
def run(verification_id) def run(verification_id)
email_address_verification = run_condition(EmailAddressVerification.find(verification_id)) email_address_verification = run_condition(EmailAddressVerification.find(verification_id))
if email_address_verification.recently_verified? return if email_address_verification.recently_verified?
destroy
return
end
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
email_address_verification.verify email_address_verification.verify

View file

@ -3,15 +3,15 @@ module Concerns
extend ActiveSupport::Concern extend ActiveSupport::Concern
def email_verification def email_verification
EmailAddressVerification.find_or_create_by(email: email, EmailAddressVerification.find_or_create_by(email: email.downcase,
domain: domain(email)) domain: domain(email.downcase))
end end
def billing_email_verification def billing_email_verification
return unless attribute_names.include?('billing_email') return unless attribute_names.include?('billing_email')
EmailAddressVerification.find_or_create_by(email: billing_email, EmailAddressVerification.find_or_create_by(email: billing_email.downcase,
domain: domain(email)) domain: domain(email.downcase))
end end
def domain(email) def domain(email)

View file

@ -62,6 +62,10 @@ if @cron_group == 'registry'
rake 'domain:discard' rake 'domain:discard'
end end
every 10.minutes do
rake 'verify_email:all_domains'
end
# Should be at least once every 4 days, since according to LHV specs: # Should be at least once every 4 days, since according to LHV specs:
# "Unread messages older than 5 days are automatically scheduled for deletion" # "Unread messages older than 5 days are automatically scheduled for deletion"
# https://partners.lhv.ee/en/connect/#messaging # https://partners.lhv.ee/en/connect/#messaging

View file

@ -0,0 +1,13 @@
class ChangeEmailVerificationFieldsToCitext < ActiveRecord::Migration[6.0]
def up
enable_extension 'citext'
change_column :email_address_verifications, :email, :citext
change_column :email_address_verifications, :domain, :citext
end
def down
change_column :email_address_verifications, :email, :string
change_column :email_address_verifications, :domain, :string
disable_extension 'citext'
end
end

View file

@ -33,10 +33,17 @@ CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
-- --
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner: - -- Name: citext; Type: EXTENSION; Schema: -; Owner: -
-- --
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST'; CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;
--
-- Name: EXTENSION citext; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION citext IS 'data type for case-insensitive character strings';
-- --
@ -822,10 +829,10 @@ ALTER SEQUENCE public.domains_id_seq OWNED BY public.domains.id;
CREATE TABLE public.email_address_verifications ( CREATE TABLE public.email_address_verifications (
id bigint NOT NULL, id bigint NOT NULL,
email character varying NOT NULL, email public.citext NOT NULL,
verified_at timestamp without time zone, verified_at timestamp without time zone,
success boolean DEFAULT false NOT NULL, success boolean DEFAULT false NOT NULL,
domain character varying NOT NULL domain public.citext NOT NULL
); );
@ -4700,5 +4707,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200518104105'), ('20200518104105'),
('20200529115011'), ('20200529115011'),
('20200605100827'), ('20200605100827'),
('20200610090110'),
('20200630081231'); ('20200630081231');