sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Procedures in PSQL are not replaced

Open DawnKosmos opened this issue 1 year ago • 0 comments

Version

1.27.0

What happened?

While replacing a procedure in PSQL migration I noticed that SQLC generates the Procedures Struct using the old procedure parameter types somehow mixed with the new one, although the procedure is dropped in the code and re-created with a different schema.

Relevant log output

No response

Database schema

CREATE OR REPLACE PROCEDURE create_contract(
  p_location_id UUID,
  p_supplier_id UUID,
  p_contract_id UUID,
  p_account_id VARCHAR(31),
  p_country country_codes,
  p_has_medical_access BOOLEAN,
  p_organization_id UUID,
  p_group_id UUID,
  p_valid_from TIMESTAMP,
  p_valid_to TIMESTAMP,
  p_language VARCHAR(2),
  p_type VARCHAR(31),
  p_comment text
)
  LANGUAGE plpgsql
AS
$$
BEGIN
  INSERT INTO public.contracts (location_id,
                                supplier_id,
                                contract_id,
                                account_id,
                                country,
                                has_medical_access,
                                created_at,
                                updated_at,
                                deleted_at,
                                organization_id,
                                group_id,
                                valid_from,
                                valid_to,
                                language,
                                type,
                                comment)
  VALUES (p_location_id,
          p_supplier_id,
          p_contract_id,
          p_account_id,
          p_country,
          p_has_medical_access,
          now(),
          now(),
          null,
          p_organization_id,
          p_group_id,
          p_valid_from,
          p_valid_to,
          p_language,
          p_type,
          p_comment);
END;
$$;

SQL queries

-- name: CreateContract :exec
CALL create_contract(
  sqlc.arg(p_location_id),
  sqlc.arg(p_supplier_id),
  sqlc.arg(p_contract_id),
  sqlc.arg(p_account_id),
  sqlc.arg(p_country),
  sqlc.arg(p_has_medical_access),
  sqlc.arg(p_organization_id),
  sqlc.narg(group_id),
  sqlc.arg(p_valid_from),
  sqlc.arg(p_valid_to),
  sqlc.arg(p_language),
  sqlc.arg(p_type),
    sqlc.arg(p_comment)
);

Configuration

type CreateContractParams struct {
	PLocationID       uuid.UUID         `db:"p_location_id" json:"p_location_id"`
	PSupplierID       uuid.UUID         `db:"p_supplier_id" json:"p_supplier_id"`
	PContractID       uuid.UUID         `db:"p_contract_id" json:"p_contract_id"`
	PAccountID        string            `db:"p_account_id" json:"p_account_id"`
	PCountry          CountryCodes      `db:"p_country" json:"p_country"`
	PHasMedicalAccess bool              `db:"p_has_medical_access" json:"p_has_medical_access"`
	POrganizationID   bool             // TYPE SHOULD BE UUID
	GroupID           uuid.NullableUUID `db:"group_id" json:"group_id"`
	PValidFrom        bool              //TYPE SHOUDL BE pgtype.Timestamp
	PValidTo          pgtype.Timestamp  `db:"p_valid_to" json:"p_valid_to"`
	PLanguage         pgtype.Timestamp  // SHOULD BE TEXT
	PType             string            `db:"p_type" json:"p_type"`
	PComment          string            `db:"p_comment" json:"p_comment"`
}

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

DawnKosmos avatar Sep 06 '24 12:09 DawnKosmos