-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
40 lines (35 loc) · 892 Bytes
/
init.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
const sql = `
DROP TABLE if exists orderLine;
DROP TABLE if exists deliveryAddress;
DROP TABLE if exists _order;
DROP TABLE if exists customer;
CREATE TABLE customer (
id int IDENTITY(1,1) PRIMARY KEY,
name VARCHAR(100),
balance NUMERIC,
isActive BIT
);
CREATE TABLE _order (
id int IDENTITY(1,1) PRIMARY KEY,
orderDate DATETIME,
customerId INTEGER REFERENCES customer
);
CREATE TABLE orderLine (
id int IDENTITY(1,1) PRIMARY KEY,
orderId INTEGER REFERENCES _order,
product VARCHAR(100),
amount NUMERIC DEFAULT(0)
);
CREATE TABLE deliveryAddress (
id int IDENTITY(1,1) PRIMARY KEY,
orderId INTEGER REFERENCES _order,
name VARCHAR(100),
postalPlace VARCHAR(100)
)
`;
export default async function(db) {
const statements = sql.split(';');
for (let i = 0; i < statements.length; i++) {
await db.query(statements[i]);
}
};