now able to truncate csv according to the database table construct and added some sql files for some commands

master
kerem 3 years ago
parent 808f36b32c
commit 87569a9628

1
.gitignore vendored

@ -15,6 +15,7 @@ learning/rust/*/Cargo.lock
**/*.rs.bk
sql/credentials.sh
# MSVC Windows builds of rustc generate these, which store debugging information

@ -6,38 +6,38 @@ USE minibase_material;
DROP TABLE IF EXISTS products;
CREATE TABLE products (
product_id int(11) NOT NULL COMMENT 'Primary Key for Database referencing',
manufacturer varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'The mane of the manufacturer',
product_no varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'The product No of the manufacturer ',
core_product varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Core product no of the manufacturer ',
ordering_code varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Ordering code from the manufacturer, if it is different than the product no',
description varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'A brief and simple description of the article',
status varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Actual status of the products life cycle',
buy_cost float NOT NULL COMMENT 'our standard buy price.',
pricing_scheme varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'If the manufacturer of the product allows a pricing scheme for this product',
price_change_flag tinyint(1) NOT NULL COMMENT 'did the price changed since the last update ? this flag should be carefully monitored to be sure that every client was informed before resetting it !!!',
currency varchar(6) NOT NULL COMMENT 'The currency with which the manufaturer sells'
lead_time_days int(11) NOT NULL COMMENT 'Actual lead time on this product in days',
physical_form varchar(50) NOT NULL COMMENT 'The physical form of the product. is it a flower ? or is it a box or is it tssop18 packaged IC ?',
packing varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Available packing options for the product, plastic wrap, tray, bulk, reel and so on.',
packing_size int(11) NOT NULL COMMENT 'How many items are there in one packing ? Ex : A basket of 50 tomatoes. ',
minimum_order_quantity int(11) NOT NULL COMMENT 'What is the minimum order quantity that the manufacturer allows. no one will send you only one flower seed. ',
product_id int(11) NOT NULL COMMENT 'Primary Key for Database referencing',
manufacturer varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'The mane of the manufacturer',
product_no varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'The product No of the manufacturer ',
core_product varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Core product no of the manufacturer ',
ordering_code varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Ordering code from the manufacturer, if it is different than the product no',
description varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'A brief and simple description of the article',
status varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Actual status of the products life cycle',
buy_cost float NOT NULL COMMENT 'our standard buy price.',
pricing_scheme varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'If the manufacturer of the product allows a pricing scheme for this product',
price_change_flag tinyint(1) NOT NULL COMMENT 'did the price changed since the last update ? this flag should be carefully monitored to be sure that every client was informed before resetting it !!!',
currency varchar(6) NOT NULL COMMENT 'The currency with which the manufaturer sells',
lead_time_days int(11) NOT NULL COMMENT 'Actual lead time on this product in days',
physical_form varchar(50) NOT NULL COMMENT 'The physical form of the product. is it a flower ? or is it a box or is it tssop18 packaged IC ?',
packing varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Available packing options for the product, plastic wrap, tray, bulk, reel and so on.',
packing_size int(11) NOT NULL COMMENT 'How many items are there in one packing ? Ex : A basket of 50 tomatoes. ',
minimum_order_quantity int(11) NOT NULL COMMENT 'What is the minimum order quantity that the manufacturer allows. no one will send you only one flower seed. ',
minimum_awarding_quantity int(11) NOT NULL COMMENT 'If we support an customer of ours and the manufacturer proposes a special pricing condition for this product. This is the quantity that must be reached before we can be awarded for our efforts in order to get the promised special price. ',
minimum_quote_quantity int(11) NOT NULL COMMENT 'If no special pricing conditions are available, this is the first price break quantity. for the rest a quotation should be asked. ',
proposed_margin int(11) NOT NULL COMMENT 'Margins defined/proposed by the organisation for this article ',
container varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Shipping container form of the packaged product.',
container_size int(11) NOT NULL COMMENT 'How many items are there in one shipping container ? 5 baskets of 50 tomatoes for a total of 250 tomatoes.',
product_class int(11) NOT NULL COMMENT 'Class of product. \r\nThis should be defined by the organisation.',
product_category int(11) NOT NULL COMMENT 'Category of the product. \r\nThis should be linked to the product_categories_table defined by the organisation.',
product_family int(11) NOT NULL COMMENT 'Family of the product. \r\nThis should be defined by the organisation.',
product_group int(11) NOT NULL COMMENT 'Group of the product. \r\nThis should be defined by the organisation.',
last_update_date date NOT NULL COMMENT 'Last date that this product has had an updated field',
last_time_buy_date date NOT NULL COMMENT 'Last time that this product can be purchased',
obsolete_date date NOT NULL COMMENT 'The date since/at which this product will be declared obsolete',
pollution_level varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Depending on the Product some pollution level requirement can be met or not.',
production_site varchar(20) NOT NULL COMMENT 'The production site for this product. This should be linked to the manufacturer profile.',
comment_manufacturer varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Comments fomr the manufaturer'
comment varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Special comments. '
minimum_quote_quantity int(11) NOT NULL COMMENT 'If no special pricing conditions are available, this is the first price break quantity. for the rest a quotation should be asked. ',
proposed_margin int(11) NOT NULL COMMENT 'Margins defined/proposed by the organisation for this article ',
container varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Shipping container form of the packaged product.',
container_size int(11) NOT NULL COMMENT 'How many items are there in one shipping container ? 5 baskets of 50 tomatoes for a total of 250 tomatoes.',
product_class int(11) NOT NULL COMMENT 'Class of product. \r\nThis should be defined by the organisation.',
product_category int(11) NOT NULL COMMENT 'Category of the product. \r\nThis should be linked to the product_categories_table defined by the organisation.',
product_family int(11) NOT NULL COMMENT 'Family of the product. \r\nThis should be defined by the organisation.',
product_group int(11) NOT NULL COMMENT 'Group of the product. \r\nThis should be defined by the organisation.',
last_update_date date NOT NULL COMMENT 'Last date that this product has had an updated field',
last_time_buy_date date NOT NULL COMMENT 'Last time that this product can be purchased',
obsolete_date date NOT NULL COMMENT 'The date since/at which this product will be declared obsolete',
pollution_level varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Depending on the Product some pollution level requirement can be met or not.',
production_site varchar(20) NOT NULL COMMENT 'The production site for this product. This should be linked to the manufacturer profile.',
comment_manufacturer varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Comments fomr the manufaturer',
comment varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Special comments.'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE products

Can't render this file because it is too large.

Can't render this file because it is too large.

@ -0,0 +1,6 @@
#!/bin/bash
source /home/credentials.sh
mysql -h $MARIADB_HOST -u $MARIADB_USER -p$MARIADB_PASS -e "LOAD DATA INFILE '/home/output.csv' IGNORE INTO TABLE minibase_material.products FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES ; SHOW WARNINGS"

@ -0,0 +1,6 @@
#!/bin/bash
source /home/credentials.sh
mysql -h $MARIADB_HOST -u $MARIADB_USER -p$MARIADB_PASS -e "$1"

@ -0,0 +1,5 @@
#!/bin/bash
source /home/credentials.sh
mysql -h $MARIADB_HOST -u $MARIADB_USER -p$MARIADB_PASS "$1" < "$2"

@ -0,0 +1,7 @@
#!/bin/bash
source /home/credentials.sh
COMMAND="$(cat $1)"
mysql -h $MARIADB_HOST -u $MARIADB_USER -p$MARIADB_PASS -e "$COMMAND"

File diff suppressed because it is too large Load Diff

@ -14,71 +14,73 @@ HEADER_STRING=""
LINE_STRING=""
PRODUCTS_ARR=(
"product_id"
"manufacturer"
"product_no"
"core_product"
"ordering_code"
"description"
"status"
"buy_cost"
"pricing_scheme"
"price_change_flag"
"currency"
"lead_time_days"
"physical_form"
"packing"
"packing_size"
"minimum_order_quantity"
"minimum_awarding_quantity"
"minimum_quote_quantity"
"proposed_margin"
"container"
"container_size"
"product_class"
"product_category"
"product_family"
"product_group"
"last_update_date"
"last_time_buy_date"
"obsolete_date"
"pollution_level"
"production_site"
"comment_manufacturer"
"comment")
product_id="NULL"
manufacturer="Infineon"
"product_id"
"manufacturer"
"product_no"
"core_product"
"ordering_code"
"description"
"status"
"buy_cost"
"pricing_scheme"
"price_change_flag"
"currency"
"lead_time_days"
"physical_form"
"packing"
"packing_size"
"minimum_order_quantity"
"minimum_awarding_quantity"
"minimum_quote_quantity"
"proposed_margin"
"container"
"container_size"
"product_class"
"product_category"
"product_family"
"product_group"
"last_update_date"
"last_time_buy_date"
"obsolete_date"
"pollution_level"
"production_site"
"comment_manufacturer"
"comment"
)
product_id=0
manufacturer="Infineon"
product_no=2
core_product=6
ordering_code=1
description=10
status=22
buy_cost=33
pricing_scheme=20
price_change_flag=0
pricing_scheme=20
price_change_flag=0
currency="USD"
lead_time_days=8
physical_form=25
packing=26
packing_size=27
minimum_order_quantity=29
minimum_awarding_quantity=31
packing_size=27
minimum_order_quantity=29
minimum_awarding_quantity=31
minimum_quote_quantity=30
proposed_margin=25
container="none"
container_size=29
product_class=0
product_category=0
product_family=0
container="box"
container_size=29
product_class=0
product_category=0
product_family=0
product_group=0
last_update_date="2022-08-14"
last_time_buy_date="0000-00-00"
last_update_date="2022-08-14"
last_time_buy_date="0000-00-00"
obsolete_date="0000-00-00"
pollution_level=""
pollution_level="RoSh"
production_site="DE"
comment_manufacturer=44
comment="Test Upload"
comment_manufacturer=44
comment="Test Upload"
####################################################################################################
rm output.csv
@ -127,7 +129,8 @@ for i in "${CSV_LINES[@]}";do
if [ $counter -gt 1 ]
then
LINE_STRING+="$product_id,\
LINE_STRING+="\
$product_id,\
$manufacturer,\
${LINE[$product_no]},\
${LINE[$core_product]},\
@ -158,10 +161,14 @@ $obsolete_date,\
$pollution_level,\
$production_site,\
${LINE[$comment_manufacturer]},\
$comment\n"
$comment\
\n"
fi
((counter++))
done
echo -e "$LINE_STRING" >> output.csv
sed -i '$ d' output.csv
sed -i '$ d' output.csv #Delete the last line
####################################################################################################
sshpass -p "$SERVER_USER_PASS" scp output.csv $SERVER_USER_NAME@$SERVER_HOST:$MARIADB_OUTSIDE_DATA

@ -0,0 +1,6 @@
#!/bin/bash
source /home/credentials.sh
mariadb-import -h $MARIADB_HOST -P $MARIADB_PORT -u $MARIADB_USER -p$MARIADB_PASS --fields-terminated-by=, --lines-terminated-by="\n" --ignore-lines=1 --ignore minibase_material /var/tmp/products.csv; SHOW WARNINGS;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save