Merge migrations from before 0.6.0.0 to 0000_create_schema.rb

closes #7580
This commit is contained in:
Benjamin Neff 2017-08-25 02:01:55 +02:00
parent b040f85790
commit e08440d7ba
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
62 changed files with 306 additions and 1231 deletions

View file

@ -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)

View file

@ -2,8 +2,9 @@ class CreateSchema < ActiveRecord::Migration[4.2]
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength, Layout/ExtraSpacing
def up
create_table :account_deletions do |t|
t.string :diaspora_handle
t.integer :person_id
t.string :diaspora_handle
t.integer :person_id
t.datetime :completed_at
end
create_table :aspect_memberships do |t|
@ -14,54 +15,103 @@ class CreateSchema < ActiveRecord::Migration[4.2]
end
add_index :aspect_memberships, %i[aspect_id contact_id], name: :index_aspect_memberships_on_aspect_id_and_contact_id, unique: true
add_index :aspect_memberships, [:aspect_id], name: :index_aspect_memberships_on_aspect_id
add_index :aspect_memberships, [:contact_id], name: :index_aspect_memberships_on_contact_id
add_index :aspect_memberships, :aspect_id, name: :index_aspect_memberships_on_aspect_id
add_index :aspect_memberships, :contact_id, name: :index_aspect_memberships_on_contact_id
create_table :aspect_visibilities do |t|
t.integer :shareable_id, null: false
t.integer :aspect_id, null: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.string :shareable_type, default: "Post", null: false
end
add_index :aspect_visibilities, [:aspect_id], name: :index_aspect_visibilities_on_aspect_id
add_index :aspect_visibilities, %i[shareable_id shareable_type aspect_id], name: :shareable_and_aspect_id, length: {shareable_type: 189}, using: :btree
add_index :aspect_visibilities, %i[shareable_id shareable_type], name: :index_aspect_visibilities_on_shareable_id_and_shareable_type, length: {shareable_type: 190}, using: :btree
add_index :aspect_visibilities, :aspect_id, name: :index_aspect_visibilities_on_aspect_id
add_index :aspect_visibilities, %i[shareable_id shareable_type aspect_id], name: :shareable_and_aspect_id, length: {shareable_type: 189}
add_index :aspect_visibilities, %i[shareable_id shareable_type], name: :index_aspect_visibilities_on_shareable_id_and_shareable_type, length: {shareable_type: 190}
create_table :aspects do |t|
t.string :name, null: false
t.integer :user_id, null: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.boolean :contacts_visible, default: true, null: false
t.string :name, null: false
t.integer :user_id, null: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.boolean :contacts_visible, default: true, null: false
t.integer :order_id
t.boolean :chat_enabled, default: false
end
add_index :aspects, %i[user_id contacts_visible], name: :index_aspects_on_user_id_and_contacts_visible
add_index :aspects, [:user_id], name: :index_aspects_on_user_id
add_index :aspects, :user_id, name: :index_aspects_on_user_id
create_table :authorizations do |t|
t.integer :user_id
t.integer :o_auth_application_id
t.string :refresh_token
t.string :code
t.string :redirect_uri
t.string :nonce
t.string :scopes
t.boolean :code_used, default: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
end
add_index :authorizations, :user_id, name: :index_authorizations_on_user_id
add_index :authorizations, :o_auth_application_id, name: :index_authorizations_on_o_auth_application_id
create_table :blocks do |t|
t.integer :user_id
t.integer :person_id
end
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, %i[user_id jid], name: :index_chat_contacts_on_user_id_and_jid, length: {jid: 190}, unique: true
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
add_index :chat_fragments, :user_id, name: :index_chat_fragments_on_user_id, unique: true
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
create_table :comment_signatures, id: false do |t|
t.integer :comment_id, null: false
t.text :author_signature, null: false
t.integer :signature_order_id, null: false
t.text :additional_data
end
add_index :comment_signatures, :comment_id, name: :index_comment_signatures_on_comment_id, unique: true
create_table :comments do |t|
t.text :text, null: false
t.integer :commentable_id, null: false
t.integer :author_id, null: false
t.string :guid, null: false
t.text :author_signature
t.text :parent_author_signature
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.integer :likes_count, default: 0, null: false
t.string :commentable_type, limit: 60, default: "Post", null: false
end
add_index :comments, [:author_id], name: :index_comments_on_person_id
add_index :comments, :author_id, name: :index_comments_on_person_id
add_index :comments, %i[commentable_id commentable_type], name: :index_comments_on_commentable_id_and_commentable_type
add_index :comments, [:guid], name: :index_comments_on_guid, length: {guid: 191}, using: :btree, unique: true
add_index :comments, :guid, name: :index_comments_on_guid, length: {guid: 191}, unique: true
create_table :contacts do |t|
t.integer :user_id, null: false
@ -72,7 +122,7 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.boolean :receiving, default: false, null: false
end
add_index :contacts, [:person_id], name: :index_contacts_on_person_id
add_index :contacts, :person_id, name: :index_contacts_on_person_id
add_index :contacts, %i[user_id person_id], name: :index_contacts_on_user_id_and_person_id, unique: true
create_table :conversation_visibilities do |t|
@ -84,8 +134,8 @@ class CreateSchema < ActiveRecord::Migration[4.2]
end
add_index :conversation_visibilities, %i[conversation_id person_id], name: :index_conversation_visibilities_usefully, unique: true
add_index :conversation_visibilities, [:conversation_id], name: :index_conversation_visibilities_on_conversation_id
add_index :conversation_visibilities, [:person_id], name: :index_conversation_visibilities_on_person_id
add_index :conversation_visibilities, :conversation_id, name: :index_conversation_visibilities_on_conversation_id
add_index :conversation_visibilities, :person_id, name: :index_conversation_visibilities_on_person_id
create_table :conversations do |t|
t.string :subject
@ -95,7 +145,8 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.datetime :updated_at, null: false
end
add_index :conversations, [:author_id], name: :conversations_author_id_fk
add_index :conversations, :guid, name: :index_conversations_on_guid, length: 191, unique: true
add_index :conversations, :author_id, name: :conversations_author_id_fk
create_table :invitation_codes do |t|
t.string :token
@ -105,39 +156,29 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.datetime :updated_at, null: false
end
create_table :invitations do |t|
t.text :message
t.integer :sender_id
t.integer :recipient_id
t.integer :aspect_id
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.string :service
t.string :identifier
t.boolean :admin, default: false
t.string :language, default: "en"
create_table :like_signatures, id: false do |t|
t.integer :like_id, null: false
t.text :author_signature, null: false
t.integer :signature_order_id, null: false
t.text :additional_data
end
add_index :invitations, [:aspect_id], name: :index_invitations_on_aspect_id
add_index :invitations, [:recipient_id], name: :index_invitations_on_recipient_id
add_index :invitations, [:sender_id], name: :index_invitations_on_sender_id
add_index :like_signatures, :like_id, name: :index_like_signatures_on_like_id, unique: true
create_table :likes do |t|
t.boolean :positive, default: true
t.integer :target_id
t.integer :author_id
t.string :guid
t.text :author_signature
t.text :parent_author_signature
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.string :target_type, limit: 60, null: false
end
add_index :likes, [:author_id], name: :likes_author_id_fk
add_index :likes, [:guid], name: :index_likes_on_guid, length: {guid: 191}, using: :btree, unique: true
add_index :likes, :author_id, name: :likes_author_id_fk
add_index :likes, :guid, name: :index_likes_on_guid, length: {guid: 191}, unique: true
add_index :likes, %i[target_id author_id target_type], name: :index_likes_on_target_id_and_author_id_and_target_type, unique: true
add_index :likes, [:target_id], name: :index_likes_on_post_id
add_index :likes, :target_id, name: :index_likes_on_post_id
create_table :locations do |t|
t.string :address
@ -154,8 +195,8 @@ class CreateSchema < ActiveRecord::Migration[4.2]
end
add_index :mentions, %i[person_id post_id], name: :index_mentions_on_person_id_and_post_id, unique: true
add_index :mentions, [:person_id], name: :index_mentions_on_person_id
add_index :mentions, [:post_id], name: :index_mentions_on_post_id
add_index :mentions, :person_id, name: :index_mentions_on_person_id
add_index :mentions, :post_id, name: :index_mentions_on_post_id
create_table :messages do |t|
t.integer :conversation_id, null: false
@ -165,11 +206,11 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.text :author_signature
t.text :parent_author_signature
end
add_index :messages, [:author_id], name: :index_messages_on_author_id
add_index :messages, [:conversation_id], name: :messages_conversation_id_fk
add_index :messages, :guid, name: :index_messages_on_guid, length: 191, unique: true
add_index :messages, :author_id, name: :index_messages_on_author_id
add_index :messages, :conversation_id, name: :messages_conversation_id_fk
create_table :notification_actors do |t|
t.integer :notification_id
@ -179,8 +220,8 @@ class CreateSchema < ActiveRecord::Migration[4.2]
end
add_index :notification_actors, %i[notification_id person_id], name: :index_notification_actors_on_notification_id_and_person_id, unique: true
add_index :notification_actors, [:notification_id], name: :index_notification_actors_on_notification_id
add_index :notification_actors, [:person_id], name: :index_notification_actors_on_person_id
add_index :notification_actors, :notification_id, name: :index_notification_actors_on_notification_id
add_index :notification_actors, :person_id, name: :index_notification_actors_on_person_id
create_table :notifications do |t|
t.string :target_type
@ -192,34 +233,78 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.string :type
end
add_index :notifications, [:recipient_id], name: :index_notifications_on_recipient_id
add_index :notifications, [:target_id], name: :index_notifications_on_target_id
add_index :notifications, %i[target_type target_id], name: :index_notifications_on_target_type_and_target_id, length: {target_type: 190}, using: :btree
add_index :notifications, :recipient_id, name: :index_notifications_on_recipient_id
add_index :notifications, :target_id, name: :index_notifications_on_target_id
add_index :notifications, %i[target_type target_id], name: :index_notifications_on_target_type_and_target_id, length: {target_type: 190}
create_table :o_auth_access_tokens do |t|
t.integer :authorization_id
t.string :token
t.datetime :expires_at
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
end
add_index :o_auth_access_tokens, :authorization_id, name: :index_o_auth_access_tokens_on_authorization_id
add_index :o_auth_access_tokens, :token, name: :index_o_auth_access_tokens_on_token, length: {token: 191}, unique: true
create_table :o_auth_applications do |t|
t.integer :user_id
t.string :client_id
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.datetime :created_at, null: false
t.datetime :updated_at, null: false
end
add_index :o_auth_applications, :user_id, name: :index_o_auth_applications_on_user_id
add_index :o_auth_applications, :client_id, name: :index_o_auth_applications_on_client_id, length: {client_id: 191}, unique: true
create_table :open_graph_caches do |t|
t.string :title
t.string :ob_type
t.text :image
t.text :url
t.text :description
end
create_table :o_embed_caches do |t|
t.string :url, limit: 1024, null: false
t.text :data, null: false
end
add_index :o_embed_caches, [:url], name: :index_o_embed_caches_on_url, length: {url: 191}, using: :btree
add_index :o_embed_caches, :url, name: :index_o_embed_caches_on_url, length: {url: 191}
create_table :participations do |t|
t.string :guid
t.integer :target_id
t.string :target_type, limit: 60, null: false
t.integer :author_id
t.text :author_signature
t.text :parent_author_signature
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.integer :count, default: 1, null: false
end
add_index :participations, [:guid], name: :index_participations_on_guid, length: {guid: 191}, using: :btree
add_index :participations, %i[target_id target_type author_id], name: :index_participations_on_target_id_and_target_type_and_author_id
add_index :participations, :guid, name: :index_participations_on_guid, length: {guid: 191}
add_index :participations, :author_id, name: :index_participations_on_author_id
add_index :participations, %i[target_id target_type author_id], name: :index_participations_on_target_id_and_target_type_and_author_id, unique: true
create_table :people do |t|
t.string :guid, null: false
t.text :url, null: false
t.string :diaspora_handle, null: false
t.text :serialized_public_key, null: false
t.integer :owner_id
@ -227,17 +312,16 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.datetime :updated_at, null: false
t.boolean :closed_account, default: false
t.integer :fetch_status, default: 0
t.integer :pod_id
end
add_index :people, [:diaspora_handle], name: :index_people_on_diaspora_handle, unique: true, length: {diaspora_handle: 191}
add_index :people, [:guid], name: :index_people_on_guid, length: {guid: 191}, using: :btree, unique: true
add_index :people, [:owner_id], name: :index_people_on_owner_id, unique: true
add_index :people, :diaspora_handle, name: :index_people_on_diaspora_handle, unique: true, length: {diaspora_handle: 191}
add_index :people, :guid, name: :index_people_on_guid, length: {guid: 191}, unique: true
add_index :people, :owner_id, name: :index_people_on_owner_id, unique: true
create_table :photos do |t|
t.integer :tmp_old_id
t.integer :author_id, null: false
t.boolean :public, default: false, null: false
t.string :diaspora_handle
t.string :guid, null: false
t.boolean :pending, default: false, null: false
t.text :text
@ -254,56 +338,109 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.integer :width
end
add_index :photos, [:status_message_guid], name: :index_photos_on_status_message_guid, length: {status_message_guid: 191}, using: :btree
add_index :photos, :guid, name: :index_photos_on_guid, length: 191, unique: true
add_index :photos, :status_message_guid, name: :index_photos_on_status_message_guid, length: {status_message_guid: 191}
create_table :pods do |t|
t.string :host
t.boolean :ssl
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.integer :status, default: 0
t.datetime :checked_at, default: Time.zone.at(0)
t.datetime :offline_since, default: nil
t.integer :response_time, default: -1
t.string :software
t.string :error
t.integer :port
t.boolean :blocked, default: false
end
add_index :pods, :status, name: :index_pods_on_status
add_index :pods, :checked_at, name: :index_pods_on_checked_at
add_index :pods, :offline_since, name: :index_pods_on_offline_since
add_index :pods, %i[host port], name: :index_pods_on_host_and_port, length: {host: 190}, unique: true
create_table :poll_answers do |t|
t.string :answer, null: false
t.integer :poll_id, null: false
t.string :guid
t.integer :vote_count, default: 0
end
add_index :poll_answers, :guid, name: :index_poll_answers_on_guid, length: 191, unique: true
add_index :poll_answers, :poll_id, name: :index_poll_answers_on_poll_id
create_table :poll_participation_signatures, id: false do |t|
t.integer :poll_participation_id, null: false
t.text :author_signature, null: false
t.integer :signature_order_id, null: false
t.text :additional_data
end
add_index :poll_participation_signatures, :poll_participation_id, name: :index_poll_participation_signatures_on_poll_participation_id, unique: true
create_table :poll_participations do |t|
t.integer :poll_answer_id, null: false
t.integer :author_id, null: false
t.integer :poll_id, null: false
t.string :guid
t.timestamps
end
add_index :poll_participations, :guid, name: :index_poll_participations_on_guid, length: 191, unique: true
add_index :poll_participations, :poll_id, name: :index_poll_participations_on_poll_id
create_table :polls do |t|
t.string :question, null: false
t.integer :status_message_id, null: false
t.boolean :status
t.string :guid
t.timestamps
end
add_index :polls, :guid, name: :index_polls_on_guid, length: 191, unique: true
add_index :polls, :status_message_id, name: :index_polls_on_status_message_id
create_table :posts do |t|
t.integer :author_id, null: false
t.boolean :public, default: false, null: false
t.string :diaspora_handle
t.string :guid, null: false
t.boolean :pending, default: false, null: false
t.string :type, limit: 40, null: false
t.text :text
t.text :remote_photo_path
t.string :remote_photo_name
t.string :random_string
t.string :processed_image
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.string :unprocessed_image
t.string :object_url
t.string :image_url
t.integer :image_height
t.integer :image_width
t.string :provider_display_name
t.string :actor_url
t.string :objectId
t.string :root_guid, limit: 30
t.string :status_message_guid
t.string :root_guid
t.integer :likes_count, default: 0
t.integer :comments_count, default: 0
t.integer :o_embed_cache_id
t.integer :reshares_count, default: 0
t.datetime :interacted_at
t.string :frame_name
t.boolean :favorite, default: false
t.string :facebook_id
t.string :tweet_id
t.integer :open_graph_cache_id
t.text :tumblr_ids
end
add_index :posts, %i[author_id root_guid], name: :index_posts_on_author_id_and_root_guid, length: {root_guid: 30}, using: :btree, unique: true
add_index :posts, [:author_id], name: :index_posts_on_person_id
add_index :posts, [:guid], name: :index_posts_on_guid, length: {guid: 191}, using: :btree, unique: true
add_index :posts, %i[id type], name: :index_posts_on_id_and_type
add_index :posts, %i[author_id root_guid], name: :index_posts_on_author_id_and_root_guid, length: {root_guid: 190}, unique: true
add_index :posts, :author_id, name: :index_posts_on_person_id
add_index :posts, :guid, name: :index_posts_on_guid, length: {guid: 191}, unique: true
add_index :posts, %i[id type created_at], name: :index_posts_on_id_and_type_and_created_at
add_index :posts, [:root_guid], name: :index_posts_on_root_guid, length: {root_guid: 30}
add_index :posts, %i[status_message_guid pending], name: :index_posts_on_status_message_guid_and_pending, length: {status_message_guid: 190}, using: :btree
add_index :posts, [:status_message_guid], name: :index_posts_on_status_message_guid, length: {status_message_guid: 191}, using: :btree
add_index :posts, %i[type pending id], name: :index_posts_on_type_and_pending_and_id
add_index :posts, :root_guid, name: :index_posts_on_root_guid, length: {root_guid: 191}
add_index :posts, :tweet_id, name: :index_posts_on_tweet_id, length: {tweet_id: 191}
create_table :ppid do |t|
t.integer :o_auth_application_id
t.integer :user_id
t.string :guid, limit: 32
t.string :string, limit: 32
t.string :identifier
end
add_index :ppid, :o_auth_application_id, name: :index_ppid_on_o_auth_application_id
add_index :ppid, :user_id, name: :index_ppid_on_user_id
create_table :profiles do |t|
t.string :diaspora_handle
@ -322,11 +459,12 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.string :location
t.string :full_name, limit: 70
t.boolean :nsfw, default: false
t.boolean :public_details, default: false
end
add_index :profiles, %i[full_name searchable], name: :index_profiles_on_full_name_and_searchable
add_index :profiles, [:full_name], name: :index_profiles_on_full_name
add_index :profiles, [:person_id], name: :index_profiles_on_person_id
add_index :profiles, :full_name, name: :index_profiles_on_full_name
add_index :profiles, :person_id, name: :index_profiles_on_person_id
create_table :rails_admin_histories do |t|
t.text :message
@ -341,6 +479,17 @@ class CreateSchema < ActiveRecord::Migration[4.2]
add_index :rails_admin_histories, %i[item table month year], name: :index_rails_admin_histories, length: {table: 188}
create_table :reports do |t|
t.integer :item_id, null: false
t.string :item_type, null: false
t.boolean :reviewed, default: false
t.text :text
t.timestamps
t.integer :user_id, null: false
end
add_index :reports, :item_id, name: :index_reports_on_item_id
create_table :roles do |t|
t.integer :person_id
t.string :name
@ -359,22 +508,34 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.datetime :updated_at, null: false
end
add_index :services, %i[type uid], name: :index_services_on_type_and_uid, length: {type: 64, uid: 127}, using: :btree
add_index :services, [:user_id], name: :index_services_on_user_id
add_index :services, %i[type uid], name: :index_services_on_type_and_uid, length: {type: 64, uid: 127}
add_index :services, :user_id, name: :index_services_on_user_id
create_table :share_visibilities do |t|
t.integer :shareable_id, null: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.boolean :hidden, default: false, null: false
t.integer :contact_id, null: false
t.string :shareable_type, limit: 60, default: "Post", null: false
t.integer :user_id, null: false
end
add_index :share_visibilities, [:contact_id], name: :index_post_visibilities_on_contact_id
add_index :share_visibilities, %i[shareable_id shareable_type contact_id], name: :shareable_and_contact_id
add_index :share_visibilities, %i[shareable_id shareable_type hidden contact_id], name: :shareable_and_hidden_and_contact_id
add_index :share_visibilities, [:shareable_id], name: :index_post_visibilities_on_post_id
add_index :share_visibilities, :user_id, name: :index_share_visibilities_on_user_id
add_index :share_visibilities, %i[shareable_id shareable_type user_id], name: :shareable_and_user_id
add_index :share_visibilities, %i[shareable_id shareable_type hidden user_id], name: :shareable_and_hidden_and_user_id
add_index :share_visibilities, :shareable_id, name: :index_post_visibilities_on_post_id
create_table :signature_orders do |t|
t.string :order, null: false
end
add_index :signature_orders, :order, name: :index_signature_orders_on_order, length: 191, unique: true
create_table :simple_captcha_data do |t|
t.string :key, limit: 40
t.string :value, limit: 12
t.timestamps
end
add_index :simple_captcha_data, :key, name: :idx_key
create_table :tag_followings do |t|
t.integer :tag_id, null: false
@ -384,8 +545,8 @@ class CreateSchema < ActiveRecord::Migration[4.2]
end
add_index :tag_followings, %i[tag_id user_id], name: :index_tag_followings_on_tag_id_and_user_id, unique: true
add_index :tag_followings, [:tag_id], name: :index_tag_followings_on_tag_id
add_index :tag_followings, [:user_id], name: :index_tag_followings_on_user_id
add_index :tag_followings, :tag_id, name: :index_tag_followings_on_tag_id
add_index :tag_followings, :user_id, name: :index_tag_followings_on_user_id
create_table :taggings do |t|
t.integer :tag_id
@ -397,16 +558,17 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.datetime :created_at
end
add_index :taggings, [:created_at], name: :index_taggings_on_created_at
add_index :taggings, [:tag_id], name: :index_taggings_on_tag_id
add_index :taggings, %i[taggable_id taggable_type context], name: :index_taggings_on_taggable_id_and_taggable_type_and_context, length: {taggable_type: 95, context: 95}, using: :btree
add_index :taggings, :created_at, name: :index_taggings_on_created_at
add_index :taggings, :tag_id, name: :index_taggings_on_tag_id
add_index :taggings, %i[taggable_id taggable_type context], name: :index_taggings_on_taggable_id_and_taggable_type_and_context, length: {taggable_type: 95, context: 95}
add_index :taggings, %i[taggable_id taggable_type tag_id], name: :index_taggings_uniquely, unique: true
create_table :tags do |t|
t.string :name
t.string :name
t.integer :taggings_count, default: 0
end
add_index :tags, [:name], name: :index_tags_on_name, unique: true, length: {name: 191}
add_index :tags, :name, name: :index_tags_on_name, unique: true, length: {name: 191}
create_table :user_preferences do |t|
t.string :email_type
@ -416,15 +578,13 @@ class CreateSchema < ActiveRecord::Migration[4.2]
end
create_table :users do |t|
t.string :username
t.string :username, null: false
t.text :serialized_private_key
t.boolean :getting_started, default: true, null: false
t.boolean :disable_mail, default: false, null: false
t.string :language
t.string :email, default: "", null: false
t.string :encrypted_password, default: "", null: false
t.string :invitation_token, limit: 60
t.datetime :invitation_sent_at
t.string :reset_password_token
t.datetime :remember_created_at
t.integer :sign_in_count, default: 0
@ -434,11 +594,7 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.string :last_sign_in_ip
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.string :invitation_service, limit: 127
t.string :invitation_identifier, limit: 127
t.integer :invitation_limit
t.integer :invited_by_id
t.string :invited_by_type
t.string :authentication_token, limit: 30
t.string :unconfirmed_email
t.string :confirm_email_token, limit: 30
@ -448,19 +604,33 @@ class CreateSchema < ActiveRecord::Migration[4.2]
t.integer :auto_follow_back_aspect_id
t.text :hidden_shareables
t.datetime :reset_password_sent_at
t.datetime :last_seen
t.datetime :remove_after
t.string :export
t.datetime :exported_at
t.boolean :exporting, default: false
t.boolean :strip_exif, default: true
t.string :exported_photos_file
t.datetime :exported_photos_at
t.boolean :exporting_photos, default: false
t.string :color_theme
end
add_index :users, [:authentication_token], name: :index_users_on_authentication_token, unique: true
add_index :users, [:email], name: :index_users_on_email, length: {email: 191}
add_index :users, %i[invitation_service invitation_identifier], name: :index_users_on_invitation_service_and_invitation_identifier, length: {invitation_service: 64, invitation_identifier: 127}, using: :btree, unique: true
add_index :users, [:invitation_token], name: :index_users_on_invitation_token
add_index :users, [:username], name: :index_users_on_username, length: {username: 191}, using: :btree, unique: true
add_index :users, :authentication_token, name: :index_users_on_authentication_token, unique: true
add_index :users, :username, name: :index_users_on_username, length: {username: 191}, unique: true
add_index :users, :email, name: :index_users_on_email, length: {email: 191}, unique: true
add_foreign_key :aspect_memberships, :aspects, name: :aspect_memberships_aspect_id_fk, on_delete: :cascade
add_foreign_key :aspect_memberships, :contacts, name: :aspect_memberships_contact_id_fk, on_delete: :cascade
add_foreign_key :aspect_visibilities, :aspects, name: :aspect_visibilities_aspect_id_fk, on_delete: :cascade
add_foreign_key :authorizations, :users
add_foreign_key :authorizations, :o_auth_applications
add_foreign_key :comment_signatures, :comments, name: :comment_signatures_comment_id_fk, on_delete: :cascade
add_foreign_key :comment_signatures, :signature_orders, name: :comment_signatures_signature_orders_id_fk
add_foreign_key :comments, :people, name: :comments_author_id_fk, column: :author_id, on_delete: :cascade
add_foreign_key :contacts, :people, name: :contacts_person_id_fk, on_delete: :cascade
@ -470,8 +640,8 @@ class CreateSchema < ActiveRecord::Migration[4.2]
add_foreign_key :conversations, :people, name: :conversations_author_id_fk, column: :author_id, on_delete: :cascade
add_foreign_key :invitations, :users, name: :invitations_recipient_id_fk, column: :recipient_id, on_delete: :cascade
add_foreign_key :invitations, :users, name: :invitations_sender_id_fk, column: :sender_id, on_delete: :cascade
add_foreign_key :like_signatures, :likes, name: :like_signatures_like_id_fk, on_delete: :cascade
add_foreign_key :like_signatures, :signature_orders, name: :like_signatures_signature_orders_id_fk
add_foreign_key :likes, :people, name: :likes_author_id_fk, column: :author_id, on_delete: :cascade
@ -480,13 +650,25 @@ class CreateSchema < ActiveRecord::Migration[4.2]
add_foreign_key :notification_actors, :notifications, name: :notification_actors_notification_id_fk, on_delete: :cascade
add_foreign_key :o_auth_access_tokens, :authorizations
add_foreign_key :o_auth_applications, :users
add_foreign_key :people, :pods, name: :people_pod_id_fk, on_delete: :cascade
add_foreign_key :poll_participation_signatures, :poll_participations, name: :poll_participation_signatures_poll_participation_id_fk, on_delete: :cascade
add_foreign_key :poll_participation_signatures, :signature_orders, name: :poll_participation_signatures_signature_orders_id_fk
add_foreign_key :posts, :people, name: :posts_author_id_fk, column: :author_id, on_delete: :cascade
add_foreign_key :ppid, :o_auth_applications
add_foreign_key :ppid, :users
add_foreign_key :profiles, :people, name: :profiles_person_id_fk, on_delete: :cascade
add_foreign_key :services, :users, name: :services_user_id_fk, on_delete: :cascade
add_foreign_key :share_visibilities, :contacts, name: :post_visibilities_contact_id_fk, on_delete: :cascade
add_foreign_key :share_visibilities, :users, name: :share_visibilities_user_id_fk, on_delete: :cascade
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength, Layout/ExtraSpacing
end

