SamlProvider has many linked Identities

What does this MR do?

Adds saml_provider_id to the identities table and updates validations

Extracted from https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4076

Why was this MR needed?

Needed for Group SAML where we'll want to associate a login with group's provider

Database Checklist

  • Updated db/schema.rb
  • Added a down method so the migration can be reverted
  • Added the output of the migration(s) to the MR body
  • Added foreign keys to any columns pointing to data in other tables
  • Added indexes for fields that are used in statements such as WHERE, ORDER BY, GROUP BY, and JOINs
== 20180317020334 AddSamlProviderToIdentities: migrating ======================
-- add_column(:identities, :saml_provider_id, :integer)
   -> 0.0418s
== 20180317020334 AddSamlProviderToIdentities: migrated (0.0421s) =============


== 20180502125859 AddSamlProviderIndexAndConstraintToIdentities: migrating ====
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- index_exists?(:identities, :saml_provider_id, {:where=>"saml_provider_id IS NOT NULL", :algorithm=>:concurrently})
   -> 0.0014s
-- add_index(:identities, :saml_provider_id, {:where=>"saml_provider_id IS NOT NULL", :algorithm=>:concurrently})
   -> 0.0045s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0004s
-- foreign_keys(:identities)
   -> 0.0024s
-- execute("ALTER TABLE identities\nADD CONSTRAINT fk_aade90f0fc\nFOREIGN KEY (saml_provider_id)\nREFERENCES saml_providers (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0064s
-- execute("ALTER TABLE identities VALIDATE CONSTRAINT fk_aade90f0fc;")
   -> 0.0022s
== 20180502125859 AddSamlProviderIndexAndConstraintToIdentities: migrated (0.0189s) 

Acceptance criteria

  • API support added
  • Tests added for this feature/bug
  • Review
    • Has been reviewed by Backend
    • Has been reviewed by Database
  • EE specific content should be in the top level /ee folder
  • Squashed related commits together
  • End-to-end tests pass (package-qa manual pipeline job)

What are the relevant issue numbers?

Edited by Andreas Brandl

Merge request reports

Loading