-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
73 lines (60 loc) · 2.16 KB
/
schema.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
PRAGMA foreign_keys = ON;
-- -----------------------------------------------------
-- Table `chat`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `chat` (
`chat_id` TEXT NOT NULL PRIMARY KEY,
`telegram_chat_id` TEXT NOT NULL UNIQUE
);
-- -----------------------------------------------------
-- Table `event_type`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `event_type` (
`event_type` TEXT NOT NULL PRIMARY KEY
);
INSERT INTO `event_type` (`event_type`)
VALUES
('birthday'),
('nameday'),
('wedding anniversary');
-- -----------------------------------------------------
-- Table `event`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `event` (
`event_id` TEXT NOT NULL PRIMARY KEY,
`event_type` TEXT NOT NULL,
`year` INTEGER,
`month` INTEGER NOT NULL,
`day` INTEGER NOT NULL,
FOREIGN KEY (`event_type`) REFERENCES `event_type` (`event_type`)
);
-- -----------------------------------------------------
-- Table `chat_event`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `chat_event` (
`chat_id` TEXT NOT NULL,
`event_id` TEXT NOT NULL,
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`chat_id`),
FOREIGN KEY (`event_id`) REFERENCES `event` (`event_id`)
);
CREATE UNIQUE INDEX IF NOT EXISTS `chat_id_event_id_UNIQUE`
ON `chat_event` (`chat_id`, `event_id`);
-- -----------------------------------------------------
-- Table `person`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `person` (
`person_id` TEXT NOT NULL PRIMARY KEY
`name` TEXT NOT NULL,
`surname` TEXT
);
-- -----------------------------------------------------
-- Table `event_person`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `event_person` (
`event_id` TEXT NOT NULL,
`person_id` TEXT NOT NULL,
FOREIGN KEY (`event_id`) REFERENCES `event` (`event_id`),
FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`)
);
CREATE UNIQUE INDEX IF NOT EXISTS `event_id_person_id_UNIQUE`
ON `event_person` (`event_id`, `person_id`);