rb)
class InitialSchema < ActiveRecord::Migration
def self.up
create_table :hits do |t|
t.column :user_agent, :string
t.column :path_info,:string
t.column :remote_addr, :string
t.column :http_referrer, :string
t.column :status, :string
t.column :visited_at, :datetime
end
create_table :advertisers do |t|
t.column :company_name, :string
t.column :referrer_url, :string
t.column :cost_per_click, :decimal,
:precision => 9, :scale => 2
end
end
def self.down
drop_table :hits
drop_table :advertisers
end
end
Save this as db/migrate/001_initial_schema.rb. You can run the migration as follows:
rake db:migrate
== 1 InitialSchema: migrating =================================================
-- create_table(:hits)
-> 0.1570s
-- create_table(:advertisers)
-> 0.1250s
== 1 InitialSchema: migrated (0.2820s) ========================================
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 202
Defining the Models
This example uses two models: Advertiser and Hit, as shown in Listings 10-10 and 10-11.
Pages:
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292