Made the import script more versatile

This commit is contained in:
Amritanshu Agrawal 2021-03-18 17:20:48 +05:30
parent 1163989866
commit 52943c7ee0
4 changed files with 102 additions and 70 deletions

View File

@ -1,28 +0,0 @@
"\Program Files\PostgreSQL\11\bin\dropdb.exe" -U postgres petty
"\Program Files\PostgreSQL\11\bin\createdb.exe" -U postgres petty
..\env\Scripts\initdb.exe ..\development.ini
..\env\Scripts\fixtures.exe ..\development.ini
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\a-Roles.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\b-Permissions.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\c-RolePermissions.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\d-Users.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\e-UserRoles.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\f-Customers.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\g-FoodTables.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\h-Taxes.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\i-MenuCategories.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\j-SaleCategories.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\k-Products.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\l-Modifiers.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\m-Sections.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\n-Printers.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\o-SectionPrinters.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\p-Vouchers.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\q-Kots.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\r-Inventories.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\s-InventoryModifiers.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\t-Overview.sql
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\u-ProductGroupModifiers.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\v-Reprints.sql
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\w-Settings.sql
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\x-VoucherSettlements.sql

View File

@ -1,40 +0,0 @@
#!/usr/bin/env bash
#scp knox:csv.tar.zip /home/tanshu/Programming/csv
cd /home/tanshu/Programming/csv
#tar xvf csv.tar.zip
docker run -it --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres -c "drop database petty"'
docker run -it --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres -c "create database petty"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "CREATE EXTENSION btree_gist;"'
cd /home/tanshu/Programming/barker/barker
alembic upgrade 8c06ac60d125
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy roles(id, name) from /mnt/a-Roles.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy permissions(id, name) from /mnt/b-Permissions.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy role_permissions(id, permission_id, role_id) from /mnt/c-RolePermissions.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy users(id, name, password, locked_out) from /mnt/d-Users.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy user_roles(id, user_id, role_id) from /mnt/e-UserRoles.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy customers(id, name, address, phone) from /mnt/f-Customers.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy food_tables(id, name, seats, is_active, section_id, sort_order) from /mnt/g-FoodTables.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy taxes(id, name, rate, is_fixture) from /mnt/h-Taxes.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy menu_categories(id, name, discount_limit, is_active, is_fixture, sort_order) from /mnt/i-MenuCategories.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy sale_categories(id, name, tax_id) from /mnt/j-SaleCategories.csv"'
sed -i 's/\x0//g' ~/Programming/csv/k-Products.csv
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -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 /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy modifiers(id, name, show_in_bill, is_active, modifier_category_id, price) from /mnt/l-Modifiers.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -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' /home/tanshu/Programming/csv/n-Printers.csv
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy printers(id, name, address, cut_code) from /mnt/n-Printers.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy section_printers(id, menu_category_id, section_name, printer_name, copies) from /mnt/o-SectionPrinters.csv"'
alembic upgrade 34fe3d061c5f
sed -i 's/\x0/\\N/g' ~/Programming/csv/p-Vouchers.csv
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -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 /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy kots(id, voucher_id, code, food_table_id, date, user_id) from /mnt/q-Kots.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -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 /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy inventory_modifiers(id, inventory_id, modifier_id, price) from /mnt/s-InventoryModifiers.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy overview(id, voucher_id, food_table_id, status) from /mnt/t-Overview.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy reprints(id, user_id, date, voucher_id) from /mnt/u-Reprints.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy settings(id, name, data) from /mnt/v-Settings.csv"'
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy settlements(id, voucher_id, settled, amount) from /mnt/w-VoucherSettlements.csv"'
alembic upgrade 48bc1c7c07ce
# Show the file in code to see the hidden chars
# od -t c ~/Programming/csv/n-Printers.csv

View File

@ -12,7 +12,7 @@ call:copyQuery j-SaleCategories "SELECT newid(), pgo.GroupType, 1, CAST((select
call:copyQuery k-Products "SELECT ProductID, Name, COALESCE(Units, '\N'), ProductGroupID, (SELECT GroupType FROM Test.dbo.ProductGroups pgs WHERE pgs.ProductGroupID = Products.ProductGroupID), Price, CASE WHEN HasHappyHour = 1 THEN 't' ELSE 'f' END , CASE WHEN IsActive = 1 THEN 't' ELSE 'f' END, CASE WHEN IsNotAvailable = 1 THEN 't' ELSE 'f' END, SortOrder, Quantity FROM Test.dbo.Products;"
call:copyQuery l-Modifiers "SELECT ModifierID, Name, CASE WHEN ShowInBill = 1 THEN 't' ELSE 'f' END, 't', 'e046ad33-dc65-4c78-8833-c3d3538d44c0', Price FROM Test.dbo.Modifiers;"
call:copyQuery m-Sections "SELECT NewID(), Location, 'f' FROM Test.dbo.PrintLocations GROUP BY Location;"
call:copyQuery n-Printers "SELECT NewID(), Printer, Printer, CutCode FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
call:copyQuery n-Printers "SELECT NewID(), Printer, Printer, 0x1d764103 FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
call:copyQuery o-SectionPrinters "SELECT PrintLocationID, COALESCE(CAST(ProductGroupID AS Nvarchar(36)), '\N'), Location, Printer, Copies FROM Test.dbo.PrintLocations;"
call:copyQuery p-Vouchers "SELECT VoucherID, Date, Pax, UserID, CreationDate, LastEditDate, COALESCE(CAST(BillID AS Nvarchar(36)), '\N'), TableID, CustomerID, COALESCE(Narration, '\N'), VoidReason, CASE WHEN Printed = 0 THEN '0' WHEN Void = 1 THEN '5' ELSE VoucherType END, KotID FROM Test.dbo.Vouchers;"
call:copyQuery q-Kots "SELECT KotID, VoucherID, Code, TableID, Date, UserID FROM Test.dbo.Kots;"
@ -20,7 +20,7 @@ call:copyQuery r-Inventories "SELECT InventoryID, KotID, ProductID, SortOrder, Q
call:copyQuery s-InventoryModifiers "SELECT InventoryModifierID, InventoryID, ModifierID, 0 FROM Test.dbo.InventoryModifiers;"
call:copyQuery t-Overview "SELECT newid(), VoucherID, FoodTableID, Status FROM Test.dbo.FoodTables WHERE VoucherID IS NOT NULL;"
call:copyQuery u-Reprints "SELECT ReprintID, UserID, Date, VoucherID FROM Test.dbo.Reprints;"
call:copyQuery v-Settings "SELECT SettingID, Name, Details FROM Test.dbo.Settings;"
call:copyQuery v-Settings "SELECT SettingID, Name, '{""Text"": ""' + Details + '""}' FROM Test.dbo.Settings;"
call:copyQuery w-VoucherSettlements "SELECT VoucherSettlementID, VoucherID, Settled, Amount FROM Test.dbo.VoucherSettlements;"
goto:eof

100
import.sh Executable file
View File

@ -0,0 +1,100 @@
#!/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 "$parent_path"/csv/*.csv "$parent_path"/csv/csv.tar.zip || exit
#rmdir "$parent_path"/csv || exit
# Show the file in code to see the hidden chars
# od -t c "$parent_path"/Programming/csv/n-Printers.csv