39 lines
2.5 KiB
Bash
Executable File
39 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
cp ./db/csv_seeder/* /tmp/
|
|
sudo -u postgres psql \
|
|
-c '\copy users(id,username,password) FROM '"'/tmp/user.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy regions(id, region_name) FROM '"'/tmp/regions.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy provinces(id, province_name, region_id) FROM '"'/tmp/provinsi.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy regencies(id, province_id, regency_name) FROM '"'/tmp/kabupaten.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
|
-c '\copy reviews(id,submitted_by,is_from_critic,comments,score,is_hided,location_id) FROM '"'/tmp/reviews.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
|
-d hiling_dev &&
|
|
sudo -u postgres psql \
|
|
-c '\copy users(id,username,password) FROM '"'/tmp/user.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy regions(id, region_name) FROM '"'/tmp/regions.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy provinces(id, province_name, region_id) FROM '"'/tmp/provinsi.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy regencies(id, province_id, regency_name) FROM '"'/tmp/kabupaten.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
|
-c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
|
-c '\copy reviews(id,submitted_by,is_from_critic,comments,score,is_hided,location_id) FROM '"'/tmp/reviews.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
|
-d hiling_dev_test
|
|
|
|
# FIXING SEQUENCES AFTER SEEDING
|
|
sudo -u postgres psql \
|
|
-c 'SELECT setval('"'locations_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'locations_id_seq'"'))-1 FROM locations))' \
|
|
-d hiling_dev_test &&
|
|
sudo -u postgres psql \
|
|
-c 'SELECT setval('"'users_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'users_id_seq'"'))-1 FROM users))' \
|
|
-d hiling_dev_test &&
|
|
sudo -u postgres psql \
|
|
-c 'SELECT setval('"'reviews_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'reviews_id_seq'"'))-1 FROM reviews))' \
|
|
-d hiling_dev_test &&
|
|
sudo -u postgres psql \
|
|
-c 'SELECT setval('"'locations_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'locations_id_seq'"'))-1 FROM locations))' \
|
|
-d hiling_dev &&
|
|
sudo -u postgres psql \
|
|
-c 'SELECT setval('"'users_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'users_id_seq'"'))-1 FROM users))' \
|
|
-d hiling_dev &&
|
|
sudo -u postgres psql \
|
|
-c 'SELECT setval('"'reviews_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'reviews_id_seq'"'))-1 FROM reviews))' \
|
|
-d hiling_dev
|