blob: 10936610b5deb9a6fa8ee1a4ac1bee012e805b35 (
plain)
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
48
49
|
require 'rubygems'
require 'bundler'
Bundler.require(:default)
DATABASE_NAME = 'sql_bootcamp'
DATABASE = Sequel.connect("mysql2://root@localhost/#{DATABASE_NAME}")
#| BUSINESSES | | COMPUTERS | | EVENTS | |
#| id | int | id | int | id | int |
#| name | varchar(255) | active | tinyint | computer_id | int |
#| business_relationship_id | int | business_id | int | occurred_at | datetime |
#| | | | | type | varchar(255) |
#| | | | | data | text |
namespace :db do
def pipe_to_mysql(command)
`echo "#{command}" | mysql -u root`
end
desc "create database"
task :create do
pipe_to_mysql("CREATE DATABASE #{DATABASE_NAME}")
end
desc "drop database"
task :drop do
pipe_to_mysql("DROP DATABASE IF EXISTS #{DATABASE_NAME}")
end
desc "Run migrations"
task :migrate, [:version] do |t, args|
Sequel.extension :migration
if args[:version]
puts "Migrating to version #{args[:version]}"
Sequel::Migrator.run(DATABASE, "db/migrations", target: args[:version].to_i)
else
puts "Migrating to latest"
Sequel::Migrator.run(DATABASE, "db/migrations")
end
end
task :seed do
require_relative 'db/seeds.rb'
end
desc "drop, create and migrate the database"
task :reset => [:drop, :create, :migrate, :seed]
end
|