From 7cd922d2a52cd5b55db47cb8bb114f387d93bdee Mon Sep 17 00:00:00 2001 From: Alexey Shiklomanov Date: Wed, 7 Feb 2018 14:47:23 -0600 Subject: [PATCH] MIGRATION: Relax constraints on citations table - Change `citations.title` and `citations.journal` columns to unlimited variable width `text` type. - Remove format constraint on `citations.pg`. --- db/migrate/20180206152600_relax_citations.rb | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 db/migrate/20180206152600_relax_citations.rb diff --git a/db/migrate/20180206152600_relax_citations.rb b/db/migrate/20180206152600_relax_citations.rb new file mode 100644 index 000000000..0468af612 --- /dev/null +++ b/db/migrate/20180206152600_relax_citations.rb @@ -0,0 +1,25 @@ +class RelaxCitations < ActiveRecord::Migration + def self.up + # Use longer "text" field + change_column :citations, :title, :text + change_column :citations, :journal, :text + add_column :citations, :notes, :text + + # This constraint is draconian and totally unnecessary. + # Other metadata should be plenty sufficient without well-formed page number + execute %q{ + ALTER TABLE citations + DROP CONSTRAINT well_formed_citation_page_spec; + } + end + + def self.down + change_column :citations, :title, :string + change_column :citations, :journal, :string + remove_column :citations, :notes, :text + execute %q{ + ALTER TABLE citations + ADD CONSTRAINT well_formed_citation_page_spec CHECK (pg ~ '^([1-9]\d*(\u2013[1-9]\d*)?)?$'); + } + end +end