add unique constraint in model and database

pull/14417/head
Gonzalo Riestra 6 years ago
parent 598f3276cd
commit 0be4bde5cc

@ -13,6 +13,7 @@ module Carto
belongs_to :user, inverse_of: :user_multifactor_auths, foreign_key: :user_id
validates :type, inclusion: { in: VALID_TYPES }
validates_uniqueness_of :type, scope: :user_id
before_create :create_shared_secret

@ -0,0 +1,16 @@
require 'carto/db/migration_helper'
include Carto::Db::MigrationHelper
migration(
Proc.new do
alter_table :user_multifactor_auths do
add_unique_constraint [:user_id, :type]
end
end,
Proc.new do
alter_table :user_multifactor_auths do
drop_constraint :user_multifactor_auths_user_id_type_key
end
end
)
Loading…
Cancel
Save