-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg-init.sql
118 lines (89 loc) · 2.08 KB
/
pg-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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
-- DROP SCHEMA test;
CREATE SCHEMA test;
ALTER SCHEMA test owner to test;
-- test.testUser definition
-- Drop table
-- DROP TABLE test.test_user;
CREATE TABLE test.test_user
(
uid bigint not null
CONSTRAINT test_user_pk
PRIMARY KEY,
username varchar(100),
password varchar(100) not null
);
ALTER TABLE test.test_user owner to test;
-- Insert test data
INSERT INTO test.test_user (uid, username, "password") VALUES (0, 'user1', 'password');
INSERT INTO test.test_user (uid, username, "password") VALUES (1, 'hello world', 'p@ssword');
INSERT INTO test.test_user (uid, username, "password") VALUES (2, 'user2', 'test_pass');
-- test.test_session definition
-- Drop table
-- DROP TABLE test.test_session;
CREATE TABLE test.test_session
(
uid bigint,
sid bigint,
nonce bytea,
data jsonb,
ip inet,
user_agent varchar,
create_time bigint,
update_time bigint,
expire_time bigint,
CONSTRAINT test_session_pk
UNIQUE (uid, sid)
);
ALTER TABLE test.test_session owner to test;
CREATE TABLE test.student
(
uid bigint not null
CONSTRAINT student_pk_uid
PRIMARY KEY,
username varchar(100)
CONSTRAINT student_pk_username
UNIQUE,
nickname varchar(100),
email varchar(100),
create_time bigint,
update_time bigint
);
ALTER TABLE test.student owner to test;
-- DROP SCHEMA demo_pg;
CREATE SCHEMA demo_pg;
ALTER SCHEMA demo_pg owner to test;
-- demo_pg.session definition
-- Drop table
-- DROP TABLE demo_pg.session;
CREATE TABLE demo_pg.session
(
uid bigint,
sid bigint,
nonce bytea,
data jsonb,
ip inet,
user_agent varchar,
create_time bigint,
update_time bigint,
expire_time bigint,
CONSTRAINT test_session_pk
UNIQUE (uid, sid)
);
ALTER TABLE demo_pg.session owner to test;
-- demo_pg.user definition
-- Drop table
-- DROP TABLE demo_pg.user;
CREATE TABLE demo_pg.user
(
uid bigint not null
CONSTRAINT user_pk_uid
PRIMARY KEY,
username varchar(100)
CONSTRAINT user_pk_username
UNIQUE,
nickname varchar(100),
email varchar(100),
create_time bigint,
update_time bigint
);
ALTER TABLE demo_pg.user owner to test;