View file

@ -1,5 +0,0 @@
class AddFacebookIdToPost < ActiveRecord::Migration[4.2]
def change
add_column :posts, :facebook_id, :string
end
end

View file

@ -1,9 +0,0 @@
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

View file

@ -1,6 +0,0 @@
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

View file

@ -1,19 +0,0 @@
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

View file

@ -1,13 +0,0 @@
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

View file

@ -1,13 +0,0 @@
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

View file

@ -1,5 +0,0 @@
class AddTumblrPostIdsToPosts < ActiveRecord::Migration[4.2]
def change
add_column :posts, :tumblr_ids, :text
end
end

View file

@ -1,13 +0,0 @@
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

View file

@ -1,15 +0,0 @@
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

View file

@ -1,6 +0,0 @@
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

View file

@ -1,8 +0,0 @@
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

View file

@ -1,12 +0,0 @@
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

View file

@ -1,38 +0,0 @@
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

View file

@ -1,11 +0,0 @@
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

View file

@ -1,12 +0,0 @@
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

View file

@ -1,15 +0,0 @@
# 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

View file

@ -1,17 +0,0 @@
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

View file

@ -1,17 +0,0 @@
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

View file

@ -1,5 +0,0 @@
class AddCompletedAtToAccountDeletions < ActiveRecord::Migration[4.2]
def change
add_column :account_deletions, :completed_at, :datetime
end
end

