[#534] Merged upstream/develop.
This commit is contained in:
commit
d3f9e6f6fe
76 changed files with 1588 additions and 187 deletions
|
|
@ -0,0 +1,125 @@
|
|||
defmodule Pleroma.Repo.Migrations.UsersAndActivitiesFlakeId do
|
||||
use Ecto.Migration
|
||||
alias Pleroma.Clippy
|
||||
require Integer
|
||||
import Ecto.Query
|
||||
alias Pleroma.Repo
|
||||
|
||||
# This migrates from int serial IDs to custom Flake:
|
||||
# 1- create a temporary uuid column
|
||||
# 2- fill this column with compatibility ids (see below)
|
||||
# 3- remove pkeys constraints
|
||||
# 4- update relation pkeys with the new ids
|
||||
# 5- rename the temporary column to id
|
||||
# 6- re-create the constraints
|
||||
def change do
|
||||
# Old serial int ids are transformed to 128bits with extra padding.
|
||||
# The application (in `Pleroma.FlakeId`) handles theses IDs properly as integers; to keep compatibility
|
||||
# with previously issued ids.
|
||||
#execute "update activities set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
|
||||
#execute "update users set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
|
||||
|
||||
clippy = start_clippy_heartbeats()
|
||||
|
||||
# Lock both tables to avoid a running server to meddling with our transaction
|
||||
execute "LOCK TABLE activities;"
|
||||
execute "LOCK TABLE users;"
|
||||
|
||||
execute """
|
||||
ALTER TABLE activities
|
||||
DROP CONSTRAINT activities_pkey CASCADE,
|
||||
ALTER COLUMN id DROP default,
|
||||
ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid),
|
||||
ADD PRIMARY KEY (id);
|
||||
"""
|
||||
|
||||
execute """
|
||||
ALTER TABLE users
|
||||
DROP CONSTRAINT users_pkey CASCADE,
|
||||
ALTER COLUMN id DROP default,
|
||||
ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid),
|
||||
ADD PRIMARY KEY (id);
|
||||
"""
|
||||
|
||||
execute "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);"
|
||||
|
||||
# Fkeys:
|
||||
# Activities - Referenced by:
|
||||
# TABLE "notifications" CONSTRAINT "notifications_activity_id_fkey" FOREIGN KEY (activity_id) REFERENCES activities(id) ON DELETE CASCADE
|
||||
# Users - Referenced by:
|
||||
# TABLE "filters" CONSTRAINT "filters_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
# TABLE "lists" CONSTRAINT "lists_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
# TABLE "notifications" CONSTRAINT "notifications_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
# TABLE "oauth_authorizations" CONSTRAINT "oauth_authorizations_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
# TABLE "oauth_tokens" CONSTRAINT "oauth_tokens_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
# TABLE "password_reset_tokens" CONSTRAINT "password_reset_tokens_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
# TABLE "push_subscriptions" CONSTRAINT "push_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
# TABLE "websub_client_subscriptions" CONSTRAINT "websub_client_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
|
||||
execute """
|
||||
ALTER TABLE notifications
|
||||
ALTER COLUMN activity_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(activity_id), 32, '0' ) AS uuid),
|
||||
ADD CONSTRAINT notifications_activity_id_fkey FOREIGN KEY (activity_id) REFERENCES activities(id) ON DELETE CASCADE;
|
||||
"""
|
||||
|
||||
for table <- ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do
|
||||
execute """
|
||||
ALTER TABLE #{table}
|
||||
ALTER COLUMN user_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(user_id), 32, '0' ) AS uuid),
|
||||
ADD CONSTRAINT #{table}_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
"""
|
||||
end
|
||||
|
||||
flush()
|
||||
|
||||
stop_clippy_heartbeats(clippy)
|
||||
end
|
||||
|
||||
defp start_clippy_heartbeats() do
|
||||
count = from(a in "activities", select: count(a.id)) |> Repo.one!
|
||||
|
||||
if count > 5000 do
|
||||
heartbeat_interval = :timer.minutes(2) + :timer.seconds(30)
|
||||
all_tips = Clippy.tips() ++ [
|
||||
"The migration is still running, maybe it's time for another “tea”?",
|
||||
"Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!",
|
||||
"Nothing and everything.\n\nI still work.",
|
||||
"Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi",
|
||||
"Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused.",
|
||||
]
|
||||
|
||||
heartbeat = fn(heartbeat, runs, all_tips, tips) ->
|
||||
tips = if Integer.is_even(runs) do
|
||||
tips = if tips == [], do: all_tips, else: tips
|
||||
[tip | tips] = Enum.shuffle(tips)
|
||||
Clippy.puts(tip)
|
||||
tips
|
||||
else
|
||||
IO.puts "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n"
|
||||
tips
|
||||
end
|
||||
:timer.sleep(heartbeat_interval)
|
||||
heartbeat.(heartbeat, runs + 1, all_tips, tips)
|
||||
end
|
||||
|
||||
Clippy.puts [
|
||||
[:red, :bright, "It looks like you are running an older instance!"],
|
||||
[""],
|
||||
[:bright, "This migration may take a long time", :reset, " -- so you probably should"],
|
||||
["go drink a cofe, or a tea, or a beer, a whiskey, a vodka,"],
|
||||
["while it runs to deal with your temporary fediverse pause!"]
|
||||
]
|
||||
:timer.sleep(heartbeat_interval)
|
||||
spawn_link(fn() -> heartbeat.(heartbeat, 1, all_tips, []) end)
|
||||
end
|
||||
end
|
||||
|
||||
defp stop_clippy_heartbeats(pid) do
|
||||
if pid do
|
||||
Process.unlink(pid)
|
||||
Process.exit(pid, :kill)
|
||||
Clippy.puts [[:green, :bright, "Hurray!!", "", "", "Migration completed!"]]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
defmodule Pleroma.Repo.Migrations.UpdateActivityVisibilityAgain do
|
||||
use Ecto.Migration
|
||||
@disable_ddl_transaction true
|
||||
|
||||
def up do
|
||||
definition = """
|
||||
create or replace function activity_visibility(actor varchar, recipients varchar[], data jsonb) returns varchar as $$
|
||||
DECLARE
|
||||
fa varchar;
|
||||
public varchar := 'https://www.w3.org/ns/activitystreams#Public';
|
||||
BEGIN
|
||||
SELECT COALESCE(users.follower_address, '') into fa from public.users where users.ap_id = actor;
|
||||
|
||||
IF data->'to' ? public THEN
|
||||
RETURN 'public';
|
||||
ELSIF data->'cc' ? public THEN
|
||||
RETURN 'unlisted';
|
||||
ELSIF ARRAY[fa] && recipients THEN
|
||||
RETURN 'private';
|
||||
ELSIF not(ARRAY[fa, public] && recipients) THEN
|
||||
RETURN 'direct';
|
||||
ELSE
|
||||
RETURN 'unknown';
|
||||
END IF;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE SECURITY DEFINER;
|
||||
"""
|
||||
|
||||
execute(definition)
|
||||
|
||||
end
|
||||
|
||||
def down do
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
defmodule Pleroma.Repo.Migrations.ChangePushSubscriptionsVarchar do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:push_subscriptions) do
|
||||
modify(:endpoint, :varchar)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddActivitiesLikesIndex do
|
||||
use Ecto.Migration
|
||||
@disable_ddl_transaction true
|
||||
|
||||
def change do
|
||||
create index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], concurrently: true, name: :activities_likes, using: :gin)
|
||||
end
|
||||
end
|
||||
|
|
@ -1 +1 @@
|
|||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link rel=stylesheet href=/static/font/css/fontello.css><link rel=stylesheet href=/static/font/css/animation.css><link href=/static/css/app.3d3e30a9afb8c41739656f496e8c79e6.css rel=stylesheet></head><body style="display: none"><div id=app></div><script type=text/javascript src=/static/js/manifest.e58590e04ca06ebbea1e.js></script><script type=text/javascript src=/static/js/vendor.61fac267296f19262d14.js></script><script type=text/javascript src=/static/js/app.76e23c93f1de5902c4d7.js></script></body></html>
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link rel=stylesheet href=/static/font/css/fontello.css><link rel=stylesheet href=/static/font/css/animation.css><link href=/static/css/app.3d3e30a9afb8c41739656f496e8c79e6.css rel=stylesheet></head><body style="display: none"><div id=app></div><script type=text/javascript src=/static/js/manifest.8dc8d7a1dc85bfdf2b14.js></script><script type=text/javascript src=/static/js/vendor.61fd03d8471aaadcf63c.js></script><script type=text/javascript src=/static/js/app.ddbd2a89e264d04e0d6d.js></script></body></html>
|
||||
|
|
@ -18,5 +18,6 @@
|
|||
"hideUserStats": false,
|
||||
"loginMethod": "password",
|
||||
"webPushNotifications": false,
|
||||
"noAttachmentLinks": false
|
||||
"noAttachmentLinks": false,
|
||||
"nsfwCensorImage": ""
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
14
priv/static/static/js/app.ddbd2a89e264d04e0d6d.js
Normal file
14
priv/static/static/js/app.ddbd2a89e264d04e0d6d.js
Normal file
File diff suppressed because one or more lines are too long
1
priv/static/static/js/app.ddbd2a89e264d04e0d6d.js.map
Normal file
1
priv/static/static/js/app.ddbd2a89e264d04e0d6d.js.map
Normal file
File diff suppressed because one or more lines are too long
2
priv/static/static/js/manifest.8dc8d7a1dc85bfdf2b14.js
Normal file
2
priv/static/static/js/manifest.8dc8d7a1dc85bfdf2b14.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
!function(e){function t(a){if(r[a])return r[a].exports;var n=r[a]={exports:{},id:a,loaded:!1};return e[a].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var a=window.webpackJsonp;window.webpackJsonp=function(o,c){for(var p,d,l=0,s=[];l<o.length;l++)d=o[l],n[d]&&s.push.apply(s,n[d]),n[d]=0;for(p in c)Object.prototype.hasOwnProperty.call(c,p)&&(e[p]=c[p]);for(a&&a(o,c);s.length;)s.shift().call(null,t);if(c[0])return r[0]=0,t(0)};var r={},n={0:0};t.e=function(e,a){if(0===n[e])return a.call(null,t);if(void 0!==n[e])n[e].push(a);else{n[e]=[a];var r=document.getElementsByTagName("head")[0],o=document.createElement("script");o.type="text/javascript",o.charset="utf-8",o.async=!0,o.src=t.p+"static/js/"+e+"."+{1:"61fd03d8471aaadcf63c",2:"ddbd2a89e264d04e0d6d"}[e]+".js",r.appendChild(o)}},t.m=e,t.c=r,t.p="/"}([]);
|
||||
//# sourceMappingURL=manifest.8dc8d7a1dc85bfdf2b14.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,2 +0,0 @@
|
|||
!function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={exports:{},id:r,loaded:!1};return e[r].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r=window.webpackJsonp;window.webpackJsonp=function(c,o){for(var p,l,s=0,i=[];s<c.length;s++)l=c[s],a[l]&&i.push.apply(i,a[l]),a[l]=0;for(p in o)Object.prototype.hasOwnProperty.call(o,p)&&(e[p]=o[p]);for(r&&r(c,o);i.length;)i.shift().call(null,t);if(o[0])return n[0]=0,t(0)};var n={},a={0:0};t.e=function(e,r){if(0===a[e])return r.call(null,t);if(void 0!==a[e])a[e].push(r);else{a[e]=[r];var n=document.getElementsByTagName("head")[0],c=document.createElement("script");c.type="text/javascript",c.charset="utf-8",c.async=!0,c.src=t.p+"static/js/"+e+"."+{1:"61fac267296f19262d14",2:"76e23c93f1de5902c4d7"}[e]+".js",n.appendChild(c)}},t.m=e,t.c=n,t.p="/"}([]);
|
||||
//# sourceMappingURL=manifest.e58590e04ca06ebbea1e.js.map
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
priv/static/static/js/vendor.61fd03d8471aaadcf63c.js.map
Normal file
1
priv/static/static/js/vendor.61fd03d8471aaadcf63c.js.map
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
var serviceWorkerOption = {"assets":["/static/img/nsfw.50fd83c.png","/static/js/manifest.e58590e04ca06ebbea1e.js","/static/js/vendor.61fac267296f19262d14.js","/static/js/app.76e23c93f1de5902c4d7.js","/static/css/app.3d3e30a9afb8c41739656f496e8c79e6.css"]};
|
||||
var serviceWorkerOption = {"assets":["/static/img/nsfw.50fd83c.png","/static/js/manifest.8dc8d7a1dc85bfdf2b14.js","/static/js/vendor.61fd03d8471aaadcf63c.js","/static/js/app.ddbd2a89e264d04e0d6d.js","/static/css/app.3d3e30a9afb8c41739656f496e8c79e6.css"]};
|
||||
|
||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=e,n.c=t,n.p="/",n(0)}([function(e,n,t){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(){return u.default.getItem("vuex-lz").then(function(e){return e.config.webPushNotifications})}function i(){return clients.matchAll({includeUncontrolled:!0}).then(function(e){return e.filter(function(e){var n=e.type;return"window"===n})})}var a=t(1),u=r(a);self.addEventListener("push",function(e){e.data&&e.waitUntil(o().then(function(n){return n&&i().then(function(n){var t=e.data.json();if(0===n.length)return self.registration.showNotification(t.title,t)})}))}),self.addEventListener("notificationclick",function(e){e.notification.close(),e.waitUntil(i().then(function(e){for(var n=0;n<e.length;n++){var t=e[n];if("/"===t.url&&"focus"in t)return t.focus()}if(clients.openWindow)return clients.openWindow("/")}))})},function(e,n){/*!
|
||||
localForage -- Offline Storage, Improved
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue