-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload_ip2loc_data.sh
executable file
·27 lines (23 loc) · 1.01 KB
/
upload_ip2loc_data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
set -e
eval $(grep -v -e '^#' ./config/assetdb.env | xargs -I {} echo export \'{}\')
# insert data from the CSV files within the ip2location database
PGPASSWORD=$AMASS_PASSWORD psql -v ON_ERROR_STOP=1 -h localhost -U "$AMASS_USER" --dbname ip2location <<-EOSQL
DROP TABLE IF EXISTS ip_geo;
CREATE TABLE ip_geo (
ip_from DECIMAL(39,0) NOT NULL,
ip_to DECIMAL(39,0) NOT NULL,
country_code CHAR(2) NOT NULL,
country_name VARCHAR(64) NOT NULL,
region_name VARCHAR(128) NOT NULL,
city_name VARCHAR(128) NOT NULL,
latitude VARCHAR(20) NOT NULL,
longitude VARCHAR(20) NOT NULL,
zip_code VARCHAR(30) NULL DEFAULT NULL,
time_zone VARCHAR(8) NULL DEFAULT NULL,
CONSTRAINT idx_key PRIMARY KEY (ip_to)
);
\copy ip_geo from 'IP2LOCATION-LITE-DB11.CSV' with (format 'csv', quote '"')
\copy ip_geo from 'IP2LOCATION-LITE-DB11.IPV6.CSV' with (format 'csv', quote '"')
CREATE INDEX ip_from_number ON ip_geo(ip_from);
EOSQL