View file

@ -1,8 +0,0 @@
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

View file

@ -1,10 +0,0 @@
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

View file

@ -1,5 +0,0 @@
class AddRemoveAfterToUsers < ActiveRecord::Migration[4.2]
def change
add_column :users, :remove_after, :datetime
end
end

View file

@ -1,9 +0,0 @@
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

View file

@ -1,14 +0,0 @@
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

View file

@ -1,9 +0,0 @@
class DropOpenGraphCachesWithInvalidUrls < ActiveRecord::Migration[4.2]
def up
OpenGraphCache.where(url: 'http://').delete_all
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -1,13 +0,0 @@
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

View file

@ -1,7 +0,0 @@
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

View file

@ -1,9 +0,0 @@
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

View file

@ -1,9 +0,0 @@
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

View file

@ -1,13 +0,0 @@
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

View file

@ -1,11 +0,0 @@
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

View file

@ -1,11 +0,0 @@
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

View file

@ -1,9 +0,0 @@
class EnableColorThemes < ActiveRecord::Migration[4.2]
def up
add_column(:users, :color_theme, :string)
end
def down
remove_column(:users, :color_theme)
end
end

View file

@ -1,10 +0,0 @@
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

View file

@ -1,9 +0,0 @@
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

View file

@ -1,30 +0,0 @@
# 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

