Merge migrations from before 0.6.0.0 to 0000_create_schema.rb

closes #7580
parent b040f857
......@@ -6,6 +6,7 @@
* Sort notifications by last interaction [#7568](https://github.com/diaspora/diaspora/pull/7568)
* Remove tiff support from photos [#7576](https://github.com/diaspora/diaspora/pull/7576)
* Remove reference from reshares when original post is deleted [#7578](https://github.com/diaspora/diaspora/pull/7578)
* Merge migrations from before 0.6.0.0 to CreateSchema [#7580](https://github.com/diaspora/diaspora/pull/7580)
## Bug fixes
* Fix displaying polls with long answers [#7579](https://github.com/diaspora/diaspora/pull/7579)
......
This diff is collapsed.
class AddFacebookIdToPost < ActiveRecord::Migration[4.2]
def change
add_column :posts, :facebook_id, :string
end
end
class FixDefaultImageUrlFromProfile < ActiveRecord::Migration[4.2]
def up
execute("UPDATE profiles SET image_url = REPLACE(image_url, 'images', 'assets'), image_url_small = REPLACE(image_url_small, 'images', 'assets'), image_url_medium = REPLACE(image_url_medium, 'images', 'assets') WHERE image_url LIKE '%images/user/default.png';")
end
def down
execute("UPDATE profiles SET image_url = REPLACE(image_url, 'assets', 'images'), image_url_small = REPLACE(image_url_small, 'assets', 'images'), image_url_medium = REPLACE(image_url_medium, 'assets', 'images') WHERE image_url LIKE '%assets/user/default.png';")
end
end
class AddTweetIdToPost < ActiveRecord::Migration[4.2]
def change
add_column :posts, :tweet_id, :string
add_index :posts, ['tweet_id'], :length => { "tweet_id" => 191 }
end
end
class AddOpenGraphCache < ActiveRecord::Migration[4.2]
def up
create_table :open_graph_caches do |t|
t.string :title
t.string :ob_type
t.string :image
t.string :url
t.text :description
end
change_table :posts do |t|
t.integer :open_graph_cache_id
end
end
def down
remove_column :posts, :open_graph_cache_id
drop_table :open_graph_caches
end
end
class RemoveLimitFromRootGuidInPosts < ActiveRecord::Migration[4.2]
def up
remove_index 'posts', :name => 'index_posts_on_root_guid'
remove_index 'posts', :name => 'index_posts_on_author_id_and_root_guid'
change_column :posts, :root_guid, :string
add_index 'posts', ["root_guid"], :name => 'index_posts_on_root_guid', length: {"root_guid"=>191}
add_index 'posts', ["author_id", "root_guid"], :name => 'index_posts_on_author_id_and_root_guid', length: {"root_guid"=>190}, :using => :btree, :unique => true
end
def down
change_column :posts, :root_guid, :string, limit: 30
end
end
class MigrateActivityStreamToStatusMessage < ActiveRecord::Migration[4.2]
class Post < ApplicationRecord; self.inheritance_column = false; end
def up
posts_stream_photos = Post.where(type: 'ActivityStreams::Photo')
posts_stream_photos.each do |p|
p.update_attributes({text: "#{p.text} ![](#{p.image_url})", type: "StatusMessage"}, without_protection: true)
end
end
def down
raise ActiveRecord::IrreversibleMigration, "Can't recover the deleted ActivityStreams::Photo"
end
end
class AddTumblrPostIdsToPosts < ActiveRecord::Migration[4.2]
def change
add_column :posts, :tumblr_ids, :text
end
end
class CreatePostReports < ActiveRecord::Migration[4.2]
def change
create_table :post_reports do |t|
t.integer :post_id, :null => false
t.string :user_id
t.boolean :reviewed, :default => false
t.text :text
t.timestamps
end
add_index :post_reports, :post_id
end
end
class CreateSimpleCaptchaData < ActiveRecord::Migration[4.2]
def self.up
create_table :simple_captcha_data do |t|
t.string :key, :limit => 40
t.string :value, :limit => 6
t.timestamps
end
add_index :simple_captcha_data, :key, :name => "idx_key"
end
def self.down
drop_table :simple_captcha_data
end
end
class AddPostTypeToPostReport < ActiveRecord::Migration[4.2]
def change
add_column :post_reports, :post_type, :string, :null => false, :after => :post_id, :default => 'post'
change_column_default :post_reports, :post_type, nil
end
end
class RenamePostReportToReport < ActiveRecord::Migration[4.2]
def self.up
rename_table :post_reports, :reports
end
def self.down
rename_table :reports, :post_reports
end
end
class DeviseAddLastseenableUser < ActiveRecord::Migration[4.2]
def self.up
add_column :users, :last_seen, :datetime
User.find_each do |user|
user.update_column(:last_seen, user.last_sign_in_at)
end
end
def self.down
remove_column :users, :last_seen
end
end
\ No newline at end of file
class CreatePolls < ActiveRecord::Migration[4.2]
def up
create_table :polls do |t|
t.string :question, :null => false
t.belongs_to :status_message, :null => false
t.boolean :status
t.string :guid
t.timestamps
end
add_index :polls, :status_message_id
create_table :poll_answers do |t|
t.string :answer, :null => false
t.belongs_to :poll, :null => false
t.string :guid
t.integer :vote_count, :default => 0
end
add_index :poll_answers, :poll_id
create_table :poll_participations do |t|
t.belongs_to :poll_answer, :null => false
t.belongs_to :author, :null => false
t.belongs_to :poll, :null => false
t.string :guid
t.text :author_signature
t.text :parent_author_signature
t.timestamps
end
add_index :poll_participations, :poll_id
end
def down
drop_table :polls
drop_table :poll_answers
drop_table :poll_participations
end
end
class RenamePostColumnsToItem < ActiveRecord::Migration[4.2]
def up
rename_column :reports, :post_id, :item_id
rename_column :reports, :post_type, :item_type
end
def down
rename_column :reports, :item_id, :post_id
rename_column :reports, :item_type, :post_type
end
end
class ChangeUserIdTypeToInteger < ActiveRecord::Migration[4.2]
def up
remove_column :reports, :user_id
add_column :reports, :user_id, :integer, :null => false, :default => 1
change_column_default :reports, :user_id, nil
end
def down
remove_column :reports, :user_id
add_column :reports, :user_id, :string
end
end
# This migration comes from acts_as_taggable_on_engine (originally 3)
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]
def self.up
add_column :tags, :taggings_count, :integer, default: 0
ActsAsTaggableOn::Tag.reset_column_information
ActsAsTaggableOn::Tag.find_each do |tag|
ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
end
end
def self.down
remove_column :tags, :taggings_count
end
end
class CreateChatContacts < ActiveRecord::Migration[4.2]
def up
create_table :chat_contacts do |t|
t.integer :user_id, null: false
## JID <= 3071 bytes http://tools.ietf.org/html/rfc6122
t.string :jid, null: false
t.string :name, limit: 255, null: true
t.string :ask, limit: 128, null: true
t.string :subscription, limit: 128, null: false
end
add_index :chat_contacts, [:user_id, :jid], unique: true, :length => {:jid => 190}
end
def down
drop_table :chat_contacts
end
end
class CreateChatFragments < ActiveRecord::Migration[4.2]
def up
create_table :chat_fragments do |t|
t.integer :user_id, null: false
t.string :root, limit: 256, null: false
t.string :namespace, limit: 256, null: false
t.text :xml, null: false
end
# That won't work due UTF-8 and the limit of 767 bytes
#add_index :chat_fragments, [:user_id, :root, :namespace], unique: true
add_index :chat_fragments, [:user_id], unique: true
end
def down
drop_table :chat_fragments
end
end
class AddCompletedAtToAccountDeletions < ActiveRecord::Migration[4.2]
def change
add_column :account_deletions, :completed_at, :datetime
end
end
class IncreaseSimpleCaptchaLimit < ActiveRecord::Migration[4.2]
def self.up
change_column :simple_captcha_data, :value, :string, :limit => 12
end
def self.down
change_column :simple_captcha_data, :value, :string, :limit => 6
end
end
class FixOpenGraphData < ActiveRecord::Migration[4.2]
def self.up
change_column :open_graph_caches, :url, :text
change_column :open_graph_caches, :image, :text
end
def self.down
change_column :open_graph_caches, :url, :string
change_column :open_graph_caches, :image, :string
end
end
class AddRemoveAfterToUsers < ActiveRecord::Migration[4.2]
def change
add_column :users, :remove_after, :datetime
end
end
class AddChatEnabledToAspects < ActiveRecord::Migration[4.2]
def self.up
add_column :aspects, :chat_enabled, :boolean, default: false
end
def self.down
remove_column :aspects, :chat_enabled
end
end
class CreateChatOfflineMessages < ActiveRecord::Migration[4.2]
def self.up
create_table :chat_offline_messages do |t|
t.string :from, :null => false
t.string :to, :null => false
t.text :message, :null => false
t.datetime "created_at", :null => false
end
end
def self.down
drop_table :chat_offline_messages
end
end
class DropOpenGraphCachesWithInvalidUrls < ActiveRecord::Migration[4.2]
def up
OpenGraphCache.where(url: 'http://').delete_all
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class PurgeOrphanConversations < ActiveRecord::Migration[4.2]
def up
Conversation.where(id: Conversation.joins("LEFT JOIN conversation_visibilities ON conversation_visibilities.conversation_id = conversations.id")
.group('conversations.id')
.having("COUNT(conversation_visibilities.id) = 0")
.pluck('conversations.id')
).delete_all
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class AddExportToUser < ActiveRecord::Migration[4.2]
def change
add_column :users, :export, :string
add_column :users, :exported_at, :datetime
add_column :users, :exporting, :boolean, default: false
end
end
class UserPrefStripExif < ActiveRecord::Migration[4.2]
def up
add_column :users, :strip_exif, :boolean, default: true
end
def down
remove_column :users, :strip_exif
end
end
class DisableMailForClosedAccount < ActiveRecord::Migration[4.2]
def up
User.joins(:person).where(people: {closed_account: true}).update_all(disable_mail: true)
end
def down
User.joins(:person).where(people: {closed_account: true}).update_all(disable_mail: false)
end
end
class AddPhotosExportToUser < ActiveRecord::Migration[4.2]
def up
add_column :users, :exported_photos_file, :string
add_column :users, :exported_photos_at, :datetime
add_column :users, :exporting_photos, :boolean, default: false
end
def down
remove_column :users, :exported_photos_file
remove_column :users, :exported_photos_at
remove_column :users, :exporting_photos
end
end
class RemoveDeletedAspectsFromAutoFollowBack < ActiveRecord::Migration[4.2]
def up
User.where.not(auto_follow_back_aspect_id: Aspect.select(:id))
.where(auto_follow_back: true)
.update_all(auto_follow_back: false, auto_follow_back_aspect_id: nil)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class FixWrongOnlySharing < ActiveRecord::Migration[4.2]
def up
Contact.where(sharing: true, receiving: false)
.where(id: AspectMembership.select(:contact_id))
.update_all(receiving: true)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class EnableColorThemes < ActiveRecord::Migration[4.2]
def up
add_column(:users, :color_theme, :string)
end
def down
remove_column(:users, :color_theme)
end
end
class CleanupDefaultAvatars < ActiveRecord::Migration[4.2]
def up
Profile.where("image_url LIKE ?", "%user/default%")
.update_all(image_url: nil, image_url_small: nil, image_url_medium: nil)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class FixPhotoPublicFlag < ActiveRecord::Migration[4.2]
def up
Photo.joins(:status_message).where(posts: {public: true}).update_all(public: true)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
# Inspired by https://github.com/nov/openid_connect_sample/blob/master/db/migrate/20110829023826_create_clients.rb
class CreateOAuthApplications < ActiveRecord::Migration[4.2]
def change
create_table :o_auth_applications do |t|
t.belongs_to :user, index: true
t.string :client_id, index: {unique: true, length: 191}
t.string :client_secret
t.string :client_name
t.text :redirect_uris
t.string :response_types
t.string :grant_types
t.string :application_type, default: "web"
t.string :contacts
t.string :logo_uri
t.string :client_uri
t.string :policy_uri
t.string :tos_uri
t.string :sector_identifier_uri
t.string :token_endpoint_auth_method
t.text :jwks
t.string :jwks_uri
t.boolean :ppid, default: false
t.timestamps null: false
end
add_foreign_key :o_auth_applications, :users
end
end
class AddPublicToProfiles < ActiveRecord::Migration[4.2]
def change
add_column :profiles, :public_details, :boolean, default: false
end
end
class CreateAuthorizations < ActiveRecord::Migration[4.2]
def change
create_table :authorizations do |t|
t.belongs_to :user, index: true
t.belongs_to :o_auth_application, index: true
t.string :refresh_token
t.string :code
t.string :redirect_uri
t.string :nonce
t.string :scopes
t.boolean :code_used, default: false
t.timestamps null: false
end
add_foreign_key :authorizations, :users
add_foreign_key :authorizations, :o_auth_applications
end
end
# Inspired by https://github.com/nov/openid_connect_sample/blob/master/db/migrate/20110829023837_create_access_tokens.rb
class CreateOAuthAccessTokens < ActiveRecord::Migration[4.2]
def change
create_table :o_auth_access_tokens do |t|
t.belongs_to :authorization, index: true
t.string :token, index: {unique: true, length: 191}
t.datetime :expires_at
t.timestamps null: false
end
add_foreign_key :o_auth_access_tokens, :authorizations
end
end
# Inspired by https://github.com/nov/openid_connect_sample/blob/master/db/migrate/20110829024010_create_id_tokens.rb
class CreateIdTokens < ActiveRecord::Migration[4.2]
def change
create_table :id_tokens do |t|
t.belongs_to :authorization, index: true
t.datetime :expires_at
t.string :nonce
t.timestamps null: false
end
add_foreign_key :id_tokens, :authorizations
end
end
class RemoveFavoritesFromPosts < ActiveRecord::Migration[4.2]
def self.up
remove_column :posts, :favorite
end
def self.down
add_column :posts, :favorite, :boolean, default: false
end
end
# Inspired by https://github.com/nov/openid_connect_sample/blob/master/db/migrate/20110829024140_create_pairwise_pseudonymous_identifiers.rb
class CreatePairwisePseudonymousIdentifiers < ActiveRecord::Migration[4.2]
def change
create_table :ppid do |t|
t.belongs_to :o_auth_application, index: true
t.belongs_to :user, index: true
t.string :guid, :string, limit: 32
t.string :identifier
end
add_foreign_key :ppid, :o_auth_applications
add_foreign_key :ppid, :users
end
end
class AddStatusToPods < ActiveRecord::Migration[4.2]
def change
add_column :pods, :status, :integer, default: 0
add_column :pods, :checked_at, :datetime, default: Time.zone.at(0)
add_column :pods, :offline_since, :datetime, default: nil
add_column :pods, :response_time, :integer, default: -1
add_column :pods, :software, :string, limit: 255
add_column :pods, :error, :string, limit: 255
add_index :pods, :status
add_index :pods, :checked_at
add_index :pods, :offline_since
end
end
class RemoveDuplicateAndEmptyPods < ActiveRecord::Migration[4.2]
def up
remove_dupes
remove_empty_or_nil
add_index :pods, :host, unique: true, length: 190 # =190*4 for utf8mb4
end
def down
remove_index :pods, :host
end
private
def remove_dupes
duplicates = Pod.group(:host).count.select {|_, v| v > 1 }.keys
ids = duplicates.flat_map {|pod| Pod.where(host: pod).order(created_at: :asc).pluck(:id).tap(&:shift) }
Pod.where(id: ids).destroy_all
end
def remove_empty_or_nil
Pod.where(host: [nil, ""]).destroy_all
end
end
class UpdateReportItemTypes < ActiveRecord::Migration[4.2]
def change
Report.all.each do |report|
report.update_attribute :item_type, report[:item_type].capitalize
end
end
end
class RemoveSignaturesFromRelayables < ActiveRecord::Migration[4.2]
def change
remove_column :comments, :parent_author_signature, :text
remove_column :poll_participations, :parent_author_signature, :text
remove_column :messages, :parent_author_signature, :text
remove_column :participations, :parent_author_signature, :text
remove_column :likes, :parent_author_signature, :text
end
end
class ExtendPods < ActiveRecord::Migration[4.2]
class Pod < ApplicationRecord
has_many :people
DEFAULT_PORTS = [URI::HTTP::DEFAULT_PORT, URI::HTTPS::DEFAULT_PORT]
def self.find_or_create_by(opts)
uri = URI.parse(opts.fetch(:url))
port = DEFAULT_PORTS.include?(uri.port) ? nil : uri.port
find_or_initialize_by(host: uri.host, port: port).tap do |pod|
pod.ssl ||= (uri.scheme == "https")
pod.save
end
end
def url
(ssl ? URI::HTTPS : URI::HTTP).build(host: host, port: port, path: "/")
end
end
class Person < ApplicationRecord
belongs_to :owner, class_name: "User"
belongs_to :pod
def url
owner_id.nil? ? pod.url.to_s : AppConfig.url_to("/")
end
end
class User < ApplicationRecord
has_one :person, inverse_of: :owner, foreign_key: :owner_id
end
def up
remove_index :pods, :host
# add port
add_column :pods, :port, :integer
add_index :pods, %i(host port), unique: true, length: {host: 190, port: nil}, using: :btree
add_column :pods, :blocked, :boolean, default: false
Pod.reset_column_information
# link people with pod
add_column :people, :pod_id, :integer
add_index :people, :url, length: 190