Skip to content

Commit 2604fad

Browse files
committed
Allow use of rake db tasks
[#46224565] The following rake tasks are added and work similar to how they work in rails apps: * db:create * db:drop * db:migrate * db:migrate:status * db:rollback * db:schema:dump * db:schema:load * db:seed (but no db seeds defined at this time) * db:setup * db:version The hidden task db:test:prepare is also available, which means `rake spec` can depend on it so that the test database is dropped and recreated from the development database when running specs (Although there are yet to be database tests, this branch is in preparation for that work that will be split between multiple developers.)
1 parent d8f46e3 commit 2604fad

File tree

7 files changed

+800
-2
lines changed

7 files changed

+800
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
.yardoc
77
# Mac OS X files
88
.DS_Store
9+
# database config for testing
10+
config/database.yml
911
# simplecov coverage data
1012
coverage
1113
data/meterpreter/ext_server_pivot.dll

Rakefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ require 'bundler/setup'
22

33
require 'metasploit_data_models'
44

5+
#
6+
# load rake files like a rails engine
7+
#
8+
9+
pathname = Pathname.new(__FILE__)
10+
root = pathname.parent
11+
rakefile_glob = root.join('lib', 'tasks', '**', '*.rake').to_path
12+
13+
Dir.glob(rakefile_glob) do |rakefile|
14+
load rakefile
15+
end
16+
517
print_without = false
618

719
begin
@@ -12,7 +24,7 @@ rescue LoadError
1224

1325
print_without = true
1426
else
15-
RSpec::Core::RakeTask.new(:spec)
27+
RSpec::Core::RakeTask.new(:spec => 'db:test:prepare')
1628

1729
task :default => :spec
1830
end

config/database.yml.example

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Please only use postgresql bound to a TCP port.
2+
development: &pgsql
3+
adapter: postgresql
4+
database: metasploit_framework_development
5+
username: metasploit_framework_development
6+
password: __________________________________
7+
host: localhost
8+
port: 5432
9+
pool: 5
10+
timeout: 5
11+
12+
# Warning: The database defined as "test" will be erased and
13+
# re-generated from your development database when you run "rake".
14+
# Do not set this db to the same as development or production.
15+
#
16+
# Note also, sqlite3 is totally unsupported by Metasploit now.
17+
test:
18+
<<: *pgsql
19+
database: metasploit_framework_test
20+
username: metasploit_framework_test
21+
password: ___________________________

0 commit comments

Comments
 (0)