Permalink
Browse files

updated vagrant conf, updates in readme, added license and extra tasks

  • Loading branch information...
1 parent a3f422f commit 5c3fa6c01e33135abff4e958757577d42802cce6 @nu7hatch committed Jul 23, 2012
Showing with 66 additions and 3 deletions.
  1. +22 −0 LICENSE
  2. +2 −1 README.md
  3. +2 −2 Vagrantfile
  4. +40 −0 lib/tasks/db.rake
View
22 LICENSE
@@ -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.
View
@@ -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
View
@@ -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
@@ -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
View
@@ -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

0 comments on commit 5c3fa6c

Please sign in to comment.