diff options
Diffstat (limited to 'db')
16 files changed, 148 insertions, 5 deletions
diff --git a/db/.gitignore b/db/.gitignore index f3aee50a1..846a7b9b3 100644 --- a/db/.gitignore +++ b/db/.gitignore @@ -1,2 +1 @@ schema.rb -development_structure.sql diff --git a/db/migrate/006_version_public_body.rb b/db/migrate/006_version_public_body.rb index 34586add2..0e4527133 100644 --- a/db/migrate/006_version_public_body.rb +++ b/db/migrate/006_version_public_body.rb @@ -1,6 +1,8 @@ class VersionPublicBody < ActiveRecord::Migration def self.up PublicBody.create_versioned_table + + add_timestamps(:public_body_versions) end def self.down diff --git a/db/migrate/101_add_hash_to_info_request.rb b/db/migrate/101_add_hash_to_info_request.rb index e21bf0989..e38384cd6 100644 --- a/db/migrate/101_add_hash_to_info_request.rb +++ b/db/migrate/101_add_hash_to_info_request.rb @@ -5,13 +5,11 @@ class AddHashToInfoRequest < ActiveRecord::Migration add_column :info_requests, :idhash, :string # Create the missing events for requests already sent - InfoRequest.find(:all).each do |info_request| - info_request.idhash = Digest::SHA1.hexdigest(info_request.id.to_s + Configuration::incoming_email_secret)[0,8] + InfoRequest.all.each do |info_request| + info_request.idhash = Digest::SHA1.hexdigest(info_request.id.to_s + AlaveteliConfiguration::incoming_email_secret)[0,8] info_request.save! - puts info_request.idhash end change_column :info_requests, :idhash, :string, :null => false - puts InfoRequest.find_by_idhash end def self.down remove_column :info_requests, :idhash diff --git a/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb b/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb new file mode 100644 index 000000000..df0278c20 --- /dev/null +++ b/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb @@ -0,0 +1,9 @@ +class RemoveProminenceFromInfoRequestEvent < ActiveRecord::Migration + def up + remove_column :info_request_events, :prominence + end + + def down + add_column :info_request_events, :prominence, :string, :null => false, :default => 'normal' + end +end diff --git a/db/migrate/20130731145325_add_prominence_to_incoming_message.rb b/db/migrate/20130731145325_add_prominence_to_incoming_message.rb new file mode 100644 index 000000000..01c4906a7 --- /dev/null +++ b/db/migrate/20130731145325_add_prominence_to_incoming_message.rb @@ -0,0 +1,5 @@ +class AddProminenceToIncomingMessage < ActiveRecord::Migration + def change + add_column :incoming_messages, :prominence, :string, :null => false, :default => 'normal' + end +end diff --git a/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb b/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb new file mode 100644 index 000000000..2d189f658 --- /dev/null +++ b/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb @@ -0,0 +1,5 @@ +class AddProminenceReasonToIncomingMessage < ActiveRecord::Migration + def change + add_column :incoming_messages, :prominence_reason, :text + end +end diff --git a/db/migrate/20130816150110_add_statistics_to_public_body.rb b/db/migrate/20130816150110_add_statistics_to_public_body.rb new file mode 100644 index 000000000..fb3a67e83 --- /dev/null +++ b/db/migrate/20130816150110_add_statistics_to_public_body.rb @@ -0,0 +1,26 @@ +class AddStatisticsToPublicBody < ActiveRecord::Migration + def self.up + add_column :public_bodies, :info_requests_successful_count, :integer + add_column :public_bodies, :info_requests_not_held_count, :integer + add_column :public_bodies, :info_requests_overdue_count, :integer + # We need to set the :info_requests_successful_count and + # :info_requests_not_held_count columns, since they will + # subsequently will be updated in after_save / + # after_destroy. :info_requests_overdue_count, however will be set + # from a periodically run rake task. + PublicBody.connection.execute("UPDATE public_bodies + SET info_requests_not_held_count = (SELECT COUNT(*) FROM info_requests + WHERE described_state = 'not_held' AND + public_body_id = public_bodies.id);") + PublicBody.connection.execute("UPDATE public_bodies + SET info_requests_successful_count = (SELECT COUNT(*) FROM info_requests + WHERE described_state IN ('successful', 'partially_successful') AND + public_body_id = public_bodies.id);") + end + + def self.down + remove_column :public_bodies, :info_requests_successful_count + remove_column :public_bodies, :info_requests_not_held_count + remove_column :public_bodies, :info_requests_overdue_count + end +end diff --git a/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb b/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb new file mode 100644 index 000000000..a75e0d426 --- /dev/null +++ b/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb @@ -0,0 +1,6 @@ +class AddProminenceFieldsToOutgoingMessage < ActiveRecord::Migration + def change + add_column :outgoing_messages, :prominence, :string, :null => false, :default => 'normal' + add_column :outgoing_messages, :prominence_reason, :text + end +end diff --git a/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb b/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb new file mode 100644 index 000000000..cc9d8e76f --- /dev/null +++ b/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb @@ -0,0 +1,5 @@ +class AddCanMakeBatchRequestsToUser < ActiveRecord::Migration + def change + add_column :users, :can_make_batch_requests, :boolean, :default => false, :null => false + end +end diff --git a/db/migrate/20131024114346_create_info_request_batches.rb b/db/migrate/20131024114346_create_info_request_batches.rb new file mode 100644 index 000000000..09c6f467b --- /dev/null +++ b/db/migrate/20131024114346_create_info_request_batches.rb @@ -0,0 +1,22 @@ +class CreateInfoRequestBatches < ActiveRecord::Migration + def up + create_table :info_request_batches do |t| + t.column :title, :text, :null => false + t.column :user_id, :integer, :null => false + t.timestamps + end + add_column :info_requests, :info_request_batch_id, :integer, :null => true + if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" + execute "ALTER TABLE info_requests + ADD CONSTRAINT fk_info_requests_info_request_batch + FOREIGN KEY (info_request_batch_id) REFERENCES info_request_batches(id)" + end + add_index :info_requests, :info_request_batch_id + add_index :info_request_batches, :user_id + end + + def down + remove_column :info_requests, :info_request_batch_id + drop_table :info_request_batches + end +end diff --git a/db/migrate/20131024152540_add_body_to_info_request_batches.rb b/db/migrate/20131024152540_add_body_to_info_request_batches.rb new file mode 100644 index 000000000..5f9b3af10 --- /dev/null +++ b/db/migrate/20131024152540_add_body_to_info_request_batches.rb @@ -0,0 +1,11 @@ +class AddBodyToInfoRequestBatches < ActiveRecord::Migration + def up + add_column :info_request_batches, :body, :text + add_index :info_request_batches, [:user_id, :body, :title] + end + + def down + remove_column :info_request_batches, :body + end + +end diff --git a/db/migrate/20131101155844_add_stats_denominator.rb b/db/migrate/20131101155844_add_stats_denominator.rb new file mode 100644 index 000000000..7df4c8200 --- /dev/null +++ b/db/migrate/20131101155844_add_stats_denominator.rb @@ -0,0 +1,15 @@ +class AddStatsDenominator < ActiveRecord::Migration + def up + add_column :public_bodies, :info_requests_visible_classified_count, :integer + PublicBody.connection.execute("UPDATE public_bodies + SET info_requests_visible_classified_count = + (SELECT COUNT(*) FROM info_requests + WHERE awaiting_description = FALSE AND + prominence = 'normal' AND + public_body_id = public_bodies.id);") + end + + def down + remove_column :public_bodies, :info_requests_visible_classified_count + end +end diff --git a/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb b/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb new file mode 100644 index 000000000..11a9c7066 --- /dev/null +++ b/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb @@ -0,0 +1,8 @@ +class CreateInfoRequestBatchPublicBodiesJoinTable < ActiveRecord::Migration + def change + create_table :info_request_batches_public_bodies, :id => false do |t| + t.integer :info_request_batch_id + t.integer :public_body_id + end + end +end diff --git a/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb b/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb new file mode 100644 index 000000000..27d4aecee --- /dev/null +++ b/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb @@ -0,0 +1,5 @@ +class AddSentAtToInfoRequestBatch < ActiveRecord::Migration + def change + add_column :info_request_batches, :sent_at, :datetime + end +end diff --git a/db/migrate/20131211152641_create_public_body_change_requests.rb b/db/migrate/20131211152641_create_public_body_change_requests.rb new file mode 100644 index 000000000..e3fb560a6 --- /dev/null +++ b/db/migrate/20131211152641_create_public_body_change_requests.rb @@ -0,0 +1,20 @@ +class CreatePublicBodyChangeRequests < ActiveRecord::Migration + def up + create_table :public_body_change_requests do |t| + t.column :user_email, :string + t.column :user_name, :string + t.column :user_id, :integer + t.column :public_body_name, :text + t.column :public_body_id, :integer + t.column :public_body_email, :string + t.column :source_url, :text + t.column :notes, :text + t.column :is_open, :boolean, :null => false, :default => true + t.timestamps + end + end + + def down + drop_table :public_body_change_requests + end +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 000000000..664d8c74c --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) +# Mayor.create(:name => 'Daley', :city => cities.first) |