Merge pull request 'HSDB Dump Script' (#9) from hsh-michaelhierweck-hsdb-dump-script into db-migration

Reviewed-on: #9
Reviewed-by: Michael Hoennig <michael.hoennig@hostsharing.net>
This commit is contained in:
Timotheus Pokorra 2024-01-11 09:05:11 +01:00
commit ab281c93a7
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#!/bin/sh
host="127.0.0.1"
port="5432"
dbname="hsh02_hsdb"
username="hsh02_hsdb_readonly"
target="/tmp"
dump() {
sql="copy ($1) to stdout with csv header delimiter ';' quote '\"'"
file="${target}/${2}"
psql --host ${host} --port ${port} --user ${username} --command "${sql}" ${dbname} >"${file}"
}
dump "select bp_id, member_id, member_code, member_since, member_until, member_role, author_contract, nondisc_contract, free, exempt_vat, indicator_vat, uid_vat
from business_partner
order by bp_id" \
"business-partners.csv"
dump "select contact_id, bp_id, salut, first_name, last_name, title, firma, co, street, zipcode, city, country, phone_private, phone_office, phone_mobile, fax, email, array_to_string(array_agg(role), ',') as roles
from contact
left join contactrole_ref using(contact_id)
group by contact_id
order by contact_id" \
"contacts.csv"
dump "select sepa_mandat_id, bp_id, bank_customer, bank_name, bank_iban, bank_bic, mandat_ref, mandat_signed, mandat_since, mandat_until, mandat_used
from sepa_mandat
order by sepa_mandat_id" \
"sepa-mandates.csv"
dump "select member_asset_id, bp_id, date, action, amount, comment
from member_asset
order by member_asset_id" \
"asset-transactions.csv"
dump "select member_share_id, bp_id, date, action, quantity, comment
from member_share
order by member_share_id" \
"share-transactions.csv"