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
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
|
# File 'lib/ditty/rake_tasks.rb', line 11
def install_tasks
namespace :ditty do
desc 'Generate the needed tokens'
task :generate_tokens do
puts 'Generating the Ditty tokens'
require 'securerandom'
File.write('.session_secret', SecureRandom.random_bytes(40)) unless File.file?('.session_secret')
File.write('.token_secret', SecureRandom.random_bytes(40)) unless File.file?('.token_secret')
end
desc 'Seed the Ditty database'
task :seed do
puts 'Seeding the Ditty database'
require 'ditty/seed'
end
desc 'Prepare Ditty'
task :prep do
puts 'Prepare the Ditty folders'
Dir.mkdir 'pids' unless File.exist?('pids')
puts 'Preparing the Ditty public folder'
Dir.mkdir 'public' unless File.exist?('public')
::Ditty::Components.public_folder.each do |path|
FileUtils.cp_r "#{path}/.", 'public' unless File.expand_path("#{path}/.").eql? File.expand_path('public')
end
puts 'Preparing the Ditty migrations folder'
Dir.mkdir 'migrations' unless File.exist?('migrations')
::Ditty::Components.migrations.each do |path|
FileUtils.cp_r "#{path}/.", 'migrations' unless File.expand_path("#{path}/.").eql? File.expand_path('migrations')
end
puts 'Migrations added:'
Dir.foreach('migrations').sort.each { |x| puts x if File.file?("migrations/#{x}") }
end
desc 'Migrate Ditty database to latest version'
task :migrate do
puts 'Running the Ditty migrations'
Rake::Task['ditty:migrate:up'].invoke
end
namespace :migrate do
require 'logger'
folder = 'migrations'
desc 'Check if the migration is current'
task :check do
::DB.loggers << Logger.new($stdout)
puts 'Running Ditty Migrations check'
::Sequel.extension :migration
begin
::Sequel::Migrator.check_current(::DB, folder)
puts 'Migrations up to date'
rescue Sequel::Migrator::Error => _e
puts 'Migrations NOT up to date'
end
end
desc 'Migrate Ditty database to latest version'
task :up do
::DB.loggers << Logger.new($stdout)
puts 'Running Ditty Migrations up'
::Sequel.extension :migration
::Sequel::Migrator.apply(::DB, folder)
end
desc 'Remove the whole Ditty database. You WILL lose data'
task :down do
::DB.loggers << Logger.new($stdout)
puts 'Running Ditty Migrations down'
::Sequel.extension :migration
::Sequel::Migrator.apply(::DB, folder, 0)
end
desc 'Reset the Ditty database. You WILL lose data'
task :bounce do
::DB.loggers << Logger.new($stdout)
puts 'Running Ditty Migrations bounce'
::Sequel.extension :migration
::Sequel::Migrator.apply(::DB, folder, 0)
::Sequel::Migrator.apply(::DB, folder)
end
end
end
end
|