Next, let??™s examine the code that contains the single model and the schema:
class Stories < ActiveRecord::Base
end
unless Stories.table_exists?
ActiveRecord::Schema.define do
create_table :stories do |t|
t.column :guid, :string
t.column :title, :string
t.column :source, :string
t.column :url, :string
t.column :published_at, :datetime
t.column :created_at, :datetime
end
create_table :cached_feeds do |t|
t.column :url , :string
t.column :title, :string
t.column :href, :string
t.column :link, :string
t.column :feed_data, :text
t.column :feed_data_type, :string, :length=>25
t.column :http_headers, :text
t.column :last_retrieved, :datetime
end
CHAPTER 11 n TRACKING THE NEWS WITH GOOGLE NEWS 223
# Without the following line,
# you can't retrieve large results -
# like those we use in this script.
execute "ALTER TABLE cached_feeds
CHANGE COLUMN feed_data feed_data MEDIUMTEXT;"
end
end
This code creates a single model, Stories, and then creates a table for it. It also creates
a second table named cached_feeds, which is used by FeedTools to store cached
feeds.
Pages:
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320