-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathcreate_db_schema.sql
More file actions
69 lines (60 loc) · 2 KB
/
create_db_schema.sql
File metadata and controls
69 lines (60 loc) · 2 KB
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
create SEQUENCE block_rowid start 1;
create SEQUENCE light_rowid start 1;
create SEQUENCE sign_rowid start 1;
create SEQUENCE block_history_rowid start 1;
create table block (
rowid bigint default nextval('public.block_rowid'::regclass) primary key,
updated_at timestamp,
user_id varchar(64) not null,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null
);
alter table block add constraint unique_block_pqxyz unique (p,q,x,y,z);
create table if not exists light (
rowid bigint default nextval('public.light_rowid'::regclass) primary key,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null
);
create unique index if not exists light_pqxyz_idx on light (p, q, x, y, z);
create table if not exists sign (
rowid bigint default nextval('public.sign_rowid'::regclass) primary key,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
face int not null,
text text not null
);
create index if not exists sign_pq_idx on sign (p, q);
create unique index if not exists sign_xyzface_idx on sign (x, y, z, face);
create table if not exists block_history (
rowid bigint default nextval('public.block_history_rowid'::regclass),
created_at timestamp,
user_id varchar(64) not null,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null,
primary key (rowid,created_at)
) partition by range (created_at);
CREATE SCHEMA partman;
CREATE EXTENSION pg_partman WITH SCHEMA partman;
SELECT partman.create_parent( p_parent_table => 'public.block_history',
p_control => 'created_at',
p_type => 'native',
p_interval=> 'monthly',
p_premake => 24);
create table user_recent_pos(updated_at timestamp,user_id varchar(64) not null,x int not null,y int not null,z int not null);
alter table user_recent_pos add constraint unique_username unique (user_id);
alter table auth_app_user add constraint unique_authappusername unique (username);