lib/picky/sources/db.rb in picky-1.4.1 vs lib/picky/sources/db.rb in picky-1.4.2
- old
+ new
@@ -81,12 +81,19 @@
on_database = database.connection
on_database.execute "DROP TABLE IF EXISTS #{origin}"
on_database.execute "CREATE TABLE #{origin} AS #{select_statement}"
- on_database.execute "ALTER TABLE #{origin} CHANGE COLUMN id indexed_id INTEGER"
- on_database.execute "ALTER TABLE #{origin} ADD COLUMN id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT"
+ # TODO Use rename_column ASAP.
+ #
+ if on_database.adapter_name == "PostgreSQL"
+ on_database.execute "ALTER TABLE #{origin} RENAME COLUMN id TO indexed_id"
+ on_database.execute "ALTER TABLE #{origin} ADD COLUMN id SERIAL PRIMARY KEY"
+ else
+ on_database.execute "ALTER TABLE #{origin} CHANGE COLUMN id indexed_id INTEGER"
+ on_database.execute "ALTER TABLE #{origin} ADD COLUMN id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT"
+ end
# Execute any special queries this type needs executed.
#
on_database.execute type.after_indexing if type.after_indexing
end
@@ -117,13 +124,27 @@
# Gets the data from the backend.
#
def get_data type, category, offset, &block # :nodoc:
select_statement = harvest_statement_with_offset(type, category, offset)
- database.connection.execute(select_statement).each do |indexed_id, text|
- next unless text
- text.force_encoding 'utf-8' # TODO Still needed? Or move to backend?
- yield indexed_id, text
+
+ # TODO Rewrite ASAP.
+ #
+ if database.connection.adapter_name == "PostgreSQL"
+ id_key = 'indexed_id'
+ text_key = category.from.to_s
+ database.connection.execute(select_statement).each do |hash|
+ indexed_id, text = hash.values_at id_key, text_key
+ next unless text
+ text.force_encoding 'utf-8' # TODO Still needed? Or move to backend?
+ yield indexed_id, text
+ end
+ else
+ database.connection.execute(select_statement).each do |indexed_id, text|
+ next unless text
+ text.force_encoding 'utf-8' # TODO Still needed? Or move to backend?
+ yield indexed_id, text
+ end
end
end
# Builds a harvest statement for getting data to index.
#
\ No newline at end of file