Class: DbdocEngine::DbDesignChangelogQueries

Inherits:
Object
  • Object
show all
Defined in:
app/queries/dbdoc_engine/db_design_changelog_queries.rb

Class Method Summary collapse

Class Method Details

.filtered_changelogs(params = {}) ⇒ ActiveRecord::Relation

Fetch filtered changelogs based on provided parameters

Parameters:

  • params (Hash) (defaults to: {}) —

    Filter parameters including:

    • entity_type: Filter by entity type (table_group/table/column)
    • entity_name: Partial match for entity name
    • action_type: Filter by action type (create/update/delete)
    • date_from: Start date filter
    • date_to: End date filter

Returns:

  • (ActiveRecord::Relation) —

    Filtered and ordered changelogs



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/queries/dbdoc_engine/db_design_changelog_queries.rb', line 15

def filtered_changelogs(params = {})
  scope = DbDesignChangelog.all

  scope = scope.where(entity_type: params[:entity_type]) if params[:entity_type].present?
  scope = scope.where('entity_name ILIKE ?', "%#{params[:entity_name]}%") if params[:entity_name].present?
  scope = scope.where(action_type: params[:action_type]) if params[:action_type].present?

  if params[:date_from].present? && params[:date_to].present?
    from_date = Date.parse(params[:date_from]).beginning_of_day
    to_date = Date.parse(params[:date_to]).end_of_day
    scope = scope.where(change_timestamp: from_date..to_date)
  end

  scope.order(change_timestamp: :desc)
end

.find_changelog(id) ⇒ DbDesignChangelog?

Find a specific changelog entry by ID

Parameters:

  • id (Integer) —

    Changelog ID to find

Returns:



34
35
36
# File 'app/queries/dbdoc_engine/db_design_changelog_queries.rb', line 34

def find_changelog(id)
  DbDesignChangelog.find_by(id: id)
end

.find_group_name(id) ⇒ String?

Get group name by ID through TableGroupQueries

Parameters:

  • id (Integer) —

    Group ID to lookup

Returns:

  • (String, nil) —

    Group name or nil if not found



63
64
65
# File 'app/queries/dbdoc_engine/db_design_changelog_queries.rb', line 63

def find_group_name(id)
  DbDesignTableGroupQueries.find_group_name(id)
end

.log_change(action_type, entity_type, entity_name, description, changed_by, previous_values = nil, new_values = nil) ⇒ DbDesignChangelog

Create a new changelog entry with audit information

Parameters:

  • action_type (String) —

    Type of action performed

  • entity_type (String) —

    Type of entity affected

  • entity_name (String) —

    Name of the affected entity

  • description (String) —

    Human-readable change description

  • changed_by (String) —

    Identifier of who made the change

  • previous_values (Hash) (defaults to: nil) —

    Optional previous state values

  • new_values (Hash) (defaults to: nil) —

    Optional new state values

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/queries/dbdoc_engine/db_design_changelog_queries.rb', line 47

def log_change(action_type, entity_type, entity_name, description, changed_by, previous_values = nil, new_values = nil)
  DbDesignChangelog.create!(
    change_timestamp: Time.current,
    action_type: action_type,
    entity_type: entity_type,
    entity_name: entity_name,
    description: description,
    changed_by: changed_by,
    previous_values: previous_values,
    new_values: new_values
  )
end