Replaces embedded objects with references to them in the `objects` table. Only needs to be ran once. The reason why this is not a migration is because it could significantly increase the database size after being ran, however after this `VACUUM FULL` will be able to reclaim about 20% (really depends on what is in the database, your mileage may vary) of the db size before the migration.
mix pleroma.database remove_embedded_objects
Options:
- `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references
"""
defrun(["remove_embedded_objects"|args])do
{options,[],[]}=
OptionParser.parse(
args,
strict:[
vacuum::boolean
]
)
Common.start_pleroma()
Ecto.Adapters.SQL.query!(
Pleroma.Repo,
"update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;"
# TODO: bench on a real DB and add clippy if it takes too long
defchangedo
execute"""
update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->>'type' = 'Create' and data->'object'->>'id' is not null;