Skip to content

Commit

Permalink
feat(CE): data app model changes (#353)
Browse files Browse the repository at this point in the history
Co-authored-by: afthab vp <[email protected]>
  • Loading branch information
github-actions[bot] and afthabvp authored Sep 3, 2024
1 parent 529e56b commit 50d3e08
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/app/models/data_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class DataApp < ApplicationRecord
validates :workspace_id, presence: true
validates :status, presence: true
validates :name, presence: true

enum :status, %i[inactive active draft]

belongs_to :workspace
has_many :visual_components, dependent: :destroy
has_many :models, through: :visual_components

after_initialize :set_default_status, if: :new_record?

private

def set_default_status
self.status ||= :draft
end
end
1 change: 1 addition & 0 deletions server/app/models/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Model < ApplicationRecord
belongs_to :connector

has_many :syncs, dependent: :destroy
has_many :visual_components, dependent: :destroy

scope :data, -> { where(query_type: %i[raw_sql dbt soql table_selector]) }
scope :ai_ml, -> { where(query_type: :ai_ml) }
Expand Down
14 changes: 14 additions & 0 deletions server/app/models/visual_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class VisualComponent < ApplicationRecord
validates :workspace_id, presence: true
validates :component_type, presence: true
validates :model_id, presence: true
validates :data_app_id, presence: true

enum :component_type, %i[pie bar data_table]

belongs_to :workspace
belongs_to :data_app
belongs_to :model
end
1 change: 1 addition & 0 deletions server/app/models/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Workspace < ApplicationRecord
has_many :catalogs, dependent: :nullify
has_many :syncs, dependent: :nullify
has_many :sync_runs, dependent: :nullify
has_many :data_apps, dependent: :nullify
belongs_to :organization

STATUS_ACTIVE = "active"
Expand Down
23 changes: 23 additions & 0 deletions server/spec/models/data_app_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe DataApp, type: :model do
it { should validate_presence_of(:workspace_id) }
it { should validate_presence_of(:status) }
it { should validate_presence_of(:name) }

it { should define_enum_for(:status).with_values(inactive: 0, active: 1, draft: 2) }

it { should belong_to(:workspace) }
it { should have_many(:visual_components).dependent(:destroy) }
it { should have_many(:models).through(:visual_components) }

describe "#set_default_status" do
let(:data_app) { DataApp.new }

it "sets default status" do
expect(data_app.status).to eq("draft")
end
end
end
1 change: 1 addition & 0 deletions server/spec/models/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
it { should belong_to(:workspace) }
it { should belong_to(:connector) }
it { should have_many(:syncs).dependent(:destroy) }
it { should have_many(:visual_components).dependent(:destroy) }
end

describe "validations" do
Expand Down
16 changes: 16 additions & 0 deletions server/spec/models/visual_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe VisualComponent, type: :model do
it { should validate_presence_of(:workspace_id) }
it { should validate_presence_of(:component_type) }
it { should validate_presence_of(:model_id) }
it { should validate_presence_of(:data_app_id) }

it { should define_enum_for(:component_type).with_values(pie: 0, bar: 1, data_table: 2) }

it { should belong_to(:workspace) }
it { should belong_to(:data_app) }
it { should belong_to(:model) }
end
1 change: 1 addition & 0 deletions server/spec/models/workspace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
it { should have_many(:models).dependent(:nullify) }
it { should have_many(:catalogs).dependent(:nullify) }
it { should have_many(:syncs).dependent(:nullify) }
it { should have_many(:data_apps).dependent(:nullify) }
it { should belong_to(:organization) }
end

Expand Down

0 comments on commit 50d3e08

Please sign in to comment.