diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-15 00:13:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-15 00:13:45 +0300 |
commit | 34ee0b51d6b76bf987ce5e1cbe6a4f6cccc73910 (patch) | |
tree | 044a25178dc11a49b5ddef6c5efb281c99b79c41 /app/models/ml | |
parent | 3da283df313b950685c1513b6b69a68de9c4ab11 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ml')
-rw-r--r-- | app/models/ml/model.rb | 1 | ||||
-rw-r--r-- | app/models/ml/model_version.rb | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/app/models/ml/model.rb b/app/models/ml/model.rb index b23aa724fad..684b8e1983b 100644 --- a/app/models/ml/model.rb +++ b/app/models/ml/model.rb @@ -13,6 +13,7 @@ module Ml has_one :default_experiment, class_name: 'Ml::Experiment' belongs_to :project + has_many :versions, class_name: 'Ml::ModelVersion' def valid_default_experiment? return unless default_experiment diff --git a/app/models/ml/model_version.rb b/app/models/ml/model_version.rb new file mode 100644 index 00000000000..540fe6018a1 --- /dev/null +++ b/app/models/ml/model_version.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Ml + class ModelVersion < ApplicationRecord + validates :project, :model, presence: true + + validates :version, + format: Gitlab::Regex.ml_model_version_regex, + uniqueness: { scope: [:project, :model_id] }, + presence: true, + length: { maximum: 255 } + + validate :valid_model?, :valid_package? + + belongs_to :model, class_name: 'Ml::Model' + belongs_to :project + belongs_to :package, class_name: 'Packages::Package', optional: true + + delegate :name, to: :model + + private + + def valid_model? + return unless model + + errors.add(:model, 'model project must be the same') unless model.project_id == project_id + end + + def valid_package? + return unless package + + errors.add(:package, 'package must be ml_model') unless package.ml_model? + errors.add(:package, 'package name must be the same') unless package.name == name + errors.add(:package, 'package version must be the same') unless package.version == version + errors.add(:package, 'package project must be the same') unless package.project_id == project_id + end + end +end |