mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 08:16:12 +00:00
Adding unique constraint for activity ap_id. Fixes #1878
This commit is contained in:
parent
76c4378011
commit
744f242061
|
@ -127,7 +127,7 @@ mod tests {
|
|||
let inserted_activity = Activity::create(&conn, &activity_form).unwrap();
|
||||
|
||||
let expected_activity = Activity {
|
||||
ap_id: Some(ap_id.clone()),
|
||||
ap_id: ap_id.clone(),
|
||||
id: inserted_activity.id,
|
||||
data: test_json,
|
||||
local: true,
|
||||
|
|
|
@ -5,7 +5,7 @@ table! {
|
|||
local -> Bool,
|
||||
published -> Timestamp,
|
||||
updated -> Nullable<Timestamp>,
|
||||
ap_id -> Nullable<Text>,
|
||||
ap_id -> Text,
|
||||
sensitive -> Nullable<Bool>,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub struct Activity {
|
|||
pub local: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub ap_id: Option<DbUrl>,
|
||||
pub ap_id: DbUrl,
|
||||
pub sensitive: Option<bool>,
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
alter table activity alter column ap_id drop not null;
|
||||
|
||||
create unique index idx_activity_unique_apid on activity ((data ->> 'id'::text));
|
||||
|
||||
drop index idx_activity_ap_id;
|
22
migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql
Normal file
22
migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
-- Delete the empty ap_ids
|
||||
delete from activity where ap_id is null;
|
||||
|
||||
-- Make it required
|
||||
alter table activity alter column ap_id set not null;
|
||||
|
||||
-- Delete dupes, keeping the first one
|
||||
delete
|
||||
from activity
|
||||
where id not in (
|
||||
select min(id)
|
||||
from activity
|
||||
group by ap_id
|
||||
);
|
||||
|
||||
-- The index
|
||||
create unique index idx_activity_ap_id on activity(ap_id);
|
||||
|
||||
-- Drop the old index
|
||||
drop index idx_activity_unique_apid;
|
||||
|
Loading…
Reference in a new issue