Skip to content

Commit b03d787

Browse files
committed
Merge remote-tracking branch 'origin/408-introduce-primary-runtime-for-project' into 420-flow-type-structure
# Conflicts: # db/structure.sql
2 parents 6014c57 + 6d50eb2 commit b03d787

File tree

12 files changed

+68
-387
lines changed

12 files changed

+68
-387
lines changed

app/graphql/mutations/namespaces/projects/update.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Update < BaseMutation
1313

1414
argument :description, String, required: false, description: 'Description for the updated project.'
1515
argument :name, String, required: false, description: 'Name for the updated project.'
16+
argument :primary_runtime_id, Types::GlobalIdType[::Runtime],
17+
required: false, description: 'The primary runtime for the updated project.'
1618

1719
def resolve(namespace_project_id:, **params)
1820
project = SagittariusSchema.object_from_id(namespace_project_id)
@@ -22,6 +24,8 @@ def resolve(namespace_project_id:, **params)
2224
errors: [create_message_error('Invalid project')] }
2325
end
2426

27+
params[:primary_runtime_id] = params[:primary_runtime_id]&.model_id if params.key?(:primary_runtime_id)
28+
2529
::Namespaces::Projects::UpdateService.new(
2630
current_authentication,
2731
project,

app/graphql/types/namespace_project_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class NamespaceProjectType < Types::BaseObject
1212

1313
field :namespace, Types::NamespaceType, null: false,
1414
description: 'The namespace where this project belongs to'
15+
field :primary_runtime, Types::RuntimeType, null: true, description: 'The primary runtime for the project'
1516

1617
id_field NamespaceProject
1718
timestamps

app/models/namespace_project.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class NamespaceProject < ApplicationRecord
44
belongs_to :namespace, inverse_of: :projects
5+
belongs_to :primary_runtime, class_name: 'Runtime', optional: true
56

67
has_many :runtime_assignments, class_name: 'NamespaceProjectRuntimeAssignment', inverse_of: :namespace_project
78
has_many :runtimes, through: :runtime_assignments, inverse_of: :projects
@@ -22,6 +23,15 @@ class NamespaceProject < ApplicationRecord
2223

2324
before_validation :strip_whitespace
2425

26+
validate :validate_primary_runtime, if: :primary_runtime_changed?
27+
28+
def validate_primary_runtime
29+
return if primary_runtime&.namespace.nil?
30+
return if primary_runtime.namespace == namespace
31+
32+
errors.add(:primary_runtime, :invalid_namespace, message: 'must belong to the same namespace as the project')
33+
end
34+
2535
private
2636

2737
def strip_whitespace

app/services/namespaces/projects/update_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def execute
1818
return ServiceResponse.error(message: 'Missing permission', payload: :missing_permission)
1919
end
2020

21+
params[:primary_runtime_id] = params.delete(:primary_runtime)&.id if params.key?(:primary_runtime)
22+
2123
transactional do |t|
2224
success = namespace_project.update(params)
2325
unless success
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddPrimaryRuntimeToProject < Code0::ZeroTrack::Database::Migration[1.0]
4+
def change
5+
add_reference :namespace_projects, :primary_runtime, foreign_key: { to_table: :runtimes, on_delete: :cascade },
6+
null: true
7+
end
8+
end

db/schema_migrations/20250523223423

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
56e466bfc4e43b718ada800e2de7fbccd5d16817af84306908c0452b0e195c13

0 commit comments

Comments
 (0)