summaryrefslogtreecommitdiff
path: root/sql/ddl/mysql.sql
blob: 47315f9d5e957e43d27b117f276af15f08067a13 (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
create table users
(
    id          INTEGER      not null
        primary key,
    name        VARCHAR(50)  not null
        unique,
    pwd         VARCHAR(255) not null,
    description VARCHAR(100)
);

create table categories
(
    id        INTEGER     not null
        primary key,
    name      VARCHAR(50) not null,
    parent_id INTEGER
        references categories,
    user_id   INTEGER     not null
        references users
);

create table const_expenses
(
    id          INTEGER        not null
        primary key,
    description VARCHAR(50),
    expense     NUMERIC(10, 2) not null,
    months      SMALLINT       not null,
    start       DATE           not null,
    end         DATE           not null,
    prev_id     INTEGER
        references const_expenses,
    user_id     INTEGER        not null
        references users,
    category_id INTEGER        not null
        references categories
);

create index idx_start_end
    on const_expenses (user_id, start, end);

create index ix_constexpense_end
    on const_expenses (end);

create index ix_constexpense_start
    on const_expenses (start);

create table single_expenses
(
    id          INTEGER        not null
        primary key,
    description VARCHAR(50),
    expense     NUMERIC(10, 2) not null,
    year        INTEGER        not null,
    month       SMALLINT       not null,
    day         SMALLINT       not null,
    user_id     INTEGER        not null
        references users,
    category_id INTEGER        not null
        references categories
);

create index idx_single_date
    on single_expenses (user_id, year, month);