fixed migration the settings to DB
This commit is contained in:
parent
bb68f9d27c
commit
02a5648feb
3 changed files with 20 additions and 15 deletions
|
@ -52,6 +52,7 @@ def migrate_to_db(file_path \\ nil) do
|
|||
|
||||
defp do_migrate_to_db(config_file) do
|
||||
if File.exists?(config_file) do
|
||||
shell_info("Running migrate settings from file: #{Path.expand(config_file)}")
|
||||
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
|
||||
Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Config.Loader do
|
|||
Pleroma.Web.Endpoint,
|
||||
:env,
|
||||
:configurable_from_database,
|
||||
:database,
|
||||
:swarm
|
||||
]
|
||||
|
||||
|
|
|
@ -2,24 +2,29 @@ defmodule Pleroma.Repo.Migrations.AddFtsIndexToObjectsTwo do
|
|||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
execute("create extension if not exists rum")
|
||||
drop_if_exists index(:objects, ["(to_tsvector('english', data->>'content'))"], using: :gin, name: :objects_fts)
|
||||
alter table(:objects) do
|
||||
add(:fts_content, :tsvector)
|
||||
end
|
||||
if Pleroma.Config.get([:database, :rum_enabled]) do
|
||||
execute("create extension if not exists rum")
|
||||
drop_if_exists index(:objects, ["(to_tsvector('english', data->>'content'))"], using: :gin, name: :objects_fts)
|
||||
alter table(:objects) do
|
||||
add(:fts_content, :tsvector)
|
||||
end
|
||||
|
||||
execute("CREATE FUNCTION objects_fts_update() RETURNS trigger AS $$
|
||||
begin
|
||||
execute("CREATE FUNCTION objects_fts_update() RETURNS trigger AS $$
|
||||
begin
|
||||
new.fts_content := to_tsvector('english', new.data->>'content');
|
||||
return new;
|
||||
end
|
||||
$$ LANGUAGE plpgsql")
|
||||
execute("create index if not exists objects_fts on objects using RUM (fts_content rum_tsvector_addon_ops, inserted_at) with (attach = 'inserted_at', to = 'fts_content');")
|
||||
|
||||
execute("CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON objects
|
||||
FOR EACH ROW EXECUTE PROCEDURE objects_fts_update()")
|
||||
|
||||
execute("UPDATE objects SET updated_at = NOW()")
|
||||
else
|
||||
raise Ecto.MigrationError,
|
||||
message: "Migration is not allowed. You can change this behavior by setting `database/rum_enabled` to true."
|
||||
end
|
||||
$$ LANGUAGE plpgsql")
|
||||
execute("create index if not exists objects_fts on objects using RUM (fts_content rum_tsvector_addon_ops, inserted_at) with (attach = 'inserted_at', to = 'fts_content');")
|
||||
|
||||
execute("CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON objects
|
||||
FOR EACH ROW EXECUTE PROCEDURE objects_fts_update()")
|
||||
|
||||
execute("UPDATE objects SET updated_at = NOW()")
|
||||
end
|
||||
|
||||
def down do
|
||||
|
|
Loading…
Reference in a new issue