-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.rb
41 lines (36 loc) · 1.22 KB
/
install.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'find'
require 'fileutils'
RAILS_ROOT = File.dirname(__FILE__) + "/../../.."
MIGRATIONS_DIR = "#{RAILS_ROOT}/db/migrate/"
# This method will create a new migration filename
# Please note that this could be done with more sugar through the generator classes.
def build_migration_file_name (name)
migration_number_strings = []
Find.find(MIGRATIONS_DIR) do |filename|
nr_scan = filename.scan( /((\d){3})[^\/]*rb$/ )
while nr_scan.class == Array
nr_scan = nr_scan[0]
end
migration_number_strings << nr_scan
end
sprintf "%.3d_%s.rb", ( migration_number_strings.map{ |s| s.to_s.to_i }.max + 1 ), name
end
# Create the new migration to support the tags_done_right system
filename = MIGRATIONS_DIR + (build_migration_file_name "create_tags")
puts "Printing to: " + filename
File.open(filename, 'w') do |f|
f.write("# THIS IS AN AUTOGENERATED FILE BY TAGS_DONE_RIGHT
# This migration sets-up the database to store the tags in it.
# Advanced users may modify it to attach extra information to a tag
class CreateTags < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.column :name, :string
end
add_index :tags, \"name\"
end
def self.down
drop_table :tags
end
end")
end