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
6 changes: 6 additions & 0 deletions server/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@ gem "rexml", "~> 3.4.2"

gem "git", "~> 4.0"

<<<<<<< HEAD
gem "pdf-reader", "~> 2.15"
=======
gem "ruby-openai", "~> 8.3"

gem "paper_trail", "~> 17.0"
>>>>>>> 578f80e42 (feat(CE): database migrations for workflow versioning (#1598))
6 changes: 6 additions & 0 deletions server/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,9 @@ GEM
orm_adapter (0.5.0)
os (1.1.4)
ostruct (0.6.1)
paper_trail (17.0.0)
activerecord (>= 7.1)
request_store (~> 1.4)
parallel (1.24.0)
parser (3.3.0.3)
ast (~> 2.4.1)
Expand Down Expand Up @@ -2153,6 +2156,8 @@ GEM
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
request_store (1.7.0)
rack (>= 1.4)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
Expand Down Expand Up @@ -2342,6 +2347,7 @@ DEPENDENCIES
multiwoven-integrations (~> 0.34.6)
mysql2
newrelic_rpm
paper_trail (~> 17.0)
parallel
pdf-reader (~> 2.15)
pg (~> 1.1)
Expand Down
37 changes: 37 additions & 0 deletions server/app/models/agents/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@

module Agents
class Workflow < ApplicationRecord
has_paper_trail if: ->(_workflow) { false }, # Disable automatic versions
meta: {
version_number: :version_number,
associations: :associations_for_version
}

def associations_for_version
{
components: components.map(&:attributes),
edges: edges.map(&:attributes)
}
end

def latest_published_version
return nil if versions.empty?

latest_published_version = versions.where(event: "published").reorder(version_number: :desc).first
return nil if latest_published_version.nil?

latest_workflow = latest_published_version.reify
return nil if latest_workflow.nil?

latest_workflow.association(:components).target = []
latest_workflow.association(:edges).target = []
latest_published_version.associations["components"].each do |component|
latest_workflow.components.build(component)
end
latest_published_version.associations["edges"].each do |edge|
latest_workflow.edges.build(edge)
end
latest_workflow
end

default_scope { order(updated_at: :desc) }

belongs_to :workspace
Expand Down Expand Up @@ -30,5 +63,9 @@ def build_dag
def generate_token_on_publish
self.token = SecureRandom.hex(16) if status_changed? && published?
end

def version_number_changed?
saved_change_to_version_number?
end
end
end
4 changes: 4 additions & 0 deletions server/config/initializers/paper_trail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Switch to JSON Serializer, instead of default YAML.
# YAML deserialization raises security-related issues,
# specifically when deserializing TimeWithZone, TimeZone, Date, Time, etc.
PaperTrail.serializer = PaperTrail::Serializers::JSON
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddVersionNumberToWorkflow < ActiveRecord::Migration[7.1]
def up
add_column :workflows, :version_number, :integer, default: 1
end

def down
remove_column :workflows, :version_number
end
end
41 changes: 41 additions & 0 deletions server/db/migrate/20260118124139_create_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This migration creates the `versions` table for the Version class.
# All other migrations PT provides are optional.
class CreateVersions < ActiveRecord::Migration[7.1]

# The largest text column available in all supported RDBMS is
# 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
# so that MySQL will use `longtext` instead of `text`. Otherwise,
# when serializing very large objects, `text` might not be big enough.
TEXT_BYTES = 1_073_741_823

def change
create_table :versions do |t|
# Consider using bigint type for performance if you are going to store only numeric ids.
# t.bigint :whodunnit
t.string :whodunnit

# Known issue in MySQL: fractional second precision
# -------------------------------------------------
#
# MySQL timestamp columns do not support fractional seconds unless
# defined with "fractional seconds precision". MySQL users should manually
# add fractional seconds precision to this migration, specifically, to
# the `created_at` column.
# (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html)
#
# MySQL users should also upgrade to at least rails 4.2, which is the first
# version of ActiveRecord with support for fractional seconds in MySQL.
# (https://github.com/rails/rails/pull/14359)
#
# MySQL users should use the following line for `created_at`
# t.datetime :created_at, limit: 6
t.datetime :created_at

t.string :item_id, null: false
t.string :item_type, null: false
t.string :event, null: false
t.text :object, limit: TEXT_BYTES
end
add_index :versions, %i[item_type item_id]
end
end
13 changes: 13 additions & 0 deletions server/db/migrate/20260118124206_add_metadata_to_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AddMetadataToVersions < ActiveRecord::Migration[7.1]
def up
add_column :versions, :version_number, :integer
add_column :versions, :version_description, :text
add_column :versions, :associations, :jsonb
end

def down
remove_column :versions, :version_number
remove_column :versions, :version_description
remove_column :versions, :associations
end
end
19 changes: 19 additions & 0 deletions server/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading