-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create runtime function definition/parameter models
- Loading branch information
Showing
11 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class RuntimeFunctionDefinition < ApplicationRecord | ||
belongs_to :return_type, class_name: 'DataType' | ||
belongs_to :namespace | ||
|
||
has_many :parameters, class_name: 'RuntimeParameterDefinition', inverse_of: :runtime_function_definition | ||
|
||
validates :runtime_name, presence: true, length: { minimum: 3, maximum: 50 }, | ||
uniqueness: { case_sensitive: false, scope: :namespace_id } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class RuntimeParameterDefinition < ApplicationRecord | ||
belongs_to :runtime_function_definition, inverse_of: :parameters | ||
belongs_to :data_type | ||
|
||
validates :name, length: { minimum: 3, maximum: 50 }, presence: true, | ||
uniqueness: { case_sensitive: false, scope: :runtime_function_definition_id } | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20250112173532_create_runtime_function_definitions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateRuntimeFunctionDefinitions < Sagittarius::Database::Migration[1.0] | ||
def change | ||
create_table :runtime_function_definitions do |t| | ||
t.references :return_type, null: true, foreign_key: { to_table: :data_types, on_delete: :restrict } | ||
t.references :namespace, null: false, index: false, foreign_key: { on_delete: :cascade } | ||
t.text :runtime_name, null: false, limit: 50 | ||
|
||
t.index %i[namespace_id runtime_name], unique: true | ||
|
||
t.timestamps_with_timezone | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20250112174055_create_runtime_parameter_definitions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateRuntimeParameterDefinitions < Sagittarius::Database::Migration[1.0] | ||
def change | ||
create_table :runtime_parameter_definitions do |t| | ||
t.references :runtime_function_definition, index: false, null: false, foreign_key: { on_delete: :cascade } | ||
t.references :data_type, null: false, foreign_key: { on_delete: :restrict } | ||
t.text :name, null: false, limit: 50 | ||
|
||
t.index %i[runtime_function_definition_id name], unique: true | ||
|
||
t.timestamps_with_timezone | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a0d27be6aad8dae7984bcdd0852e46534776bca0e0714f6ace3c5ff76870dac8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
98c5428b47c9184d281251a4db05a97bc964686db899bd88f37f7936a517d1f6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
sequence(:runtime_function_definition_name) { |n| "runtime_function_definition#{n}" } | ||
|
||
factory :runtime_function_definition do | ||
runtime_name { generate(:runtime_function_definition_name) } | ||
return_type factory: :data_type | ||
namespace | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
sequence(:runtime_parameter_definition_name) { |n| "runtime_parameter_definition#{n}" } | ||
|
||
factory :runtime_parameter_definition do | ||
runtime_function_definition | ||
data_type | ||
name { generate(:runtime_parameter_definition_name) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe RuntimeFunctionDefinition do | ||
subject { create(:runtime_function_definition) } | ||
|
||
describe 'validations' do | ||
it { is_expected.to have_many(:parameters).inverse_of(:runtime_function_definition) } | ||
|
||
it { is_expected.to validate_presence_of(:runtime_name) } | ||
it { is_expected.to validate_uniqueness_of(:runtime_name).case_insensitive.scoped_to(:namespace_id) } | ||
it { is_expected.to validate_length_of(:runtime_name).is_at_most(50) } | ||
|
||
it { is_expected.to validate_presence_of(:namespace) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe RuntimeParameterDefinition do | ||
subject { create(:runtime_parameter_definition) } | ||
|
||
describe 'validations' do | ||
it { is_expected.to validate_presence_of(:name) } | ||
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to(:runtime_function_definition_id) } | ||
it { is_expected.to validate_length_of(:name).is_at_most(50) } | ||
|
||
it { is_expected.to validate_presence_of(:runtime_function_definition) } | ||
it { is_expected.to validate_presence_of(:data_type) } | ||
end | ||
end |