discourse/db/migrate/20200708051009_cap_bookmark_name_at_100_characters.rb
Martin Brennan 6be7a66ba7
FIX: Cap bookmark name at 100 chars and truncate existing names (#10189)
We have a couple of examples of enormous amounts of text being entered in the name column of bookmarks. This is not desirable...it is just meant to be a short note / reminder of why you bookmarked this.

This PR caps the column at 100 characters and truncates existing names in the database to 100 characters.
2020-07-08 17:19:01 +10:00

13 lines
349 B
Ruby

# frozen_string_literal: true
class CapBookmarkNameAt100Characters < ActiveRecord::Migration[6.0]
def up
DB.exec("UPDATE bookmarks SET name = LEFT(name, 100) WHERE name IS NOT NULL AND name <> LEFT(name, 100)")
change_column :bookmarks, :name, :string, limit: 100
end
def down
raise ActiveRecord::IrreversibleMigration
end
end