View file

@ -1,5 +0,0 @@
class AddPublicToProfiles < ActiveRecord::Migration[4.2]
def change
add_column :profiles, :public_details, :boolean, default: false
end
end

View file

@ -1,18 +0,0 @@
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

View file

@ -1,14 +0,0 @@
# 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

View file

@ -1,14 +0,0 @@
# 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

View file

@ -1,9 +0,0 @@
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

View file

@ -1,15 +0,0 @@
# 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

View file

@ -1,14 +0,0 @@
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

View file

@ -1,24 +0,0 @@
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

View file

@ -1,7 +0,0 @@
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

View file

@ -1,9 +0,0 @@
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

View file

@ -1,77 +0,0 @@
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
add_foreign_key :people, :pods, name: :people_pod_id_fk, on_delete: :cascade
Person.where(owner: nil).distinct(:url).pluck(:url).each do |url|
pod = Pod.find_or_create_by(url: url)
Person.where(url: url, owner_id: nil).update_all(pod_id: pod.id) if pod.persisted?
end
# cleanup unused pods
Pod.joins("LEFT OUTER JOIN people ON pods.id = people.pod_id").where("people.id is NULL").delete_all
remove_column :people, :url
end
def down
# restore url
add_column :people, :url, :text
Person.all.group_by(&:pod_id).each do |pod_id, persons|
Person.where(pod_id: pod_id).update_all(url: persons.first.url)
end
change_column :people, :url, :text, null: false
remove_foreign_key :people, :pods
remove_column :people, :pod_id
# remove pods with port
Pod.where.not(port: nil).delete_all
remove_index :pods, column: %i(host port)
remove_columns :pods, :port, :blocked
add_index :pods, :host, unique: true, length: 190
end
end

