Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions server/app/models/hosted_data_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class HostedDataStore < ApplicationRecord
belongs_to :workspace
belongs_to :source_connector, class_name: "Connector", optional: true
belongs_to :destination_connector, class_name: "Connector", optional: true
has_many :hosted_data_store_tables, dependent: :destroy

enum :database_type, { vector_db: 0, raw_sql: 1 }
enum :state, { disabled: 0, enabled: 1 }

validates :name, presence: true
validates :database_type, presence: true
validates :description, presence: true
validates :state, presence: true
validates :template_id, presence: true
end
28 changes: 28 additions & 0 deletions server/spec/models/hosted_data_store_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe HostedDataStore, type: :model do
describe "validations" do
it { should validate_presence_of(:name) }
it { should validate_presence_of(:database_type) }
it { should validate_presence_of(:description) }
it { should validate_presence_of(:state) }
it { should validate_presence_of(:template_id) }
end

describe "enum for database_type" do
it { should define_enum_for(:database_type).with_values(%i[vector_db raw_sql]) }
end

describe "enum for state" do
it { should define_enum_for(:state).with_values(%i[disabled enabled]) }
end

describe "associations" do
it { should belong_to(:workspace) }
it { should belong_to(:source_connector).class_name("Connector").optional }
it { should belong_to(:destination_connector).class_name("Connector").optional }
it { should have_many(:hosted_data_store_tables).dependent(:destroy) }
end
end
Loading