1
print "Using native SQlite\n"
2
require_dependency 'models/course'
4
ActiveRecord::Base.logger = Logger.new("debug.log")
6
class SqliteError < StandardError
9
BASE_DIR = FIXTURES_ROOT
10
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
11
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
13
def make_connection(clazz, db_file)
14
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite', :database => db_file } }
15
unless File.exist?(db_file)
16
puts "SQLite database not found at #{db_file}. Rebuilding it."
17
sqlite_command = %Q{sqlite "#{db_file}" "create table a (a integer); drop table a;"}
18
puts "Executing '#{sqlite_command}'"
19
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
21
clazz.establish_connection(clazz.name)
24
make_connection(ActiveRecord::Base, sqlite_test_db)
25
make_connection(Course, sqlite_test_db2)