Integrate auction

Closes #874
This commit is contained in:
Artur Beljajev 2018-11-29 15:08:22 +02:00
parent 640faaadb9
commit 42e8f86dae
51 changed files with 1619 additions and 53 deletions

View file

@ -0,0 +1,8 @@
class CreateReleasedDomains < ActiveRecord::Migration
def change
create_table :released_domains do |t|
t.string :name, null: false
t.boolean :at_auction, default: false, null: false
end
end
end

View file

@ -0,0 +1,27 @@
class CreateAuctions < ActiveRecord::Migration
def up
execute <<-SQL
CREATE TYPE auction_status AS ENUM (
'open',
'closed_without_winner',
'closed_with_winner',
'payment_received'
);
SQL
create_table :auctions do |t|
t.string :domain, null: false
t.column :status, :auction_status, null: false
t.uuid :uuid, default: 'gen_random_uuid()', null: false
t.datetime :created_at, null: false
end
end
def down
execute <<-SQL
DROP type auction_status;
SQL
drop_table :auctions
end
end

View file

@ -0,0 +1,5 @@
class ChangeAuctionsUuidDefault < ActiveRecord::Migration
def change
change_column_default :auctions, :uuid, nil
end
end

View file

@ -0,0 +1,5 @@
class ChangeAuctionsUuidToNotNull < ActiveRecord::Migration
def change
change_column_null :auctions, :uuid, false
end
end

View file

@ -0,0 +1,5 @@
class RenameReleasedDomainsToDomainNames < ActiveRecord::Migration
def change
rename_table :released_domains, :domain_names
end
end

View file

@ -0,0 +1,5 @@
class RenameDomainNamesToAuctionableDomains < ActiveRecord::Migration
def change
rename_table :domain_names, :auctionable_domains
end
end

View file

@ -0,0 +1,5 @@
class RemoveAuctionableDomainsAtAuction < ActiveRecord::Migration
def change
remove_column :auctionable_domains, :at_auction
end
end

View file

@ -0,0 +1,5 @@
class RemoveAuctionableDomains < ActiveRecord::Migration
def change
drop_table :auctionable_domains
end
end

View file

@ -0,0 +1,5 @@
class RemoveAuctionsNotNullConstraints < ActiveRecord::Migration
def change
change_column_null :auctions, :uuid, true
end
end

View file

@ -0,0 +1,5 @@
class AddAuctionsRegistrationCode < ActiveRecord::Migration
def change
add_column :auctions, :registration_code, :string
end
end

View file

@ -0,0 +1,9 @@
class ChangeAuctionsStatus < ActiveRecord::Migration
disable_ddl_transaction!
def change
execute <<-SQL
ALTER TYPE auction_status ADD VALUE 'domain_registered' AFTER 'payment_received';
SQL
end
end

View file

@ -0,0 +1,9 @@
class AddPaymentNotReceivedToAuctionStatus < ActiveRecord::Migration
disable_ddl_transaction!
def change
execute <<-SQL
ALTER TYPE auction_status ADD VALUE 'payment_not_received' AFTER 'payment_received';
SQL
end
end

View file

@ -0,0 +1,9 @@
class ChangeAuctionsStatusToString < ActiveRecord::Migration
def change
change_column :auctions, :status, :string
execute <<-SQL
DROP type auction_status;
SQL
end
end

View file

@ -0,0 +1,13 @@
class AddAuctionsRegistrationCodeUniqConstraint < ActiveRecord::Migration
def up
execute <<-SQL
ALTER TABLE auctions ADD CONSTRAINT unique_registration_code UNIQUE (registration_code)
SQL
end
def down
execute <<-SQL
ALTER TABLE auctions DROP CONSTRAINT unique_registration_code
SQL
end
end

View file

@ -0,0 +1,5 @@
class ChangeAuctionsUuid < ActiveRecord::Migration
def change
change_column :auctions, :uuid, :uuid, null: false, default: 'gen_random_uuid()'
end
end

View file

@ -0,0 +1,13 @@
class AddAuctionsUuidUniqConstraint < ActiveRecord::Migration
def up
execute <<-SQL
ALTER TABLE auctions ADD CONSTRAINT uniq_uuid UNIQUE (uuid)
SQL
end
def down
execute <<-SQL
ALTER TABLE auctions DROP CONSTRAINT uniq_uuid
SQL
end
end