Skip to content

Commit

Permalink
updated vagrant conf, updates in readme, added license and extra tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nu7hatch committed Jul 23, 2012
1 parent a3f422f commit 5c3fa6c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012 Chris Kowalik

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ password hash for your password:
Copy generated hash and assign it to `ADMIN_PASSWORD_HASH` in `.env` file,
edit database configuration and other settings.

Last thing to do is to run migrations:
Last thing to do is to run create databases and run migrations:

$ foreman run rake db:create
$ foreman run rake db:migrate

As you can se, we must use `foreman run` command from now on - it's because
Expand Down
4 changes: 2 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Vagrant::Config.run do |config|

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "https://dl.dropbox.com/s/693uz0riijn60ia/ubuntu-precise-server-x64-desantapp.box?dl=1"
config.vm.box_url = "https://dl.dropbox.com/s/wbkg9xoq80rvgdc/ubuntu-precise-server-x64-desantapp.box?dl=1"

# Boot with a GUI so you can see the screen. (Default is headless)
# config.vm.boot_mode = :gui
Expand All @@ -34,5 +34,5 @@ Vagrant::Config.run do |config|
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the
# folder, and the third is the path on the host to the actual folder.
config.vm.share_folder "v-root", "/home/vagrant/desant", "", :nfs => true
config.vm.share_folder "v-root", "/home/vagrant/desantapp", "", :nfs => true
end
40 changes: 40 additions & 0 deletions lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@ namespace :db do
$migrations_dir = File.join($db_dir, 'migrate')
end

task :get_db_name do
$db_name = ENV['DATABASE_NAME'] || ENV['DATABASE']

if $db_name.to_s.empty?
puts "Invalid database name!"
exit(1)
end
end

task :raw_connection do
require 'active_record'

ActiveRecord::Base.establish_connection({
:adapter => ENV['DATABASE_ADAPTER'],
:host => ENV['DATABASE_HOST'],
:username => ENV['DATABASE_USER'],
:password => ENV['DATABASE_PASS']
})
end

desc "Create project databases"
task :create => [:raw_connection, :get_db_name] do
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}

['', '_test', '_development'].each do |suffix|
begin
ActiveRecord::Base.connection.create_database $db_name + suffix, options
rescue => e
raise e unless e.to_s =~ /database exists/
end
end
end

desc "Drop project databases"
task :drop => [:raw_connection, :get_db_name] do
['', '_test', '_development'].each do |suffix|
ActiveRecord::Base.connection.drop_database($db_name + suffix)
end
end

desc "Truncate whole the database"
task :truncate => [:environment, :paths] do
Reusable::ActiveRecordTasks.truncate
Expand Down

0 comments on commit 5c3fa6c

Please sign in to comment.