Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added migration for constraint name column of whois table #2592

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
.rubocop.yml
/lib/tasks/mock.rake

/node_modules
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ COPY Gemfile Gemfile.lock ./
# ADD vendor/gems/omniauth-tara ./vendor/gems/omniauth-tara
RUN gem install bundler && bundle install --jobs 20 --retry 5

RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN apt-get update && apt-get install -y postgresql-client-13

EXPOSE 3000
10 changes: 6 additions & 4 deletions app/controllers/api/v1/auctions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def serializable_hash_for_update_action(auction)
end

def update_whois_from_auction(auction)
whois_record = Whois::Record.find_or_create_by!(name: auction.domain) do |record|
record.json = {}
end
Whois::Record.transaction do
whois_record = Whois::Record.find_or_create_by!(name: auction.domain) do |record|
record.json = {}
end

whois_record.update_from_auction(auction)
whois_record.update_from_auction(auction)
end
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions app/interactions/whois/update_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class UpdateRecord < ActiveInteraction::Base
end

def execute
data = record['klass'].constantize.find_by(id: record['id'])
send "update_#{record['type']}", data
Whois::Record.transaction do
data = record['klass'].constantize.find_by(id: record['id'])
send "update_#{record['type']}", data
end
end

def update_domain(domain)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameNotNullConstraintInWhoisRecord < ActiveRecord::Migration[6.1]
def change
add_check_constraint :whois_records, "name IS NOT NULL", name: "whois_records_name_null", validate: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ValidateNameNotNullInWhoisRecord < ActiveRecord::Migration[6.1]
def up
validate_check_constraint :whois_records, name: "whois_records_name_null"
change_column_null :whois_records, :name, false
end

def down
change_column_null :whois_records, :name, true
remove_check_constraint :whois_records, name: "whois_records_name_null"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddUniqueIndexToNameInWhoisRecord < ActiveRecord::Migration[6.1]
disable_ddl_transaction!

def change
add_index :whois_records, :name, unique: true, algorithm: :concurrently
end
end
24 changes: 14 additions & 10 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
-- Name: btree_gin; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -2836,11 +2829,12 @@ ALTER SEQUENCE public.white_ips_id_seq OWNED BY public.white_ips.id;
CREATE TABLE public.whois_records (
id integer NOT NULL,
domain_id integer,
name character varying,
name character varying NOT NULL,
json json,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
registrar_id integer
registrar_id integer,
CONSTRAINT whois_records_name_null CHECK ((name IS NOT NULL))
);


Expand Down Expand Up @@ -4719,6 +4713,13 @@ CREATE INDEX index_versions_on_item_type_and_item_id ON public.versions USING bt
CREATE INDEX index_whois_records_on_domain_id ON public.whois_records USING btree (domain_id);


--
-- Name: index_whois_records_on_name; Type: INDEX; Schema: public; Owner: -
--

CREATE UNIQUE INDEX index_whois_records_on_name ON public.whois_records USING btree (name);


--
-- Name: index_whois_records_on_registrar_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -5468,6 +5469,9 @@ INSERT INTO "schema_migrations" (version) VALUES
('20221207102831'),
('20221214073933'),
('20221214074252'),
('20230531111154');
('20230531111154'),
('20230612094319'),
('20230612094326'),
('20230612094335');


1 change: 1 addition & 0 deletions test/models/whois_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_generates_json_with_registrant
disclosed_attributes: %w[name])

domain = domains(:shop)
domain.reload
domain.update!(registrant: contact.becomes(Registrant))

whois_record = whois_records(:shop)
Expand Down