forked from NoelleDL/bookmark-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakeFile
31 lines (28 loc) · 1.1 KB
/
RakeFile
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
require 'pg'
task default: %w[new_db test_database_population]
task :new_db do
p 'Creating Databases...........'
# creating new databases and tables if don't already exist
['bookmark_manager', 'bookmark_manager_test'].each do |db|
connection = PG.connect
begin
connection.exec("CREATE DATABASE #{db};")
connection = PG.connect(dbname: db)
puts "Database #{db} created."
connection.exec("CREATE TABLE links(id SERIAL PRIMARY KEY, url VARCHAR(60));")
puts "Tables on #{db} created."
rescue PG::Error => e
puts e.message
end
end
end
task :test_database_population do
p "clearing up and populating test database..."
connection = PG.connect(dbname: 'bookmark_manager_test')
connection.exec("Truncate links;")
connection.exec("INSERT INTO links VALUES(1, 'http://www.makersacademy.com');")
connection.exec("INSERT INTO links VALUES(2, 'http://www.google.com');")
connection.exec("INSERT INTO links VALUES(3, 'http://www.facebook.com');")
connection.exec("INSERT INTO links VALUES(4, 'http://www.testing_this.com');")
p "links added to test database."
end