]> git.openstreetmap.org Git - rails.git/blobdiff - db/migrate/20120318201948_create_redactions.rb
Add redactions table and link it to history tables
[rails.git] / db / migrate / 20120318201948_create_redactions.rb
diff --git a/db/migrate/20120318201948_create_redactions.rb b/db/migrate/20120318201948_create_redactions.rb
new file mode 100644 (file)
index 0000000..bcb3929
--- /dev/null
@@ -0,0 +1,26 @@
+require 'migrate'
+
+class CreateRedactions < ActiveRecord::Migration
+  def up
+    create_table :redactions do |t|
+      t.string :title
+      t.text :description
+
+      t.timestamps
+    end
+
+    [:nodes, :ways, :relations].each do |tbl|
+      add_column tbl, :redaction_id, :integer, :null => true
+      add_foreign_key tbl, [:redaction_id], :redactions, [:id]
+    end
+  end
+
+  def down
+    [:nodes, :ways, :relations].each do |tbl|
+      remove_foreign_key tbl, [:redaction_id], :redactions, [:id]
+      remove_column tbl, :redaction_id
+    end
+    
+    drop_table :redactions
+  end
+end