barker/import.sh

100 lines
7.7 KiB
Bash
Raw Normal View History

2021-03-18 11:50:48 +00:00
#!/usr/bin/env bash
if [ 2 -ne "$#" ]
then
dbname=petty
docker=0
doname=docker
else
dbname=$2
docker=1
doname=$1
fi
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P )
mkdir "$parent_path"/csv -p || exit
if [ $docker -eq 0 ]
then
scp knox:csv.tar.zip "$parent_path"/csv || exit
fi
if [ $docker -eq 1 ]
then
tar xvf "$parent_path"/csv.tar.zip -C "$parent_path"/csv || exit
else
echo tar xvf "$parent_path"/csv/csv.tar.zip -C "$parent_path"/csv
tar xvf "$parent_path"/csv/csv.tar.zip -C "$parent_path"/csv || exit
fi
if [ $docker -eq 1 ]
then
docker stop "$doname" || exit
fi
docker run -it --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres -c "drop database '"""$dbname"'"' || exit
docker run -it --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres -c "create database '"""$dbname"'"' || exit
docker run -it --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "CREATE EXTENSION btree_gist;"' || exit
if [ $docker -eq 1 ]
then
docker start "$doname" || exit
docker exec -it "$doname" alembic upgrade 8c06ac60d125 || exit
else
cd "$parent_path"/barker || exit
alembic upgrade 8c06ac60d125 || exit
fi
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy roles(id, name) from /mnt/a-Roles.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy permissions(id, name) from /mnt/b-Permissions.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy role_permissions(id, permission_id, role_id) from /mnt/c-RolePermissions.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy users(id, name, password, locked_out) from /mnt/d-Users.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy user_roles(id, user_id, role_id) from /mnt/e-UserRoles.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy customers(id, name, address, phone) from /mnt/f-Customers.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy food_tables(id, name, seats, is_active, section_id, sort_order) from /mnt/g-FoodTables.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy taxes(id, name, rate, is_fixture) from /mnt/h-Taxes.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy menu_categories(id, name, is_active, is_fixture, sort_order) from /mnt/i-MenuCategories.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy sale_categories(id, name, discount_limit, tax_id) from /mnt/j-SaleCategories.csv"'
sed -i 's/\x0//g' "$parent_path"/csv/k-Products.csv
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy products(id, name, units, menu_category_id, sale_category_name, price, has_happy_hour, is_active, is_not_available, sort_order, quantity) from /mnt/k-Products.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy modifiers(id, name, show_in_bill, is_active, modifier_category_id, price) from /mnt/l-Modifiers.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy sections(id, name, is_fixture) from /mnt/m-Sections.csv"'
# sed -i ':a;N;$!ba;s/\n\r\n\r\n\r\n\r\n\r\n\r/\\n\\n\\n\\n\\n\\n/g' "$parent_path"/csv/n-Printers.csv
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy printers(id, name, address, cut_code) from /mnt/n-Printers.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy section_printers(id, menu_category_id, section_name, printer_name, copies) from /mnt/o-SectionPrinters.csv"'
if [ $docker -eq 1 ]
then
docker start "$doname" || exit
docker exec -it "$doname" alembic upgrade 34fe3d061c5f || exit
else
cd "$parent_path"/barker || exit
alembic upgrade 34fe3d061c5f || exit
fi
sed -i 's/\x0/\\N/g' "$parent_path"/csv/p-Vouchers.csv
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy vouchers(id, date, pax, user_id, creation_date, last_edit_date, bill_id, food_table_id, customer_id, narration, reason, voucher_type, kot_id) from /mnt/p-Vouchers.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy kots(id, voucher_id, code, food_table_id, date, user_id) from /mnt/q-Kots.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy inventories(id, kot_id, product_id, sort_order, quantity, price, is_happy_hour, tax_rate, tax_id, discount) from /mnt/r-Inventories.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy inventory_modifiers(id, inventory_id, modifier_id, price) from /mnt/s-InventoryModifiers.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy overview(id, voucher_id, food_table_id, status) from /mnt/t-Overview.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy reprints(id, user_id, date, voucher_id) from /mnt/u-Reprints.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy settings(id, name, data) from /mnt/v-Settings.csv"'
docker run -it -v "$parent_path"/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres '"""$dbname"' -c "\copy settlements(id, voucher_id, settled, amount) from /mnt/w-VoucherSettlements.csv"'
if [ $docker -eq 1 ]
then
docker start "$doname" || exit
docker exec -it "$doname" alembic upgrade 48bc1c7c07ce || exit
else
cd "$parent_path"/barker || exit
alembic upgrade 48bc1c7c07ce || exit
fi
rm -f "$parent_path"/csv/*.csv "$parent_path"/csv/csv.tar.zip || exit
rmdir "$parent_path"/csv || exit
2021-03-18 11:50:48 +00:00
# Show the file in code to see the hidden chars
# od -t c "$parent_path"/Programming/csv/n-Printers.csv