forked from mysterycodesociety/sinatra-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
61 lines (56 loc) · 2.06 KB
/
Rakefile
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
require './app'
namespace :db do
task :load_config do
require "./app"
end
desc "Set up the MCS database environment"
task :setupMCS do
db_config = YAML::load(File.open('./config/database.yml'))["development"]
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
ActiveRecord::Base.establish_connection(db_config_admin)
# template1 is what activerecord uses to make new databases
# template0 and template1 in Cloud9 are SQL_ASCII instead of unicode
# Make template1 not a template, drop it, and recreate it as unicode
sql = []
# make template1 not a template anymore
sql << "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';"
# drop template1
sql << "DROP DATABASE template1;"
# create template1 as a utf-8 encoded database
sql << "CREATE DATABASE template1 WITH template = template0 encoding = 'UTF8';"
# make template 1 a template
sql << "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';"
sql.each do |s|
ActiveRecord::Base.connection.execute(s)
end
puts "MCS database setup."
end
end
desc "Start the server."
task :serve, [:port, :ip] do |t, args|
host = ENV['C9_HOSTNAME'] || "localhost"
port = args.port || ENV['PORT'] || "4567"
ip = args.ip || ENV['IP'] || nil
puts "Start server: http(s)://#{host}:#{port}/"
if ip
sh "ruby ./app.rb -p #{port} -o #{ip}"
else
sh "ruby ./app.rb -p #{port}"
end
end
task :default do
options = {
"rake -T": "Will list all other rake tasks",
"rake serve": "Will run Sinatra server",
"rake db:setupMCS": "Will set up the MCS database",
"rake db:create": "Will create a database",
"rake db:migrate": "Will run migrations",
"rake db:drop": "Will drop the database",
"rake db:create_migration": "Will create a migration"
}
options.each do |h, v|
puts "#{h}: #{v}"
end
end