]> git.openstreetmap.org Git - rails.git/blobdiff - db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb
Add Spanish attribution to copyright page
[rails.git] / db / migrate / 20161002153425_add_join_table_between_users_and_diary_entries.rb
index 4c41f725f4095496702984955bb940eff48d26e3..088b9d28bb3b718c8e46ebc4666331a5d95207b0 100644 (file)
@@ -1,12 +1,19 @@
-class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration
-  def change
+require "migrate"
+
+class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration[5.0]
+  def self.up
     create_table :diary_entry_subscriptions, :id => false do |t|
       t.column :user_id, :bigint, :null => false
       t.column :diary_entry_id, :bigint, :null => false
     end
 
-    add_index :diary_entry_subscriptions, [:user_id, :diary_entry_id], :unique => true, :name => "index_diary_subscriptions_on_user_id_and_diary_entry_id"
+    add_primary_key :diary_entry_subscriptions, [:user_id, :diary_entry_id]
     add_index :diary_entry_subscriptions, [:diary_entry_id]
+    add_foreign_key :diary_entry_subscriptions, :diary_entries, :name => "diary_entry_subscriptions_diary_entry_id_fkey"
+    add_foreign_key :diary_entry_subscriptions, :users, :name => "diary_entry_subscriptions_user_id_fkey"
   end
 
+  def self.down
+    drop_table :diary_entry_subscriptions
+  end
 end