Commit 536b54e9 authored by Monica Olinescu's avatar Monica Olinescu

Use rake task in sinatra/activerecord/rake

parent c3d19d74
......@@ -16,39 +16,6 @@ task "db:drop" do
rm_f 'db/db.sqlite3'
end
task 'db:create_migration' do
unless ENV["NAME"]
puts "No NAME specified. Example usage: `rake db:create_migration NAME=create_users`"
exit
end
name = ENV["NAME"]
version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
ActiveRecord::Migrator.migrations_paths.each do |directory|
next unless File.exist?(directory)
migration_files = Pathname(directory).children
if duplicate = migration_files.find { |path| path.basename.to_s.include?(name) }
puts "Another migration is already named \"#{name}\": #{duplicate}."
exit
end
end
filename = "#{version}_#{name}.rb"
dirname = ActiveRecord::Migrator.migrations_path
path = File.join(dirname, filename)
FileUtils.mkdir_p(dirname)
File.write path, <<-MIGRATION.strip_heredoc
class #{name.camelize} < ActiveRecord::Migration
def change
end
end
MIGRATION
puts path
end
desc 'Retrieves the current schema version number'
task "db:version" do
puts "Current version: #{ActiveRecord::Migrator.current_version}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment