aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/032_addforeignkeys.rb32
-rw-r--r--db/schema.rb2
2 files changed, 33 insertions, 1 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