[openstreetmap/openstreetmap-website] Added a validation to the Redaction model for the title. (#2034)

Andy Allan notifications at github.com
Thu Nov 29 18:50:56 UTC 2018


gravitystorm requested changes on this pull request.



> @@ -0,0 +1,19 @@
+class NameUnnamedRedactions < ActiveRecord::Migration[5.0]
+  def self.up
+  	# after titles are fixed we change the column so to not be null
+    change_column_null "redactions", "title", false

I think you might need to fill in the titles first, and then change the column constraint afterwards.

> @@ -0,0 +1,19 @@
+class NameUnnamedRedactions < ActiveRecord::Migration[5.0]

The migration file should use a timestamp in the filename, see recent migrations that start with db/migrate/2018[...]

> @@ -0,0 +1,19 @@
+class NameUnnamedRedactions < ActiveRecord::Migration[5.0]
+  def self.up
+  	# after titles are fixed we change the column so to not be null
+    change_column_null "redactions", "title", false
+    # gets each redaction
+    # sets redaction title equal to a string of the id if there is no title
+    Redaction.find_each do |redaction|
+      if redaction.title.empty?
+        redaction.title = redaction.id.to_s

There's no need to use `.to_s` here, rails will take care of the conversion for you.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/2034#pullrequestreview-179956058
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20181129/09e84241/attachment-0001.html>


More information about the rails-dev mailing list