-
Notifications
You must be signed in to change notification settings - Fork 17
/
Rakefile
47 lines (41 loc) · 1.14 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
# zomg
class String
def camelize
self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end
end
# ZOMG
MIGRATION_TEMPLATE = <<MIG
Sequel.migration do
up do
# up code
end
down do
# down code
end
end
MIG
desc "database related stuff"
namespace :db do
require "sequel"
# rake argument passing sucks. let's see if we can do something about that
desc "migrate the database"
task :migrate, :version do |t, args|
version = args[:version].to_i if args[:version]
Sequel.extension :migration
DB = Sequel.sqlite("db/development.db")
migrate_dir = File.join "db", "migrations"
Sequel::Migrator.apply(DB, migrate_dir, version)
end
# this will be moved into the framework bin file, probably similar to rails' generators
# rubot generate migration <name>
desc "generate a new migration"
task :migration, [:name] do |t, args|
raise "No name given" unless args[:name]
stamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
filename = File.join "db", "migrations", "#{stamp}_#{args[:name]}.rb"
File.open(filename, "w") do |file|
file.puts MIGRATION_TEMPLATE
end
end
end