Skip to content

Commit

Permalink
issue-218: create assertion model
Browse files Browse the repository at this point in the history
  • Loading branch information
¨caiovelp¨ committed Dec 9, 2024
1 parent 2ba309e commit d4e3103
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/models/assertion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

class Assertion < ApplicationRecord
has_paper_trail

attr_accessor :args
belongs_to :query, inverse_of: :assertions, optional: false

validates :name, presence: true
validates :assertion_template, presence: true, on: :update

def to_label
"#{self.name}"
end
end
1 change: 1 addition & 0 deletions app/models/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Represents a Query
class Query < ApplicationRecord
has_many :notifications, inverse_of: :query
has_many :assertions, inverse_of: :query
has_many :params,
class_name: "QueryParam",
dependent: :destroy, validate: false,
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20241209223140_create_assertions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateAssertions < ActiveRecord::Migration[7.0]
def change
create_table :assertions do |t|
t.string :name

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241209223141_add_query_id_to_assertions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddQueryIdToAssertions < ActiveRecord::Migration[7.0]
def change
add_reference :assertions, :query, null: true, foreign_key: true
end
end
10 changes: 10 additions & 0 deletions db/migrate/20241209223142_populate_query_id_in_assertions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class PopulateQueryIdInAssertions < ActiveRecord::Migration[7.0]
def up
default_query = Query.first
Assertion.update_all(query_id: default_query.id) if default_query
end

def down
# No need to revert data changes
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241209223143_change_query_id_in_assertions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeQueryIdInAssertions < ActiveRecord::Migration[7.0]
def change
change_column_null :assertions, :query_id, false
end
end

0 comments on commit d4e3103

Please sign in to comment.