-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb_init.sql
59 lines (46 loc) · 1.81 KB
/
db_init.sql
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
create database scooter_scrapper;
CREATE TABLE scooter_position_logs (
city VARCHAR(100) NOT NULL,
provider VARCHAR(100) NOT NULL,
scooter_id VARCHAR(100) NULL,
secondary_id VARCHAR(100) NULL,
location POINT NOT NULL,
timestamp TIMESTAMP NOT NULL,
battery_level VARCHAR(50) NULL,
licence_plate VARCHAR(50) NULL
);
create index scooter_index_alpha on scooter_position_logs_alpha (city, provider, scooter_id);
CREATE TABLE scooter_position_logs (
battery_level VARCHAR(50) NULL,
city VARCHAR(100) NOT NULL,
scooter_id VARCHAR(100) NULL,
lat FLOAT8 NOT NULL,
licence_plate VARCHAR(50) NULL,
lng FLOAT8 NOT NULL,
provider VARCHAR(100) NOT NULL,
secondary_id VARCHAR(100) NULL,
timestamp TIMESTAMP NOT NULL
);
CREATE TABLE new_spl (
battery_level VARCHAR(50) NULL,
city VARCHAR(100) NOT NULL,
scooter_id VARCHAR(100) NULL,
lat FLOAT8 NOT NULL,
licence_plate VARCHAR(50) NULL,
lng FLOAT8 NOT NULL,
provider VARCHAR(100) NOT NULL,
secondary_id VARCHAR(100) NULL,
timestamp TIMESTAMP NOT NULL
);
create index scooter_index_alpha on scooter_position_logs_alpha (city, provider, scooter_id);
INSERT INTO scooter_position_logs_alpha (battery_level,city,scooter_id,lat,licence_plate,lng,provider,secondary_id,timestamp)
SELECT battery_level,city,scooter_id, location[1]lat,licence_plate, location[0] lng,provider,secondary_id,timestamp FROM scooter_position_logs
where timestamp < '2019-11-01' and timestamp >= '2019-10-01';
-- on server creating user for observableHQ
CREATE USER observable WITH PASSWORD 'this is my very strong password';
GRANT CONNECT ON DATABASE scooter_scrapper TO observable;
GRANT USAGE ON SCHEMA public TO observable;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO observable;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT ON TABLES TO observable;
CREATE EXTENSION tablefunc;