FIX: remove nullable dates post upgrade to Rails 4

This commit is contained in:
Sam 2014-08-27 15:19:25 +10:00
parent 53e60030bc
commit 414c6d191f
54 changed files with 148 additions and 106 deletions

View file

@ -29,8 +29,8 @@ end
# key :string(64) not null
# user_id :integer
# created_by_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -247,8 +247,8 @@ end
# description :text
# badge_type_id :integer not null
# grant_count :integer default(0), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# allow_title :boolean default(FALSE), not null
# multiple_grant :boolean default(FALSE), not null
# icon :string(255) default("fa-certificate")

View file

@ -25,6 +25,6 @@ end
# name :string(255) not null
# description :text
# position :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#

View file

@ -14,8 +14,8 @@ end
#
# id :integer not null, primary key
# name :string(255) not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -361,8 +361,8 @@ end
# color :string(6) default("AB9364"), not null
# topic_id :integer
# topic_count :integer default(0), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
# topics_year :integer default(0)
# topics_month :integer default(0)

View file

@ -10,8 +10,8 @@ end
# category_id :integer not null
# name :string(256) not null
# value :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -51,8 +51,8 @@ end
#
# category_id :integer not null
# topic_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# rank :integer default(0), not null
# id :integer not null, primary key
#

View file

@ -53,8 +53,8 @@ end
# id :integer not null, primary key
# category_id :integer
# user_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -15,7 +15,7 @@ end
# id :integer not null, primary key
# category_id :integer not null
# group_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# permission_type :integer default(1)
#

View file

@ -104,6 +104,6 @@ end
# enabled :boolean default(FALSE), not null
# versioned_id :integer
# version :integer default(1), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#

View file

@ -12,8 +12,8 @@ end
# name :string(255) not null
# hex :string(255) not null
# color_scheme_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -44,8 +44,8 @@ end
# user_id :integer not null
# draft_key :string(255) not null
# data :text not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# sequence :integer default(0), not null
#
# Indexes

View file

@ -37,8 +37,8 @@ end
# to_address :string(255) not null
# email_type :string(255) not null
# user_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# reply_key :string(32)
# post_id :integer
# topic_id :integer

View file

@ -79,8 +79,8 @@ end
# token :string(255) not null
# confirmed :boolean default(FALSE), not null
# expired :boolean default(FALSE), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -16,8 +16,8 @@ end
# gender :string(255)
# name :string(255)
# link :string(255)
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -10,8 +10,8 @@ end
# user_id :integer not null
# screen_name :string(255) not null
# github_user_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -17,8 +17,8 @@ end
# link :string(255)
# profile_link :string(255)
# picture :string(255)
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -295,8 +295,8 @@ end
#
# id :integer not null, primary key
# name :string(255) not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# automatic :boolean default(FALSE), not null
# user_count :integer default(0), not null
# alias_level :integer default(0)

View file

@ -10,8 +10,8 @@ end
# group_id :integer not null
# name :string(256) not null
# value :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -10,8 +10,8 @@ end
# id :integer not null, primary key
# group_id :integer not null
# user_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -115,7 +115,7 @@ end
# Table name: incoming_links
#
# id :integer not null, primary key
# created_at :datetime
# created_at :datetime not null
# user_id :integer
# ip_address :inet
# current_user_id :integer

View file

@ -198,8 +198,8 @@ end
# invited_by_id :integer not null
# user_id :integer
# redeemed_at :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# deleted_at :datetime
# deleted_by_id :integer
# invalidated_at :datetime

View file

@ -10,6 +10,6 @@ end
# id :integer not null, primary key
# group_id :integer
# invite_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#

View file

@ -143,8 +143,8 @@ end
# user_id :integer not null
# data :string(1000) not null
# read :boolean default(FALSE), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# topic_id :integer
# post_number :integer
# post_action_id :integer

View file

@ -13,8 +13,8 @@ end
# provider :string(255) not null
# email :string(255)
# name :string(255)
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -447,8 +447,8 @@ end
# user_id :integer not null
# post_action_type_id :integer not null
# deleted_at :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# deleted_by_id :integer
# related_post_id :integer
# staff_took_action :boolean default(FALSE), not null

View file

@ -49,8 +49,8 @@ end
# name_key :string(50) not null
# is_flag :boolean default(FALSE), not null
# icon :string(20)
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# position :integer default(0), not null
#

View file

@ -10,8 +10,8 @@ end
# post_id :integer not null
# name :string(256) not null
# value :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -14,8 +14,8 @@ end
# key :string(255)
# value :string(255)
# extra :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -11,8 +11,8 @@ end
#
# post_id :integer
# reply_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -117,8 +117,8 @@ end
# post_id :integer
# modifications :text
# number :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -66,8 +66,8 @@ end
# id :integer not null, primary key
# post_id :integer not null
# quoted_post_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -71,8 +71,8 @@ end
# action_type :integer not null
# match_count :integer default(0), not null
# last_match_at :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# ip_address :inet
#
# Indexes

