method

all_foreign_keys_valid?

all_foreign_keys_valid?()
public

No documentation available.

# File activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb, line 41
        def all_foreign_keys_valid? # :nodoc:
          sql = <<~SQL
            do $$
              declare r record;
            BEGIN
            FOR r IN (
              SELECT FORMAT(
                'UPDATE pg_constraint SET convalidated=false WHERE conname = ''%I''; ALTER TABLE %I VALIDATE CONSTRAINT %I;',
                constraint_name,
                table_name,
                constraint_name
              ) AS constraint_check
              FROM information_schema.table_constraints WHERE constraint_type = 'FOREIGN KEY'
            )
              LOOP
                EXECUTE (r.constraint_check);
              END LOOP;
            END;
            $$;
          SQL

          begin
            transaction(requires_new: true) do
              execute(sql)
            end

            true
          rescue ActiveRecord::StatementInvalid
            false
          end
        end
      end