-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathinitPg.js
87 lines (74 loc) · 1.82 KB
/
initPg.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const sql = `
drop schema if exists custom cascade;
drop schema if exists public cascade;
create schema public;
create schema custom;
CREATE TABLE datetest (
id SERIAL PRIMARY KEY,
"date" DATE,
tdatetime TIMESTAMP,
tdatetime_tz TIMESTAMP WITH TIME ZONE
);
INSERT INTO datetest ("date", tdatetime, tdatetime_tz)
VALUES ('2023-07-14 12:00:00+09:00', '2023-07-14 12:00:00+09:00', '2023-07-14 12:00:00-08:00');
CREATE TABLE customer (
id SERIAL PRIMARY KEY,
name TEXT,
balance NUMERIC,
"isActive" BOOLEAN,
data JSONB,
picture BYTEA
);
CREATE TABLE vendor (
id NUMERIC PRIMARY KEY,
name TEXT,
balance NUMERIC,
"isActive" BOOLEAN
);
CREATE TABLE "order" (
id SERIAL PRIMARY KEY,
"orderDate" TIMESTAMP,
"customerId" INTEGER REFERENCES customer
);
CREATE TABLE "orderLine" (
id SERIAL PRIMARY KEY,
"orderId" INTEGER REFERENCES "order",
product TEXT,
amount NUMERIC(10,2) NULL
);
CREATE TABLE "compositeOrder" (
"companyId" VARCHAR(10),
"orderNo" numeric,
PRIMARY KEY ("companyId","orderNo")
);
CREATE TABLE "compositeOrderLine" (
"companyId" VARCHAR(10),
"orderNo" numeric,
"lineNo" numeric,
"product" varchar(40),
PRIMARY KEY ("companyId","orderNo", "lineNo"));
CREATE TABLE package (
"packageId" SERIAL PRIMARY KEY,
"lineId" INTEGER REFERENCES "orderLine",
sscc TEXT
);
CREATE TABLE "deliveryAddress" (
id SERIAL PRIMARY KEY,
"orderId" INTEGER REFERENCES "order",
name TEXT,
street TEXT,
"postalCode" TEXT,
"postalPlace" TEXT,
"countryCode" TEXT
);
CREATE TABLE custom."withSchema" (
id SERIAL PRIMARY KEY,
name TEXT
)
`;
module.exports = async function(db) {
const statements = sql.split(';');
for (let i = 0; i < statements.length; i++) {
await db.query(statements[i]);
}
};