~aleteoryx/muditaos

ref: 25250fc9c8730d958eb4b7417bac2be0686a6eaf muditaos/image/user/db/sms_001.sql -rw-r--r-- 1.2 KiB
25250fc9 — Tomasz Rybarski [BH-1314] Home Screen Layouts Selectable 4 years ago
                                                                                
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
-- Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-- For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

CREATE TABLE IF NOT EXISTS sms
(
    _id        INTEGER PRIMARY KEY,
    thread_id  INTEGER,
    contact_id INTEGER,
    date       INTEGER,
    error_code INTEGER,
    body       TEXT NOT_NULL,
    type       INTEGER,
    FOREIGN KEY (thread_id) REFERENCES threads (_id) ON DELETE CASCADE
);
-- sms.contact_id should not be used.

CREATE TABLE IF NOT EXISTS templates
(
    _id                INTEGER PRIMARY KEY,
    text               TEXT,
    lastUsageTimestamp INTEGER
);

CREATE TABLE IF NOT EXISTS threads
(
    _id        INTEGER PRIMARY KEY,
    date       INTEGER,
    msg_count  INTEGER,
    read       INTEGER,
    contact_id INTEGER,
    number_id  INTEGER,
    snippet    TEXT NOT NULL,
    last_dir   INTEGER
);
-- threads.contact_id should not be used.

CREATE TABLE IF NOT EXISTS threads_count
(
    _id   INTEGER PRIMARY KEY,
    count INTEGER
);

CREATE TRIGGER IF NOT EXISTS on_thread_insert AFTER INSERT ON threads BEGIN UPDATE threads_count SET count=count+1 WHERE _id=1; END;
CREATE TRIGGER IF NOT EXISTS on_thread_remove AFTER DELETE ON threads BEGIN UPDATE threads_count SET count=count-1 WHERE _id=1; END;