Add models and rake tasks for migrating

This commit is contained in:
James Dinkel 2025-08-19 23:39:39 -05:00
parent 0f108984ea
commit 5e3557cb63
3 changed files with 74 additions and 0 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/temp.db
/vendor/
/bin/
/.continue/

View file

@ -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

View file

@ -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