View file

@ -1,80 +0,0 @@
class LinkShareVisibilitiesWithUser < ActiveRecord::Migration[4.2]
class ShareVisibility < ApplicationRecord
end
def up
cleanup_deleted_share_visibilities
remove_columns :share_visibilities, :created_at, :updated_at
add_column :share_visibilities, :user_id, :integer
# update_all from AR doesn't work with postgres, see: https://github.com/rails/rails/issues/13496
if AppConfig.postgres?
execute "UPDATE share_visibilities SET user_id = contacts.user_id " \
"FROM contacts WHERE contacts.id = share_visibilities.contact_id"
else
ShareVisibility.joins("INNER JOIN contacts ON share_visibilities.contact_id = contacts.id")
.update_all("share_visibilities.user_id = contacts.user_id")
end
remove_foreign_key :share_visibilities, name: :post_visibilities_contact_id_fk
remove_index :share_visibilities, name: :index_post_visibilities_on_contact_id
remove_index :share_visibilities, name: :shareable_and_contact_id
remove_index :share_visibilities, name: :shareable_and_hidden_and_contact_id
remove_column :share_visibilities, :contact_id
ShareVisibility.joins("LEFT OUTER JOIN users ON users.id = share_visibilities.user_id")
.where("users.id is NULL").delete_all
change_column :share_visibilities, :user_id, :integer, null: false
add_index :share_visibilities, :user_id
add_index :share_visibilities, %i(shareable_id shareable_type user_id), name: :shareable_and_user_id
add_index :share_visibilities, %i(shareable_id shareable_type hidden user_id),
name: :shareable_and_hidden_and_user_id
add_foreign_key :share_visibilities, :users, name: :share_visibilities_user_id_fk, on_delete: :cascade
end
def down
add_column :share_visibilities, :contact_id, :integer
if AppConfig.postgres?
execute "UPDATE share_visibilities SET contact_id = contacts.id " \
"FROM contacts WHERE contacts.user_id = share_visibilities.user_id"
else
ShareVisibility.joins("INNER JOIN contacts ON share_visibilities.user_id = contacts.user_id")
.update_all("share_visibilities.contact_id = contacts.id")
end
remove_foreign_key :share_visibilities, name: :share_visibilities_user_id_fk
remove_index :share_visibilities, :user_id
remove_index :share_visibilities, name: :shareable_and_user_id
remove_index :share_visibilities, name: :shareable_and_hidden_and_user_id
remove_column :share_visibilities, :user_id
change_column :share_visibilities, :contact_id, :integer, null: false
add_index :share_visibilities, :contact_id, name: :index_post_visibilities_on_contact_id
add_index :share_visibilities, %i(shareable_id shareable_type contact_id), name: :shareable_and_contact_id
add_index :share_visibilities, %i(shareable_id shareable_type hidden contact_id),
name: :shareable_and_hidden_and_contact_id
add_foreign_key :share_visibilities, :contacts, name: :post_visibilities_contact_id_fk, on_delete: :cascade
add_column :share_visibilities, :created_at, :datetime
add_column :share_visibilities, :updated_at, :datetime
end
private
def cleanup_deleted_share_visibilities
ShareVisibility.joins("LEFT OUTER JOIN posts ON posts.id = share_visibilities.shareable_id")
.where(shareable_type: "Post").where("posts.id is NULL").delete_all
ShareVisibility.joins("LEFT OUTER JOIN photos ON photos.id = share_visibilities.shareable_id")
.where(shareable_type: "Photo").where("photos.id is NULL").delete_all
end
end

