-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.sql
92 lines (74 loc) · 2.72 KB
/
tables.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
CREATE DATABASE depenses
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE depenses;
CREATE TABLE `expenditure` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`amount` double NOT NULL,
`date` datetime NOT NULL,
`comment` text NOT NULL,
`title` varchar(256) NOT NULL,
`team_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `team` (
`id` int(11) NOT NULL,
`name` varchar(256) NOT NULL,
`description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `transaction` (
`id` int(11) NOT NULL,
`from_user` int(11) NOT NULL,
`to_user` int(11) NOT NULL,
`amount` double NOT NULL,
`comment` varchar(256) DEFAULT '',
`date` datetime NOT NULL,
`team_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` varchar(256) NOT NULL,
`password` varchar(256) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `users_by_teams` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`team_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `expenditure`
ADD PRIMARY KEY (`id`),
ADD KEY `user_id` (`user_id`),
ADD KEY `team_id` (`team_id`);
ALTER TABLE `team`
ADD PRIMARY KEY (`id`);
ALTER TABLE `transaction`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_transaction_user_id_from` (`from_user`),
ADD KEY `fk_transaction_user_id_to` (`to_user`),
ADD KEY `fk_transaction_team_id` (`team_id`);
ALTER TABLE `user`
ADD PRIMARY KEY (`id`);
ALTER TABLE `users_by_teams`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `user_id` (`user_id`,`team_id`),
ADD KEY `fk_users_by_teams_team_id` (`team_id`);
ALTER TABLE `expenditure`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `team`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `transaction`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `user`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `users_by_teams`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `expenditure`
ADD CONSTRAINT `fk_expenditure_team_id` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`),
ADD CONSTRAINT `fk_expenditure_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
ALTER TABLE `transaction`
ADD CONSTRAINT `fk_transaction_team_id` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`),
ADD CONSTRAINT `fk_transaction_user_id_from` FOREIGN KEY (`from_user`) REFERENCES `user` (`id`),
ADD CONSTRAINT `fk_transaction_user_id_to` FOREIGN KEY (`to_user`) REFERENCES `user` (`id`);
ALTER TABLE `users_by_teams`
ADD CONSTRAINT `fk_users_by_teams_team_id` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`),
ADD CONSTRAINT `fk_users_by_teams_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);