defmodule GitGud.Secrets.OrganizationVariable do
use Ecto.Schema
import Ecto.Changeset
alias GitGud.Organizations.Organization
schema "organization_variables" do
field :name, :string
field :value, :string
belongs_to :organization, Organization
timestamps(type: :utc_datetime)
end
@name_format ~r/\A[A-Za-z_][A-Za-z0-9_]*\z/
def changeset(v, attrs) do
v
|> cast(attrs, [:name, :value])
|> validate_required([:name])
|> validate_format(:name, @name_format, message: "must be a valid env var name")
|> validate_length(:name, max: 100)
|> GitGud.Secrets.ReservedNames.validate_not_reserved()
|> validate_length(:value, max: 65_535)
|> unique_constraint(:name, name: :organization_variables_organization_id_name_index)
end
end
792 B · text
5af55d9