View file

@ -1,27 +0,0 @@
class CleanupAspectVisibility < ActiveRecord::Migration[4.2]
class AspectVisibility < ApplicationRecord
end
def up
AspectVisibility.joins("LEFT OUTER JOIN posts ON posts.id = aspect_visibilities.shareable_id")
.where(shareable_type: "Post").where("posts.id is NULL").delete_all
AspectVisibility.joins("LEFT OUTER JOIN photos ON photos.id = aspect_visibilities.shareable_id")
.where(shareable_type: "Photo").where("photos.id is NULL").delete_all
AspectVisibility.joins("INNER JOIN posts ON posts.id = aspect_visibilities.shareable_id")
.where(shareable_type: "Post").where(posts: {public: true}).delete_all
AspectVisibility.joins("INNER JOIN photos ON photos.id = aspect_visibilities.shareable_id")
.where(shareable_type: "Photo").where(photos: {public: true}).delete_all
remove_columns :aspect_visibilities, :created_at, :updated_at
end
def down
add_column :aspect_visibilities, :created_at, :datetime
add_column :aspect_visibilities, :updated_at, :datetime
User.all.each do |user|
user.posts.where(public: true).each {|post| user.add_to_streams(post, user.aspects) }
user.photos.where(public: true).each {|photo| user.add_to_streams(photo, user.aspects) }
end
end
end

View file

@ -1,7 +0,0 @@
class CleanupHandles < ActiveRecord::Migration[4.2]
def change
remove_column :photos, :tmp_old_id, :integer
remove_column :photos, :diaspora_handle, :string
remove_column :posts, :diaspora_handle, :string
end
end

View file

@ -1,5 +0,0 @@
class AddAuthorIdIndexToParticipations < ActiveRecord::Migration[4.2]
def change
add_index :participations, :author_id, :using => :btree
end
end

View file

@ -1,47 +0,0 @@
class CleanupDuplicatesAndAddUniqueIndexes < ActiveRecord::Migration[4.2]
def up
# temporary index to speed up the migration
add_index :photos, :guid, length: 191
# fix share visibilities for private photos
if AppConfig.postgres?
execute "UPDATE share_visibilities" \
" SET shareable_id = (SELECT MIN(p3.id) FROM photos as p3 WHERE p3.guid = p1.guid)" \
" FROM photos as p1, photos as p2" \
" WHERE p1.id = share_visibilities.shareable_id AND (p1.guid = p2.guid AND p1.id > p2.id)" \
" AND share_visibilities.shareable_type = 'Photo'"
else
execute "UPDATE share_visibilities" \
" INNER JOIN photos as p1 ON p1.id = share_visibilities.shareable_id" \
" INNER JOIN photos as p2 ON p1.guid = p2.guid AND p1.id > p2.id" \
" SET share_visibilities.shareable_id = (SELECT MIN(p3.id) FROM photos as p3 WHERE p3.guid = p1.guid)" \
" WHERE share_visibilities.shareable_type = 'Photo'"
end
%i(conversations messages photos polls poll_answers poll_participations).each do |table|
delete_duplicates_and_create_unique_index(table)
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
private
def delete_duplicates_and_create_unique_index(table)
# temporary index to speed up the migration
add_index table, :guid, length: 191 unless table == :photos
if AppConfig.postgres?
execute "DELETE FROM #{table} AS t1 USING #{table} AS t2 WHERE t1.guid = t2.guid AND t1.id > t2.id"
else
execute "DELETE t1 FROM #{table} t1, #{table} t2 WHERE t1.guid = t2.guid AND t1.id > t2.id"
end
remove_index table, column: :guid
# now create unique index \o/
add_index table, :guid, length: 191, unique: true
end
end

