-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.rb
More file actions
35 lines (26 loc) · 799 Bytes
/
Copy pathdatabase.rb
File metadata and controls
35 lines (26 loc) · 799 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
31
32
33
34
require 'active_record'
dbconfig = YAML.load(File.read('config/database.yml'))
ActiveRecord::Base.establish_connection dbconfig['production']
ActiveRecord::Base.default_timezone = :utc
class ActiveRecord::Schema
def self.apply(options, &block)
if (ActiveRecord::Base.connection.select_value("SELECT 'found' FROM schema_migrations WHERE version = #{options[:version]}") rescue nil) != 'found'
self.define(options, &block)
end
end
end
# Schema
ActiveRecord::Schema.apply(:version => 1) do
create_table :visits, :force => true do |t|
t.string :uid
t.string :landing_page
t.string :referrer
t.datetime :created_at
end
add_index :visits, :uid
add_index :visits, :created_at
end
# Models
class Visit < ActiveRecord::Base
validates_presence_of :uid
end