-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-config.sql
More file actions
58 lines (51 loc) · 1.95 KB
/
db-config.sql
File metadata and controls
58 lines (51 loc) · 1.95 KB
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
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `accounts`;
CREATE TABLE `accounts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`name` varchar(16) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `user_id_name` (`user_id`,`name`),
KEY `user_id` (`user_id`),
CONSTRAINT `accounts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `sessions`;
CREATE TABLE `sessions` (
`session_key` char(32) NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`last_accessed` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`description` text NOT NULL,
PRIMARY KEY (`session_key`),
KEY `user_id` (`user_id`),
CONSTRAINT `sessions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `transactions`;
CREATE TABLE `transactions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`account_id` int(10) unsigned NOT NULL,
`date` date NOT NULL,
`title` varchar(32) NOT NULL,
`location` varchar(32) NOT NULL,
`amount` float NOT NULL,
`category` varchar(32) DEFAULT NULL,
`note` varchar(64) DEFAULT NULL,
`linked_transaction` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `account_id` (`account_id`),
KEY `linked_transaction` (`linked_transaction`),
CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
CONSTRAINT `transactions_ibfk_2` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(16) NOT NULL,
`password` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;