View file

@ -1,11 +0,0 @@
class RemoveDuplicateAspectVisibilities < ActiveRecord::Migration[4.2]
def up
where = "WHERE a1.aspect_id = a2.aspect_id AND a1.shareable_id = a2.shareable_id AND "\
"a1.shareable_type = a2.shareable_type AND a1.id > a2.id"
if AppConfig.postgres?
execute("DELETE FROM aspect_visibilities AS a1 USING aspect_visibilities AS a2 #{where}")
else
execute("DELETE a1 FROM aspect_visibilities a1, aspect_visibilities a2 #{where}")
end
end
end

View file

@ -1,44 +0,0 @@
class CleanupParticipations < ActiveRecord::Migration[4.2]
class Participation < ApplicationRecord
end
def up
remove_column :participations, :author_signature
cleanup
remove_index :participations, name: :index_participations_on_target_id_and_target_type_and_author_id
add_index :participations, %i(target_id target_type author_id), unique: true
end
def down
remove_index :participations, name: :index_participations_on_target_id_and_target_type_and_author_id
add_index :participations, %i(target_id target_type author_id)
add_column :participations, :author_signature, :text
end
private
def cleanup
self_where = "WHERE participations.target_type = 'Post' AND participations.target_id = posts.id AND " \
"posts.author_id = participations.author_id"
remote_where = "WHERE participations.target_type = 'Post' AND participations.target_id = posts.id AND " \
"posts.author_id = post_author.id AND participations.author_id = author.id AND " \
"author.owner_id is NULL AND post_author.owner_id is NULL"
duplicate_where = "WHERE p1.author_id = p2.author_id AND p1.target_id = p2.target_id " \
"AND p1.target_type = p2.target_type AND p1.id > p2.id"
if AppConfig.postgres?
execute "DELETE FROM participations USING posts #{self_where}"
execute "DELETE FROM participations USING posts, people AS author, people AS post_author #{remote_where}"
execute "DELETE FROM participations AS p1 USING participations AS p2 #{duplicate_where}"
else
execute "DELETE participations FROM participations, posts #{self_where}"
execute "DELETE participations FROM participations, posts, people author, people post_author #{remote_where}"
execute "DELETE p1 FROM participations p1, participations p2 #{duplicate_where}"
end
Participation.joins("LEFT OUTER JOIN posts ON posts.id = participations.target_id")
.where(target_type: "Post").where("posts.id is NULL").delete_all
end
end

View file

@ -1,87 +0,0 @@
class CreateSignatureTables < ActiveRecord::Migration[4.2]
class SignatureOrder < ApplicationRecord
end
RELAYABLES = %i(comment like poll_participation).freeze
def self.up
create_table :signature_orders do |t|
t.string :order, null: false
end
add_index :signature_orders, :order, length: 191, unique: true
RELAYABLES.each {|relayable_type| create_signature_table(relayable_type) }
migrate_signatures
RELAYABLES.each {|relayable_type| remove_column "#{relayable_type}s", :author_signature }
end
def self.down
RELAYABLES.each {|relayable_type| add_column "#{relayable_type}s", :author_signature, :text }
RELAYABLES.each {|relayable_type| restore_signatures(relayable_type) }
drop_table :comment_signatures
drop_table :like_signatures
drop_table :poll_participation_signatures
drop_table :signature_orders
end
private
def create_signature_table(relayable_type)
create_table "#{relayable_type}_signatures", id: false do |t|
t.integer "#{relayable_type}_id", null: false
t.text :author_signature, null: false
t.integer :signature_order_id, null: false
t.text :additional_data
end
add_index "#{relayable_type}_signatures", "#{relayable_type}_id", unique: true
add_foreign_key "#{relayable_type}_signatures", :signature_orders,
name: "#{relayable_type}_signatures_signature_orders_id_fk"
add_foreign_key "#{relayable_type}_signatures", "#{relayable_type}s",
name: "#{relayable_type}_signatures_#{relayable_type}_id_fk", on_delete: :cascade
end
def migrate_signatures
comment_order_id = SignatureOrder.create!(order: "guid parent_guid text author").id
comment_parent_join = "INNER JOIN posts AS parent ON relayable.commentable_id = parent.id"
migrate_signatures_for(:comment, comment_order_id, comment_parent_join)
like_order_id = SignatureOrder.create!(order: "positive guid parent_type parent_guid author").id
post_like_join = "INNER JOIN posts AS parent ON relayable.target_id = parent.id AND relayable.target_type = 'Post'"
comment_like_join = "INNER JOIN comments ON relayable.target_id = comments.id " \
"AND relayable.target_type = 'Comment' " \
"INNER JOIN posts AS parent ON comments.commentable_id = parent.id"
migrate_signatures_for(:like, like_order_id, post_like_join)
migrate_signatures_for(:like, like_order_id, comment_like_join)
poll_participation_order_id = SignatureOrder.create!(order: "guid parent_guid author poll_answer_guid").id
poll_participation_parent_join = "INNER JOIN polls ON relayable.poll_id = polls.id " \
"INNER JOIN posts AS parent ON polls.status_message_id = parent.id"
migrate_signatures_for(:poll_participation, poll_participation_order_id, poll_participation_parent_join)
end
def migrate_signatures_for(relayable_type, order_id, parent_join)
execute "INSERT INTO #{relayable_type}_signatures (#{relayable_type}_id, signature_order_id, author_signature) " \
"SELECT relayable.id, #{order_id}, relayable.author_signature FROM #{relayable_type}s AS relayable " \
"INNER JOIN people AS author ON relayable.author_id = author.id " \
"#{parent_join} INNER JOIN people AS parent_author ON parent.author_id = parent_author.id " \
"WHERE author.owner_id IS NULL AND parent_author.owner_id IS NOT NULL AND relayable.author_signature IS NOT NULL"
end
def restore_signatures(relayable_type)
if AppConfig.postgres?
execute "UPDATE #{relayable_type}s SET author_signature = #{relayable_type}_signatures.author_signature " \
"FROM #{relayable_type}_signatures " \
"WHERE #{relayable_type}s.id = #{relayable_type}_signatures.#{relayable_type}_id "
else
execute "UPDATE #{relayable_type}s INNER JOIN #{relayable_type}_signatures " \
"ON #{relayable_type}s.id = #{relayable_type}_signatures.#{relayable_type}_id " \
"SET #{relayable_type}s.author_signature = #{relayable_type}_signatures.author_signature"
end
end
end

