-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.rb
More file actions
30 lines (26 loc) · 730 Bytes
/
database.rb
File metadata and controls
30 lines (26 loc) · 730 Bytes
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
require 'data_mapper'
class Database
def self.initialize
DataMapper::Logger.new($stdout, :debug)
# memory database appears to timeout if not used in ~5 mins, which causes the database to be dumped
#DataMapper.setup(:default, 'sqlite::memory:')
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
DataMapper.finalize
DataMapper.auto_upgrade!
self.seed_data unless Donation.all.count > 0
end
def self.seed_data
(1..200).each do |donation|
Donation.create(
amount: donation,
paid: false
)
end
end
end
class Donation
include DataMapper::Resource
property :id, Serial
property :amount, Integer
property :paid, Boolean
end