commentaries: migrate columns to non-null.

This commit is contained in:
evazion 2017-06-13 15:23:38 -05:00
parent abb7117996
commit 1aafdc3928
3 changed files with 39 additions and 8 deletions

View File

@ -34,15 +34,15 @@ class ArtistCommentary < ActiveRecord::Base
end
if params[:original_present] == "yes"
q = q.where("(original_title is not null and original_title != '') or (original_description is not null and original_description != '')")
q = q.where("(original_title != '') or (original_description != '')")
elsif params[:original_present] == "no"
q = q.where("(original_title is null or original_title = '') and (original_description is null or original_description = '')")
q = q.where("(original_title = '') and (original_description = '')")
end
if params[:translated_present] == "yes"
q = q.where("(translated_title is not null and translated_title != '') or (translated_description is not null and translated_description != '')")
q = q.where("(translated_title != '') or (translated_description != '')")
elsif params[:translated_present] == "no"
q = q.where("(translated_title is null or translated_title = '') and (translated_description is null or translated_description = '')")
q = q.where("(translated_title = '') and (translated_description = '')")
end
if params[:post_tags_match].present?

View File

@ -0,0 +1,29 @@
class ChangeFieldsToNonNullOnArtistCommentaries < ActiveRecord::Migration
def up
ArtistCommentary.without_timeout do
change_column_null(:artist_commentaries, :original_title, false, "")
change_column_null(:artist_commentaries, :translated_title, false, "")
change_column_null(:artist_commentaries, :original_description, false, "")
change_column_null(:artist_commentaries, :translated_description, false, "")
change_column_default(:artist_commentaries, :original_title, "")
change_column_default(:artist_commentaries, :translated_title, "")
change_column_default(:artist_commentaries, :original_description, "")
change_column_default(:artist_commentaries, :translated_description, "")
end
end
def down
ArtistCommentary.without_timeout do
change_column_null(:artist_commentaries, :original_title, true)
change_column_null(:artist_commentaries, :translated_title, true)
change_column_null(:artist_commentaries, :original_description, true)
change_column_null(:artist_commentaries, :translated_description, true)
change_column_default(:artist_commentaries, :original_title, nil)
change_column_default(:artist_commentaries, :translated_title, nil)
change_column_default(:artist_commentaries, :original_description, nil)
change_column_default(:artist_commentaries, :translated_description, nil)
end
end
end

View File

@ -603,10 +603,10 @@ ALTER SEQUENCE api_keys_id_seq OWNED BY api_keys.id;
CREATE TABLE artist_commentaries (
id integer NOT NULL,
post_id integer NOT NULL,
original_title text,
original_description text,
translated_title text,
translated_description text,
original_title text DEFAULT ''::text NOT NULL,
original_description text DEFAULT ''::text NOT NULL,
translated_title text DEFAULT ''::text NOT NULL,
translated_description text DEFAULT ''::text NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
@ -7563,3 +7563,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170526183928');
INSERT INTO schema_migrations (version) VALUES ('20170608043651');
INSERT INTO schema_migrations (version) VALUES ('20170613200356');