Class: Junebug::Models::CreateJunebug

Inherits:
V
  • Object
show all
Defined in:
lib/junebug/models.rb

Class Method Summary collapse

Class Method Details

.downObject



91
92
93
94
95
# File 'lib/junebug/models.rb', line 91

def self.down
  drop_table :junebug_pages
  drop_table :junebug_users
  Page.drop_versioned_table
end

.upObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/junebug/models.rb', line 48

def self.up
  create_table :junebug_users do |t|
    t.column :id,       :integer, :null => false
    t.column :username, :string, :null => false
    t.column :password, :string, :null => false
    t.column :role,     :integer, :default => 0
  end
  create_table :junebug_pages do |t|
    t.column :title, :string, :limit => 255
    t.column :body, :text
    t.column :user_id, :integer, :null => false
    t.column :readonly, :boolean, :default => false
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end
  Page.create_versioned_table
  Page.reset_column_information
  
  # Create admin account
  admin = User.new(:role => User::ROLE_ADMIN)
  if ENV['INTERACTIVE']
    loop {
      print "Create an initial user account\n"
      print "\nEnter your username (3-30 chars, no spaces or punctuation): "
      admin.username = STDIN.gets.strip
      print "\nEnter your password (5-30 chars, no spaces or punctuation): "
      admin.password = STDIN.gets.strip
      break if admin.valid?
      puts "\nThe following errors were encountered:"
      admin.errors.full_messages().each {|msg| puts "  #{msg}"}
      puts
    }
  else
    admin.username = 'admin'
    admin.password = 'password'
  end
  admin.save
  
  # Install some default pages
  pages_file = File.dirname(__FILE__) + "/../../dump/junebug_pages.yml"
  puts pages_file
  YAML.load_file(pages_file).each {|page_data|Page.create(page_data) } if File.exist?(pages_file)
end