Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
f682387a
Commit
f682387a
authored
5 years ago
by
ThibG
Committed by
Eugen Rochko
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix old migration failing with new status default scope (#12493)
parent
bbf926b1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
db/migrate/20181024224956_migrate_account_conversations.rb
+60
-0
60 additions, 0 deletions
db/migrate/20181024224956_migrate_account_conversations.rb
with
60 additions
and
0 deletions
db/migrate/20181024224956_migrate_account_conversations.rb
+
60
−
0
View file @
f682387a
class
MigrateAccountConversations
<
ActiveRecord
::
Migration
[
5.2
]
disable_ddl_transaction!
class
Mention
<
ApplicationRecord
belongs_to
:account
,
inverse_of: :mentions
belongs_to
:status
,
->
{
unscope
(
where: :deleted_at
)
}
delegate
(
:username
,
:acct
,
to: :account
,
prefix:
true
)
end
class
Notification
<
ApplicationRecord
belongs_to
:account
,
optional:
true
belongs_to
:activity
,
polymorphic:
true
,
optional:
true
belongs_to
:status
,
foreign_type:
'Status'
,
foreign_key:
'activity_id'
,
optional:
true
belongs_to
:mention
,
foreign_type:
'Mention'
,
foreign_key:
'activity_id'
,
optional:
true
def
target_status
mention
&
.
status
end
end
class
AccountConversation
<
ApplicationRecord
belongs_to
:account
belongs_to
:conversation
belongs_to
:last_status
,
->
{
unscope
(
where: :deleted_at
)
},
class_name:
'Status'
before_validation
:set_last_status
class
<<
self
def
add_status
(
recipient
,
status
)
conversation
=
find_or_initialize_by
(
account:
recipient
,
conversation_id:
status
.
conversation_id
,
participant_account_ids:
participants_from_status
(
recipient
,
status
))
return
conversation
if
conversation
.
status_ids
.
include?
(
status
.
id
)
conversation
.
status_ids
<<
status
.
id
conversation
.
unread
=
status
.
account_id
!=
recipient
.
id
conversation
.
save
conversation
rescue
ActiveRecord
::
StaleObjectError
retry
end
private
def
participants_from_status
(
recipient
,
status
)
((
status
.
active_mentions
.
pluck
(
:account_id
)
+
[
status
.
account_id
]).
uniq
-
[
recipient
.
id
]).
sort
end
end
private
def
set_last_status
self
.
status_ids
=
status_ids
.
sort
self
.
last_status_id
=
status_ids
.
last
end
end
def
up
say
''
say
'WARNING: This migration may take a *long* time for large instances'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment