Merge branch 'feature/object-hashtags-rework' into 'develop'
Hashtags extraction from objects. Background migration infrastructure. Closes #1840 and #2455 See merge request pleroma/pleroma!3213
This commit is contained in:
commit
8194622a72
46 changed files with 1359 additions and 175 deletions
|
|
@ -9,7 +9,7 @@ defmodule Pleroma.Repo.Migrations.CreateSafeJsonbSet do
|
|||
begin
|
||||
result := jsonb_set(target, path, coalesce(new_value, 'null'::jsonb), create_missing);
|
||||
if result is NULL then
|
||||
raise 'jsonb_set tried to wipe the object, please report this incindent to Pleroma bug tracker. https://git.pleroma.social/pleroma/pleroma/issues/new';
|
||||
raise 'jsonb_set tried to wipe the object, please report this incident to Pleroma bug tracker. https://git.pleroma.social/pleroma/pleroma/issues/new';
|
||||
return target;
|
||||
else
|
||||
return result;
|
||||
|
|
|
|||
13
priv/repo/migrations/20201221202251_create_hashtags.exs
Normal file
13
priv/repo/migrations/20201221202251_create_hashtags.exs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreateHashtags do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists table(:hashtags) do
|
||||
add(:name, :citext, null: false)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create_if_not_exists(unique_index(:hashtags, [:name]))
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Pleroma.Repo.Migrations.RemoveDataFromHashtags do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
alter table(:hashtags) do
|
||||
remove_if_exists(:data, :map)
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:hashtags) do
|
||||
add_if_not_exists(:data, :map, default: %{})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreateHashtagsObjects do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists table(:hashtags_objects, primary_key: false) do
|
||||
add(:hashtag_id, references(:hashtags), null: false, primary_key: true)
|
||||
add(:object_id, references(:objects), null: false, primary_key: true)
|
||||
end
|
||||
|
||||
# Note: PK index: "hashtags_objects_pkey" PRIMARY KEY, btree (hashtag_id, object_id)
|
||||
create_if_not_exists(index(:hashtags_objects, [:object_id]))
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreateDataMigrations do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists table(:data_migrations) do
|
||||
add(:name, :string, null: false)
|
||||
add(:state, :integer, default: 1)
|
||||
add(:feature_lock, :boolean, default: false)
|
||||
add(:params, :map, default: %{})
|
||||
add(:data, :map, default: %{})
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create_if_not_exists(unique_index(:data_migrations, [:name]))
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
defmodule Pleroma.Repo.Migrations.DataMigrationCreatePopulateHashtagsTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
dt = NaiveDateTime.utc_now()
|
||||
|
||||
execute(
|
||||
"INSERT INTO data_migrations(name, inserted_at, updated_at) " <>
|
||||
"VALUES ('populate_hashtags_table', '#{dt}', '#{dt}') ON CONFLICT DO NOTHING;"
|
||||
)
|
||||
end
|
||||
|
||||
def down do
|
||||
execute("DELETE FROM data_migrations WHERE name = 'populate_hashtags_table';")
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreateDataMigrationFailedIds do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists table(:data_migration_failed_ids, primary_key: false) do
|
||||
add(:data_migration_id, references(:data_migrations), null: false, primary_key: true)
|
||||
add(:record_id, :bigint, null: false, primary_key: true)
|
||||
end
|
||||
|
||||
create_if_not_exists(
|
||||
unique_index(:data_migration_failed_ids, [:data_migration_id, :record_id])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
defmodule Pleroma.Repo.Migrations.RemoveHashtagsObjectsDuplicateIndex do
|
||||
use Ecto.Migration
|
||||
|
||||
@moduledoc "Removes `hashtags_objects_hashtag_id_object_id_index` index (duplicate of PK index)."
|
||||
|
||||
def up do
|
||||
drop_if_exists(unique_index(:hashtags_objects, [:hashtag_id, :object_id]))
|
||||
end
|
||||
|
||||
def down, do: nil
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Pleroma.Repo.Migrations.ChangeHashtagsNameToText do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
alter table(:hashtags) do
|
||||
modify(:name, :text)
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:hashtags) do
|
||||
modify(:name, :citext)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue