2023-09-12 12:52:01 +07:00
|
|
|
#!/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;' \
|
2023-09-13 21:42:04 +07:00
|
|
|
-c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
2023-09-14 22:50:26 +07:00
|
|
|
-c '\copy reviews(id,submitted_by,is_from_critic,comments,score,is_hided,location_id) FROM '"'/tmp/reviews.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
2023-09-19 21:48:23 +07:00
|
|
|
-c '\copy images(id,image_url,uploaded_by,image_type,image_of) FROM '"'/tmp/images.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
2023-09-20 12:30:57 +07:00
|
|
|
-c '\copy tags(id,name,submitted_by,target_id,tags_type) FROM '"'/tmp/tags.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
2023-09-12 12:52:01 +07:00
|
|
|
-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;' \
|
2023-09-13 21:42:04 +07:00
|
|
|
-c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
2023-09-14 22:50:26 +07:00
|
|
|
-c '\copy reviews(id,submitted_by,is_from_critic,comments,score,is_hided,location_id) FROM '"'/tmp/reviews.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
2023-09-19 21:48:23 +07:00
|
|
|
-c '\copy images(id,image_url,uploaded_by,image_type,image_of) FROM '"'/tmp/images.csv'"' DELIMITER '"'#'"' CSV HEADER;' \
|
2023-09-20 12:30:57 +07:00
|
|
|
-c '\copy tags(id,name,submitted_by,target_id,tags_type) FROM '"'/tmp/tags.csv'"' DELIMITER '"','"' CSV HEADER;' \
|
2023-09-12 12:52:01 +07:00
|
|
|
-d hiling_dev_test
|
2023-09-13 21:42:04 +07:00
|
|
|
|
|
|
|
# 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))' \
|
2023-09-14 22:50:26 +07:00
|
|
|
-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 &&
|
2023-09-20 12:30:57 +07:00
|
|
|
sudo -u postgres psql \
|
|
|
|
-c 'SELECT setval('"'images_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'images_id_seq'"'))-1 FROM images))' \
|
|
|
|
-d hiling_dev_test &&
|
|
|
|
sudo -u postgres psql \
|
|
|
|
-c 'SELECT setval('"'tags_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'tags_id_seq'"'))-1 FROM tags))' \
|
|
|
|
-d hiling_dev_test &&
|
2023-09-13 21:42:04 +07:00
|
|
|
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))' \
|
2023-09-14 22:50:26 +07:00
|
|
|
-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))' \
|
2023-09-20 12:30:57 +07:00
|
|
|
-d hiling_dev &&
|
|
|
|
sudo -u postgres psql \
|
|
|
|
-c 'SELECT setval('"'images_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'images_id_seq'"'))-1 FROM images))' \
|
|
|
|
-d hiling_dev &&
|
|
|
|
sudo -u postgres psql \
|
|
|
|
-c 'SELECT setval('"'tags_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'tags_id_seq'"'))-1 FROM tags))' \
|
|
|
|
-d hiling_dev
|