aboutsummaryrefslogtreecommitdiff
path: root/schema.sql
blob: f1d33fc9c211dea4947dc870ecc74ee41b4f5300 (plain)
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
-- Database schema version 3

pragma foreign_keys = on;

create table Meta (
	version integer
);

create table Rooms (
	id integer primary key not null,
	name text not null
);
create unique index rooms_name_index on Rooms(name);

create table Members (
	room integer not null,
	user integer not null,
	primary key(room, user),
	foreign key(room) references Rooms(id) on delete cascade,
	foreign key(user) references Users(id) on delete cascade
);
create index members_user_index on Members(user);

create table Users (
	id integer primary key not null,
	name text not null,
	passhash text not null
);
create unique index users_name_index on Users(name);

create table Messages (
	id integer primary key autoincrement not null,
	room integer not null,
	user integer null,
	time integer not null,
	reply integer null,
	message blob,
	foreign key(room) references Rooms(id) on delete cascade,
	foreign key(user) references Users(id) on delete set null,
	foreign key(reply) references Messages(id) on delete set null
);
create index messages_time_index on Messages(room, time desc);

create table Firebase (
	user integer not null,
	token text not null,
	foreign key(user) references Users(id) on delete cascade
);
create index firebase_user_index on Firebase(user);