View file

@ -1,30 +0,0 @@
class CleanupPostsTable < ActiveRecord::Migration[4.2]
def change
remove_index :posts, column: %i(status_message_guid pending),
name: :index_posts_on_status_message_guid_and_pending, length: {status_message_guid: 190}
remove_index :posts, column: :status_message_guid, name: :index_posts_on_status_message_guid, length: 191
remove_index :posts, column: %i(type pending id), name: :index_posts_on_type_and_pending_and_id
# from photos?
remove_column :posts, :pending, :boolean, default: false, null: false
remove_column :posts, :remote_photo_path, :text
remove_column :posts, :remote_photo_name, :string
remove_column :posts, :random_string, :string
remove_column :posts, :processed_image, :string
remove_column :posts, :unprocessed_image, :string
remove_column :posts, :status_message_guid, :string
# old cubbi.es stuff
remove_column :posts, :object_url, :string
remove_column :posts, :image_url, :string
remove_column :posts, :image_height, :integer
remove_column :posts, :image_width, :integer
remove_column :posts, :actor_url, :string
remove_column :posts, :objectId, :string
# old single post view templates
remove_column :posts, :frame_name, :string
add_index :posts, %i(id type), name: :index_posts_on_id_and_type
end
end

View file

@ -1,47 +0,0 @@
class ParticipationCounter < ActiveRecord::Migration[4.2]
class Comment < ApplicationRecord
end
class Like < ApplicationRecord
end
class Participation < ApplicationRecord
belongs_to :author, class_name: "Person"
end
class Poll < ApplicationRecord
end
class PollParticipation < ApplicationRecord
belongs_to :poll
end
def up
return if ActiveRecord::SchemaMigration.where(version: "20150404193023").exists?
add_column :participations, :count, :integer, null: false, default: 1
likes_count = Like.select("COUNT(likes.id)")
.where("likes.target_id = participations.target_id")
.where("likes.author_id = participations.author_id")
.to_sql
comments_count = Comment.select("COUNT(comments.id)")
.where("comments.commentable_id = participations.target_id")
.where("comments.author_id = participations.author_id")
.to_sql
polls_count = PollParticipation.select("COUNT(*)")
.where("poll_participations.author_id = participations.author_id")
.joins(:poll)
.where("polls.status_message_id = participations.target_id")
.to_sql
Participation.joins(:author).where.not(people: {owner_id: nil})
.update_all("count = (#{likes_count}) + (#{comments_count}) + (#{polls_count})")
Participation.where(count: 0).update_all(count: 1)
end
def down
remove_column :participations, :count
ActiveRecord::SchemaMigration.where(version: "20150404193023").delete_all
end
end

View file

@ -1,72 +0,0 @@
class CleanupInvitationColumnsFromUsers < ActiveRecord::Migration[4.2]
class InvitationCode < ApplicationRecord
end
class User < ApplicationRecord
end
def change
remove_index :users, column: %i(invitation_service invitation_identifier),
name: :index_users_on_invitation_service_and_invitation_identifier,
unique: true, length: {invitation_service: 64}
remove_index :users, column: :invitation_token, name: :index_users_on_invitation_token
remove_index :users, column: :email, name: :index_users_on_email, length: 191
cleanup_invitations
remove_column :users, :invitation_token, :string, limit: 60
remove_column :users, :invitation_sent_at, :datetime
remove_column :users, :invitation_service, :string, limit: 127
remove_column :users, :invitation_identifier, :string, limit: 127
remove_column :users, :invitation_limit, :integer
remove_column :users, :invited_by_type, :string
add_index :users, :email, name: :index_users_on_email, unique: true, length: 191
end
def cleanup_invitations
reversible do |dir|
dir.up do
drop_table :invitations
# reset negative invitation counters
new_counter = AppConfig.settings.enable_registrations? ? AppConfig["settings.invitations.count"] : 0
InvitationCode.where("count < 0").update_all(count: new_counter)
# remove old invitation-users
User.where(username: nil).delete_all
change_column :users, :username, :string, null: false
end
dir.down do
change_column :users, :username, :string, null: true
create_invitations_table
end
end
end
def create_invitations_table
# rubocop:disable Layout/ExtraSpacing
create_table :invitations, force: :cascade do |t|
t.text :message, limit: 65_535
t.integer :sender_id, limit: 4
t.integer :recipient_id, limit: 4
t.integer :aspect_id, limit: 4
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.string :service, limit: 255
t.string :identifier, limit: 255
t.boolean :admin, default: false
t.string :language, limit: 255, default: "en"
end
# rubocop:enable Layout/ExtraSpacing
add_index :invitations, :aspect_id, name: :index_invitations_on_aspect_id, using: :btree
add_index :invitations, :recipient_id, name: :index_invitations_on_recipient_id, using: :btree
add_index :invitations, :sender_id, name: :index_invitations_on_sender_id, using: :btree
add_foreign_key :invitations, :users, column: :recipient_id, name: :invitations_recipient_id_fk, on_delete: :cascade
add_foreign_key :invitations, :users, column: :sender_id, name: :invitations_sender_id_fk, on_delete: :cascade
end
end

View file

@ -1,7 +0,0 @@
require_relative "20150714055110_create_id_tokens"
class RemoveIdTokens < ActiveRecord::Migration[4.2]
def change
revert CreateIdTokens
end
end

View file

@ -1,13 +0,0 @@
class RemoveStartedSharingNotificationsWithoutContact < ActiveRecord::Migration[4.2]
class Notification < ApplicationRecord
end
def up
Notification.where(type: "Notifications::StartedSharing", target_type: "Person")
.joins("INNER JOIN people ON people.id = notifications.target_id")
.joins("LEFT OUTER JOIN contacts ON contacts.person_id = people.id " \
"AND contacts.user_id = notifications.recipient_id")
.where("contacts.id IS NULL")
.delete_all
end
end