Add models and rake tasks for migrating
This commit is contained in:
parent
0f108984ea
commit
5e3557cb63
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
||||||
/temp.db
|
/temp.db
|
||||||
/vendor/
|
/vendor/
|
||||||
/bin/
|
/bin/
|
||||||
|
/.continue/
|
||||||
54
Rakefile
54
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'
|
require 'rake/testtask'
|
||||||
|
|
||||||
Rake::TestTask.new do |task|
|
Rake::TestTask.new do |task|
|
||||||
task.pattern = 'test/*_test.rb'
|
task.pattern = 'test/*_test.rb'
|
||||||
end
|
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
|
||||||
|
|
|
||||||
19
db/migrations/0001_create_models_table.rb
Normal file
19
db/migrations/0001_create_models_table.rb
Normal 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
|
||||||
Loading…
Reference in a new issue