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 # key :string(64) not null
# user_id :integer # user_id :integer
# created_by_id :integer # created_by_id :integer
# created_at :datetime # created_at :datetime not null
# updated_at :datetime # updated_at :datetime not null
# #
# Indexes # Indexes
# #

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,8 +13,8 @@ end
# user_id :integer not null # user_id :integer not null
# email :string(255) not null # email :string(255) not null
# url :string(255) not null # url :string(255) not null
# created_at :datetime # created_at :datetime not null
# updated_at :datetime # updated_at :datetime not null
# active :boolean not null # active :boolean not null
# #
# Indexes # 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