-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinitDB.js
46 lines (36 loc) · 1.13 KB
/
initDB.js
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
require('dotenv').config();
const { Pool } = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
async function initDB() {
const query = `
SET TIME ZONE 'UTC';
-- Table: transactions
DROP INDEX IF EXISTS idx_transactions_timestamp;
DROP TABLE IF EXISTS transactions;
CREATE TABLE transactions
(
"block" numeric,
"txid" text COLLATE pg_catalog."default" NOT NULL,
"timestamp" timestamp with time zone NOT NULL,
"symbol" text COLLATE pg_catalog."default" NOT NULL,
"from" text COLLATE pg_catalog."default" NOT NULL,
"from_type" text COLLATE pg_catalog."default" NOT NULL,
"to" text COLLATE pg_catalog."default" NOT NULL,
"to_type" text COLLATE pg_catalog."default" NOT NULL,
"memo" text COLLATE pg_catalog."default" NULL,
"quantity" numeric,
CONSTRAINT transactions_pkey PRIMARY KEY (txid)
)
WITH (
OIDS = FALSE
);
-- Index: idx_transactions_timestamp
CREATE INDEX IF NOT EXISTS idx_transactions_timestamp
ON transactions USING btree
("timestamp");`;
await pool.query(query);
pool.end();
}
initDB();