-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove config field usage (#2168)
* feat: remove config field usage * feat: nilify config columns migration
- Loading branch information
Showing
5 changed files
with
40 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
priv/repo/migrations/20240808172408_nilify_config_column_for_backends_table.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Logflare.Repo.Migrations.NilifyConfigColumnForBackendsTable do | ||
use Ecto.Migration | ||
import Ecto.Query | ||
alias Logflare.Ecto.EncryptedMap | ||
|
||
def up do | ||
from(b in "backends", update: [set: [config: nil]]) | ||
|> Logflare.Repo.update_all([]) | ||
end | ||
|
||
def down do | ||
{:ok, pid} = Logflare.Vault.start_link() | ||
|
||
# copy configs over | ||
Logflare.Repo.all(from b in "backends", select: [:id, :config_encrypted]) | ||
|> Enum.each(fn %{id: id} = backend -> | ||
{:ok, config} = EncryptedMap.load(backend.config_encrypted) | ||
|
||
from(b in "backends", | ||
where: b.id == ^id, | ||
update: [set: [config: ^config]] | ||
) | ||
|> Logflare.Repo.update_all([]) | ||
end) | ||
# stop the vault | ||
Process.unlink(pid) | ||
Process.exit(pid, :kill) | ||
:timer.sleep(100) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters