<commit_before>#!/usr/bin/env ruby 

require 'rubygems'  
require 'active_record'  
require 'yaml'
require 'optparse' 

require 'db/schema.rb'

$stdout.sync = true


def migrate(direction)
	ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))

	if File.exists?("database.yml") == false
		puts "Could not find database.yml!"
		exit
	end
	
	Schema.migrate(direction)
end

@opt = OptionParser.new { |opt|
	opt.banner =  "DB Migration Tool"
	opt.banner << "usage: #{$0} [command] <options> [targets]"
	opt.separator('')
	opt.separator('Commands:')

	opt.on('-c', '--create-tables', 'Creates tables.') { 
		migrate(:up)
		puts "Successfully created tables."
		exit
	}

	opt.on('-d', '--delete-tables', 'Deletes tables.') { 
		migrate(:down)
		puts "Successfully deleted tables."
		exit
	}
     
	opt.on('-f', '--create-config-file', 'Creates an empty database.yml file to be edited.') { 
		if File.exists?("database.yml") == false
			File.open("database.yml", 'w+') { |f| 
				f.write("adapter: \nhost: \nport: \ndatabase: \nusername: \npassword: \ntimeout: \n") 
			}<commit_msg>Check to make sure the file exists BEFORE you try to open it.<commit_after>#!/usr/bin/env ruby 

require 'rubygems'  
require 'active_record'  
require 'yaml'
require 'optparse' 

require 'db/schema.rb'

$stdout.sync = true


def migrate(direction)
	if File.exists?("database.yml") == false
		puts "Could not find database.yml!"
		exit
	end

	ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))
	
	Schema.migrate(direction)
end

@opt = OptionParser.new { |opt|
	opt.banner =  "DB Migration Tool"
	opt.banner << "usage: #{$0} [command] <options> [targets]"
	opt.separator('')
	opt.separator('Commands:')

	opt.on('-c', '--create-tables', 'Creates tables.') { 
		migrate(:up)
		puts "Successfully created tables."
		exit
	}

	opt.on('-d', '--delete-tables', 'Deletes tables.') { 
		migrate(:down)
		puts "Successfully deleted tables."
		exit
	}
     
	opt.on('-f', '--create-config-file', 'Creates an empty database.yml file to be edited.') { 
		if File.exists?("database.yml") == false
			File.open("database.yml", 'w+') { |f| 
				f.write("adapter: \nhost: \nport: \ndatabase: \nusername: \npassword: \ntimeout: \n") 
			}
{'fraction_non_alphanumeric': 0.18, 'fraction_numerical': 0.0008888888888888889, 'mean_word_length': 3.893478260869565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '851650', 'n_tokens_mistral': 902, 'n_tokens_neox': 818, 'n_words': 188}