#!/usr/bin/env ruby require './boot' def confirm_drop_db? print 'We are going to drop and recreate the database, are you sure you want to proceed? [Y/n] ' answer = gets.chomp.downcase answer.blank? || answer =~ /^y/ end config = TinyRailsApp.config.database_configuration[Rails.env] require 'pathname' path = Pathname.new(config['database']) file = path.absolute? ? path.to_s : File.join(Rails.root, path) exit 0 if File.exist?(file) && !confirm_drop_db? # "Drop" database FileUtils.rm(file) if File.exist?(file) # Creates database ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection ActiveRecord::Schema.define do create_table "posts" do |t| t.string "title" t.text "body" t.timestamps end end