require "pact_broker/dataset"

module PactBroker
  module Deployments
    class CurrentlyDeployedVersionId < Sequel::Model
      set_primary_key :id

      plugin :upsert, identifying_columns: [:pacticipant_id, :environment_id, :target_for_index]

      dataset_module(PactBroker::Dataset)
    end
  end
end

# Table: currently_deployed_version_ids
# Columns:
#  id                  | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
#  target_for_index    | text    | NOT NULL
#  pacticipant_id      | integer | NOT NULL
#  environment_id      | integer | NOT NULL
#  version_id          | integer | NOT NULL
#  deployed_version_id | integer | NOT NULL
# Indexes:
#  currently_deployed_version_ids_pkey                             | PRIMARY KEY btree (id)
#  currently_deployed_version_pacticipant_environment_target_index | UNIQUE btree (pacticipant_id, environment_id, target_for_index)
# Foreign key constraints:
#  currently_deployed_version_ids_environment_id_fkey | (environment_id) REFERENCES environments(id) ON DELETE CASCADE
#  currently_deployed_version_ids_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id) ON DELETE CASCADE
#  currently_deployed_version_ids_version_id_fkey     | (version_id) REFERENCES versions(id) ON DELETE CASCADE