View file

@ -92,8 +92,8 @@ end
# action_type :integer not null
# match_count :integer default(0), not null
# last_match_at :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -47,8 +47,8 @@ end
# action_type :integer not null
# match_count :integer default(0), not null
# last_match_at :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# ip_address :inet
#
# Indexes

View file

@ -10,8 +10,8 @@ end
# user_id :integer not null
# external_id :string(255) not null
# last_payload :text not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# external_username :string(255)
# external_email :string(255)
# external_name :string(255)

View file

@ -36,8 +36,8 @@ end
#
# content_type :string(255) not null, primary key
# content :text not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -207,8 +207,8 @@ end
# user_id :integer not null
# enabled :boolean not null
# key :string(255) not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# override_default_style :boolean default(FALSE), not null
# stylesheet_baked :text default(""), not null
# mobile_stylesheet :text

View file

@ -846,8 +846,8 @@ end
# id :integer not null, primary key
# title :string(255) not null
# last_posted_at :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# views :integer default(0), not null
# posts_count :integer default(0), not null
# user_id :integer

View file

@ -12,8 +12,8 @@ end
# id :integer not null, primary key
# user_id :integer not null
# topic_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -10,8 +10,8 @@ end
# topic_id :integer not null
# name :string(256) not null
# value :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -168,8 +168,8 @@ end
# post_id :integer not null
# embed_url :string(255) not null
# content_sha1 :string(40)
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -15,8 +15,8 @@ end
# id :integer not null, primary key
# topic_id :integer not null
# invite_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -220,8 +220,8 @@ end
# domain :string(100) not null
# internal :boolean default(FALSE), not null
# link_topic_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# reflection :boolean default(FALSE)
# clicks :integer default(0), not null
# link_post_id :integer

View file

@ -58,8 +58,8 @@ end
# id :integer not null, primary key
# topic_link_id :integer not null
# user_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# ip_address :inet not null
#
# Indexes

View file

@ -10,8 +10,8 @@ end
# user_id :integer not null
# screen_name :string(255) not null
# twitter_user_id :integer not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -135,8 +135,8 @@ end
# width :integer
# height :integer
# url :string(255) not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# sha1 :string(40)
# origin :string(1000)
#

View file

@ -765,8 +765,8 @@ end
#
# id :integer not null, primary key
# username :string(60) not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# name :string(255)
# seen_notification_id :integer default(0), not null
# last_posted_at :datetime
@ -805,8 +805,8 @@ end
# uploaded_avatar_id :integer
# email_always :boolean default(FALSE), not null
# mailing_list_mode :boolean default(FALSE), not null
# locale :string(10)
# primary_group_id :integer
# locale :string(10)
# registration_ip_address :inet
# last_redirected_to_top_at :datetime
# disable_jump_reply :boolean default(FALSE), not null

View file

@ -331,8 +331,8 @@ end
# target_post_id :integer
# target_user_id :integer
# acting_user_id :integer
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -48,8 +48,8 @@ end
# custom_upload_id :integer
# gravatar_upload_id :integer
# last_gravatar_download_attempt :datetime
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -10,8 +10,8 @@ end
# user_id :integer not null
# name :string(256) not null
# value :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View file

@ -105,8 +105,8 @@ end
# acting_user_id :integer
# target_user_id :integer
# details :text
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# context :string(255)
# ip_address :string(255)
# email :string(255)

View file

@ -13,8 +13,8 @@ end
# user_id :integer not null
# email :string(255) not null
# url :string(255) not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# active :boolean not null
#
# Indexes

View file

@ -0,0 +1,42 @@
class RemoveNullableDates < ActiveRecord::Migration
def up
# must drop so we can muck with the column
execute "DROP VIEW badge_posts"
# Rails 3 used to have nullable created_at and updated_at dates
# this is no longer the case in Rails 4, some old installs have
# this relic
# Fix it
sql = "select table_name, column_name from information_schema.columns
WHERE column_name IN ('created_at','updated_at') AND
table_schema = 'public' AND
is_nullable = 'YES' AND
is_updatable = 'YES' AND
data_type = 'timestamp without time zone'"
execute(sql).each do |row|
table = row["table_name"]
column = row["column_name"]
execute "UPDATE \"#{table}\" SET #{column} = CURRENT_TIMESTAMP WHERE #{column} IS NULL"
change_column table.to_sym, column.to_sym, :datetime, null: false
end
execute "CREATE VIEW badge_posts AS
SELECT p.*
FROM posts p
JOIN topics t ON t.id = p.topic_id
JOIN categories c ON c.id = t.category_id
WHERE c.allow_badges AND
p.deleted_at IS NULL AND
t.deleted_at IS NULL AND
NOT c.read_restricted AND
t.visible"
end
def down
# no need to revert
end
end