summaryrefslogtreecommitdiff
path: root/migrations/20241017005219_retain_deleted.sql
blob: aed87f4e2ebdafe219506834d5b6322e14ab22eb (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
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
alter table channel
rename to old_channel;

alter table message
rename to old_message;

create table channel (
	id text
		not null
		primary key,
	name text
		null
		unique,
	created_sequence bigint
		unique
		not null,
	created_at text
		not null
);

insert into channel (id, name, created_sequence, created_at)
select id, name, created_sequence, created_at from old_channel;

create table channel_deleted (
	id text
		not null
		primary key
		references channel (id),
	deleted_sequence bigint
		unique
		not null,
	deleted_at text
		not null
);

create table message (
	id text
		not null
		primary key,
	channel text
		not null
		references channel (id),
	sender text
		not null
		references login (id),
	sent_sequence bigint
		unique
		not null,
	sent_at text
		not null,
	body text
		null
);

insert into message (id, channel, sender, sent_sequence, sent_at, body)
select id, channel, sender, sent_sequence, sent_at, body from old_message;

create table message_deleted (
	id text
		not null
		primary key
		references message (id),
	deleted_sequence bigint
		unique
		not null,
	deleted_at text
		not null
);

drop table old_message;
drop table old_channel;

create index message_sent_at
on message (sent_at);

create index channel_created_at
on channel (created_at);