-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1119 from OpenFn/audit_trail
for #271, set up audit_events
- Loading branch information
Showing
12 changed files
with
199 additions
and
64 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
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
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
41 changes: 41 additions & 0 deletions
41
priv/repo/migrations/20230916052400_change_credentials_audit_to_audit_events.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,41 @@ | ||
defmodule Lightning.Repo.Migrations.ChangeCredentialsAuditToAuditEvents do | ||
use Ecto.Migration | ||
|
||
def up do | ||
rename_index(from: "credentials_audit_pkey", to: "audit_events_pkey") | ||
rename_index(from: "credentials_audit_row_id_index", to: "audit_events_item_id_index") | ||
drop constraint("credentials_audit", "credentials_audit_actor_id_fkey") | ||
|
||
rename table("credentials_audit"), :row_id, to: :item_id | ||
rename table("credentials_audit"), :metadata, to: :changes | ||
create index("credentials_audit", [:actor_id]) | ||
|
||
rename table(:credentials_audit), to: table(:audit_events) | ||
|
||
alter table("audit_events") do | ||
add :item_type, :string, default: "credential" | ||
end | ||
end | ||
|
||
defp rename_constraint(table, from: from, to: to) do | ||
execute( | ||
""" | ||
ALTER TABLE #{table} RENAME CONSTRAINT "#{from}" TO "#{to}"; | ||
""", | ||
""" | ||
ALTER TABLE #{table} RENAME CONSTRAINT "#{to}" TO "#{from}"; | ||
""" | ||
) | ||
end | ||
|
||
defp rename_index(from: from, to: to) do | ||
execute( | ||
""" | ||
ALTER INDEX #{from} RENAME TO #{to}; | ||
""", | ||
""" | ||
ALTER INDEX #{to} RENAME TO #{from}; | ||
""" | ||
) | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
priv/repo/migrations/20230916055521_remove_defauilt_item_type_for_audit_events.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,9 @@ | ||
defmodule Lightning.Repo.Migrations.RemoveDefauiltItemTypeForAuditEvents do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:audit_events) do | ||
modify(:item_type, :string, default: nil, null: false) | ||
end | ||
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
Oops, something went wrong.