Class: Junebug::Models::CreateJunebug

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

Class Method Summary collapse

Class Method Details

.downObject



108
109
110
111
112
# File 'lib/junebug/models.rb', line 108

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

.upObject



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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/junebug/models.rb', line 61

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"
  if File.exist?(pages_file)
    puts "Loading fixtures"
    YAML.load_file(pages_file).each {|page_data|Page.create(page_data) }
  else
    puts "Could not find fixtures: #{pages_file}" 
  end
end