aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-02-12 14:46:58 +0000
committerfrancis <francis>2008-02-12 14:46:58 +0000
commitd296a09d9acd0dc033e509dbb05dbd36b0b65762 (patch)
treee45571f4bd2afd3cd2ee42553a0e28a0a413747e
parent56d2ffd5d936aea42e2218fbd1dc9c7bc4bfe301 (diff)
It's a shitty way to add foreign keys to the database, but it works (tried to
find a plugin, but there are many and they're not very good).
-rw-r--r--db/migrate/032_addforeignkeys.rb32
-rw-r--r--db/schema.rb2
-rw-r--r--todo.txt12
3 files changed, 36 insertions, 10 deletions
diff --git a/db/migrate/032_addforeignkeys.rb b/db/migrate/032_addforeignkeys.rb
new file mode 100644
index 000000000..645aa2324
--- /dev/null
+++ b/db/migrate/032_addforeignkeys.rb
@@ -0,0 +1,32 @@
+class Addforeignkeys < ActiveRecord::Migration
+ def self.up
+ execute "ALTER TABLE incoming_messages ADD CONSTRAINT fk_incoming_messages_info_request FOREIGN KEY (info_request_id) REFERENCES info_requests(id)"
+
+ execute "ALTER TABLE info_request_events ADD CONSTRAINT fk_info_request_events_info_request FOREIGN KEY (info_request_id) REFERENCES info_requests(id)"
+ execute "ALTER TABLE info_requests ADD CONSTRAINT fk_info_requests_user FOREIGN KEY (user_id) REFERENCES users(id)"
+ execute "ALTER TABLE info_requests ADD CONSTRAINT fk_info_requests_public_body FOREIGN KEY (public_body_id) REFERENCES public_bodies(id)"
+
+ execute "ALTER TABLE outgoing_messages ADD CONSTRAINT fk_outgoing_messages_info_request FOREIGN KEY (info_request_id) REFERENCES info_requests(id)"
+ execute "ALTER TABLE outgoing_messages ADD CONSTRAINT fk_incoming_message_followup_info_request FOREIGN KEY (incoming_message_followup_id) REFERENCES incoming_messages(id)"
+
+ execute "ALTER TABLE post_redirects ADD CONSTRAINT fk_post_redirects_user FOREIGN KEY (user_id) REFERENCES users(id)"
+
+ execute "ALTER TABLE public_body_versions ADD CONSTRAINT fk_public_body_versions_public_body FOREIGN KEY (public_body_id) REFERENCES public_bodies(id)"
+ end
+
+ def self.down
+ execute "ALTER TABLE incoming_messages DROP CONSTRAINT fk_incoming_messages_info_request"
+
+ execute "ALTER TABLE info_request_events DROP CONSTRAINT fk_info_request_events_info_request"
+
+ execute "ALTER TABLE info_requests DROP CONSTRAINT fk_info_requests_user"
+ execute "ALTER TABLE info_requests DROP CONSTRAINT fk_info_requests_public_body"
+
+ execute "ALTER TABLE outgoing_messages DROP CONSTRAINT fk_outgoing_messages_info_request"
+ execute "ALTER TABLE outgoing_messages DROP CONSTRAINT fk_incoming_message_followup_info_request"
+
+ execute "ALTER TABLE post_redirects DROP CONSTRAINT fk_post_redirects_user"
+
+ execute "ALTER TABLE public_body_versions DROP CONSTRAINT fk_public_body_versions_public_body"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 72e075da7..c01221291 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 31) do
+ActiveRecord::Schema.define(:version => 32) do
create_table "incoming_messages", :force => true do |t|
t.integer "info_request_id", :null => false
diff --git a/todo.txt b/todo.txt
index 6a648324c..db31dad6a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -56,18 +56,12 @@ And me
- add reply-to header to emails
Consider removing login links from notifications of new responses
+Things waiting clarification need link to help you do it.
+
Tidying
=======
-Add SQL foreign keys to database schema (THIS IS IMPORTANT, or things will screw up)
- execute 'ALTER TABLE researchers ADD CONSTRAINT fk_researchers_departments FOREIGN KEY ( department_id ) REFERENCES departments( id ) '
- http://wiki.rubyonrails.org/rails/pages/UsingMigrations link to:
- http://www.surfdewey.com/2.html
- http://www.redhillconsulting.com.au/rails_plugins.html#foreign_key_migrations
- http://rubyforge.org/projects/mig-constraints/
-
-Mark some requests as test requests
-
+Mark some requests as test requests
Later
=====