ALTER TABLE "acl"
    ADD CONSTRAINT "acl_acl_high_person_acl_role" UNIQUE ("acl_high", "person", "acl_role");

ALTER TABLE "acl_role"
    ADD CONSTRAINT "acl_role_name" UNIQUE ("name");

ALTER TABLE "acl_role_person"
    ADD CONSTRAINT "acl_role_person_acl_role_person" UNIQUE ("acl_role", "person");

ALTER TABLE "billinterval"
    ADD CONSTRAINT "billinterval_name" UNIQUE ("name");

ALTER TABLE "contract"
    ADD CONSTRAINT "contract_evid_version" UNIQUE ("evid", "version");

ALTER TABLE "contract_invoice_grouping"
    ADD CONSTRAINT "contract_invoice_grouping_name" UNIQUE ("name"),
    ADD CONSTRAINT "contract_invoice_grouping_sysname" UNIQUE ("sysname");

ALTER TABLE "contract_item_binding"
    ADD CONSTRAINT "contract_item_binding_name" UNIQUE ("name");

ALTER TABLE "contract_item_status"
    ADD CONSTRAINT "contract_item_status_name" UNIQUE ("name");

ALTER TABLE "contract_party"
    ADD CONSTRAINT "contract_party_name" UNIQUE ("name");

ALTER TABLE "contract_status"
    ADD CONSTRAINT "contract_status_name" UNIQUE ("name");

ALTER TABLE "contract_type"
    ADD CONSTRAINT "contract_type_type_version" UNIQUE ("type", "version");

CREATE INDEX "contract_type_person_person" ON "contract_type_person" ("person");

-- SELECT * FROM "contract_type_person" WHERE "person" = '4' AND "contract_type" = '6'
-- ALTER TABLE "contract_type_person"
--    ADD CONSTRAINT "contract_type_person_contract_type_person" UNIQUE ("contract_type", "person");

ALTER TABLE "entitled_person"
    ADD CONSTRAINT "entitled_person_supervisor_subordinate_type_contract" UNIQUE ("supervisor", "subordinate", "type", "contract");

ALTER TABLE "entitled_person_type"
    ADD CONSTRAINT "entitled_person_type_name" UNIQUE ("name");

ALTER TABLE "hw_barcode"
    ADD CONSTRAINT "hw_barcode_hw_barcode" UNIQUE ("hw", "barcode");

ALTER TABLE "hw_brand"
    ADD CONSTRAINT "hw_brand_name" UNIQUE ("name");

ALTER TABLE "hw_status"
    ADD CONSTRAINT "hw_status_name" UNIQUE ("name");

ALTER TABLE "hw_stock"
    ADD CONSTRAINT "hw_stock_name" UNIQUE ("name");

ALTER TABLE "message_layout"
    ADD CONSTRAINT "message_layout_name" UNIQUE ("name"),
    ADD CONSTRAINT "message_layout_sysname" UNIQUE ("sysname");

ALTER TABLE "message_medium"
    ADD CONSTRAINT "message_medium_name" UNIQUE ("name");

ALTER TABLE "person_contact"
    ADD CONSTRAINT "person_contact_person_type_uri" UNIQUE ("person", "type", "uri");

ALTER TABLE "message_medium_variant"
    ADD CONSTRAINT "message_medium_variant_name" UNIQUE ("name");

ALTER TABLE "message_status"
    ADD CONSTRAINT "message_status_name" UNIQUE ("name");

ALTER TABLE "message_template"
    ADD CONSTRAINT "message_template_name" UNIQUE ("name"),
    ADD CONSTRAINT "message_template_sysname" UNIQUE ("sysname");

ALTER TABLE "message_template_variant"
    ADD CONSTRAINT "message_template_variant_template_layout_medium_variant_sender_pid" UNIQUE ("template", "layout", "medium_variant", "sender_pid");

ALTER TABLE "message_type"
    ADD CONSTRAINT "message_type_name" UNIQUE ("name");

-- trochu divoké, ale malo by brániť odosielaniu jednej správy viackrát
ALTER TABLE "message_variant"
    ADD CONSTRAINT "message_variant_message_medium_medium_variant_layout_template_variant_sender_uri_recipient_uri" UNIQUE ("message", "medium", "medium_variant", "layout", "template_variant", "sender_uri", "recipient_uri");

ALTER TABLE "nationality"
    ADD CONSTRAINT "nationality_name" UNIQUE ("name");

ALTER TABLE "person_contact"
    ADD CONSTRAINT "person_contact_id_comment_uri" UNIQUE ("id", "comment", "uri");

ALTER TABLE "person_role"
    ADD CONSTRAINT "person_role_name" UNIQUE ("name");

CREATE INDEX "prepaid_remind_log_evid" ON "prepaid_remind_log" ("evid");

COMMENT ON COLUMN "property"."sk_obec" IS 'kod obce z sk_obec';

ALTER TABLE "property_part"
    ALTER "property" TYPE integer;

ALTER TABLE "property_person_role"
    ADD CONSTRAINT "property_person_role_name" UNIQUE ("name");

ALTER TABLE "property_type"
    ADD CONSTRAINT "property_type_name" UNIQUE ("name");

ALTER TABLE "report_group"
    ADD CONSTRAINT "report_group_name" UNIQUE ("name");

ALTER TABLE "person"
    ADD CONSTRAINT "person_pid_unique" UNIQUE ("pid");

ALTER TABLE "tarifitem_currency"
    ADD CONSTRAINT "tarifitem_currency_name" UNIQUE ("name"),
    ADD CONSTRAINT "tarifitem_currency_code" UNIQUE ("code");

ALTER TABLE "tarifitem_vat_type"
    ADD CONSTRAINT "tarifitem_vat_type_name" UNIQUE ("name");

ALTER TABLE "tarifitemgroup"
    ADD CONSTRAINT "tarifitemgroup_name" UNIQUE ("name");

ALTER TABLE "tarifitemtype"
    ADD CONSTRAINT "tarifitemtype_name" UNIQUE ("name");

ALTER TABLE "tarifitemunit"
    ADD CONSTRAINT "tarifitemunit_name" UNIQUE ("name"),
    ADD CONSTRAINT "tarifitemunit_shortname" UNIQUE ("shortname"),
    ADD CONSTRAINT "tarifitemunit_advname" UNIQUE ("advname"),
    ADD CONSTRAINT "tarifitemunit_flexiname" UNIQUE ("flexiname");

ALTER TABLE "task_calc_status"
    ADD CONSTRAINT "task_calc_status_name" UNIQUE ("name");

ALTER TABLE "task_calc_type"
    ADD CONSTRAINT "task_calc_type_name" UNIQUE ("name");

ALTER TABLE "task_event_type"
    ADD CONSTRAINT "task_event_type_name" UNIQUE ("name");

ALTER TABLE "task_person_cancel_reason"
    ADD CONSTRAINT "task_person_cancel_reason_name" UNIQUE ("name");

ALTER TABLE "task_priority" ADD CONSTRAINT "task_priority_name" UNIQUE ("name");

ALTER TABLE "task_shift_type"
    ADD CONSTRAINT "task_shift_type_name" UNIQUE ("name");

ALTER TABLE "task_status"
    ADD CONSTRAINT "task_status_name" UNIQUE ("name");

ALTER TABLE "task_tag"
    ADD CONSTRAINT "task_tag_name" UNIQUE ("name");

ALTER TABLE "task_type"
    ADD CONSTRAINT "task_type_name" UNIQUE ("name");

ALTER TABLE "task_type"
    ALTER COLUMN "sample_calc" TYPE json
    USING "sample_calc"::JSON;