diff --git a/db/migrate/20171230220225_change_timestamps_to_non_null_on_tags.rb b/db/migrate/20171230220225_change_timestamps_to_non_null_on_tags.rb new file mode 100644 index 000000000..9caf220cb --- /dev/null +++ b/db/migrate/20171230220225_change_timestamps_to_non_null_on_tags.rb @@ -0,0 +1,8 @@ +class ChangeTimestampsToNonNullOnTags < ActiveRecord::Migration + def change + Post.without_timeout do + change_column_null :tags, :created_at, false + change_column_null :tags, :updated_at, false + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 236d92d8b..430544698 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3010,8 +3010,8 @@ CREATE TABLE tags ( category integer DEFAULT 0 NOT NULL, related_tags text, related_tags_updated_at timestamp without time zone, - created_at timestamp without time zone, - updated_at timestamp without time zone, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, is_locked boolean DEFAULT false NOT NULL ); @@ -7541,7 +7541,9 @@ INSERT INTO schema_migrations (version) VALUES ('20171106075030'); INSERT INTO schema_migrations (version) VALUES ('20171127195124'); -INSERT INTO schema_migrations (version) VALUES ('20171219001521'); - INSERT INTO schema_migrations (version) VALUES ('20171218213037'); +INSERT INTO schema_migrations (version) VALUES ('20171219001521'); + +INSERT INTO schema_migrations (version) VALUES ('20171230220225'); + diff --git a/script/fixes/052_fix_tag_timestamps.rb b/script/fixes/052_fix_tag_timestamps.rb new file mode 100755 index 000000000..348c4b1fb --- /dev/null +++ b/script/fixes/052_fix_tag_timestamps.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +CurrentUser.user = User.system +CurrentUser.ip_addr = "127.0.0.1" + +Tag.transaction do + Tag.without_timeout do + puts "Tag.where(updated_at: nil).count = #{Tag.where(updated_at: nil).count}" + puts "Tag.where(created_at: nil).count = #{Tag.where(created_at: nil).count}" + + Tag.where(updated_at: nil).update_all(updated_at: Time.zone.now) + Tag.where(created_at: nil).update_all("created_at = updated_at") + end +end