-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprovision.js
34 lines (33 loc) · 1.09 KB
/
provision.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
const sqlScript = `
CREATE TABLE IF NOT EXISTS "users" (
"id" serial primary key,
"name" character varying(255) NOT NULL,
"email" character varying(255) NOT NULL,
"registration_timestamp" timestamp without time zone NOT NULL,
"secret" character varying(255) NOT NULL,
"rfid" "text"
);
CREATE TYPE payment_status AS ENUM ('confirmed', 'pending', 'declined');
CREATE TABLE IF NOT EXISTS "payments" (
"id" serial NOT NULL primary key,
"user_id" integer NOT NULL references users(id),
"amount_cents" integer NOT NULL,
"timestamp" timestamp without time zone NOT NULL,
"status" payment_status DEFAULT 'pending' NOT NULL
);
CREATE TABLE IF NOT EXISTS "purchases" (
"id" serial NOT NULL primary key,
"user_id" integer NOT NULL references users(id),
"price_cents" integer NOT NULL,
"timestamp" timestamp without time zone NOT NULL
);`;
const Client = require('./services/databaseService.js');
Client.query({
text: sqlScript,
})
.then(function() {
console.log('successful, press ctrl-c');
})
.catch(function(err) {
console.error('PROVISION ABORTED!', err);
});