From 5e3557cb63a9d94ee25df6d832018b35174d6955 Mon Sep 17 00:00:00 2001 From: James Dinkel Date: Tue, 19 Aug 2025 23:39:39 -0500 Subject: [PATCH] Add models and rake tasks for migrating --- .gitignore | 1 + Rakefile | 54 +++++++++++++++++++++++ db/migrations/0001_create_models_table.rb | 19 ++++++++ 3 files changed, 74 insertions(+) create mode 100644 db/migrations/0001_create_models_table.rb diff --git a/.gitignore b/.gitignore index 1861c6d..97155ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /temp.db /vendor/ /bin/ +/.continue/ \ No newline at end of file diff --git a/Rakefile b/Rakefile index d082351..39ac30d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,59 @@ +# frozen_string_literal: true + +# convert any arguments to a hash, maybe convert to a method and only call when needed +begin + arguments = ARGV.drop(1).map { |pair| pair.split('=', 2) }.to_h +rescue => e + puts "Arguments error: #{e.message}" +end + + require 'rake/testtask' Rake::TestTask.new do |task| task.pattern = 'test/*_test.rb' end + +namespace :db do + require_relative 'db' + require 'sequel/core' + Sequel.extension :migration + + migration_folder='db/migrations' + + desc "Run all pending migrations or to [:version]" + task :migrate, [:version] do |t, args| + begin + version = args[:version].to_i if args[:version] # rake's default way of passing in a single argument + version = arguments["version"].to_i if arguments["version"] # override if given key=value arguments + Sequel::Migrator.run(DB, "db/migrations", target: version) + puts "Migration completed successfully!" + rescue => e + puts "Migration failed: #{e.message}" + exit 1 + end + end + + desc "Rollback the last migration" + task :rollback do + begin + Sequel::Migrator.run(DB, "db/migrations", relative: -1) + rescue => e + puts "Rollback failed: #{e.message}" + exit 1 + end + end + + desc "Show current migration status" + task :status do + begin + status = "" + status = "NOT " if Sequel::Migrator.is_current?(DB, migration_folder) == false + puts "The database is #{status}current." + #puts Sequel::Migrator.is_current?(DB, migration_folder) + rescue => e + puts "Status check failed: #{e.message}" + exit 1 + end + end +end diff --git a/db/migrations/0001_create_models_table.rb b/db/migrations/0001_create_models_table.rb new file mode 100644 index 0000000..3f6f1de --- /dev/null +++ b/db/migrations/0001_create_models_table.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +Sequel.migration do + change do + create_table(:models) do + primary_key :id + String :name, null: false + String :run_command, null: false, unique: true + String :reputation, text: true + Integer :context_length + Integer :parameters + Float :prompt_rate + Float :eval_rate + String :capabilities + String :test_results + DateTime :created_at, null: false + end + end +end \ No newline at end of file