Skip to content

Commit

Permalink
Save export script (#3448)
Browse files Browse the repository at this point in the history
  • Loading branch information
thbar authored Sep 11, 2023
1 parent af989b9 commit 2ccb1ed
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/contacts/contact_export.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! mix run

import Ecto.Query

# NOTE: for now, edit Transport.Vault and temporarily inject the production `CLOAK_KEY` value to decrypt email
# NOTE: in `restore_db.sh`, make sure to uncomment `Truncating contact table` line when restoring a backup!

# DB.Contact.__schema__(:fields)
# |> IO.inspect(IEx.inspect_opts())

rows =
from(DB.Contact)
|> select([c], map(c, [:id, :first_name, :last_name, :job_title, :organization, :email]))
|> order_by([{:asc, :id}])
|> DB.Repo.all()
|> CSV.encode(headers: true)
|> Enum.into([])

File.write!("data.csv", rows)

0 comments on commit 2ccb1ed

Please sign in to comment.