/
setup.rb
75 lines (72 loc) · 2.31 KB
/
setup.rb
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
# Setup script for ACE tools.
# Assumes you have a MySQL database set up with read/write permissions.
# Modify database credentials in config file and then run this script to create tables.
# Will not overwrite existing tables; delete manually if you need to re-create them.
require 'config'
require 'mysql'
sql = <<EOF
CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`metadata` text,
`pubmed_metadata` text,
`filename` varchar(256) DEFAULT NULL,
`journal` varchar(256) DEFAULT NULL,
`doi` varchar(256) DEFAULT NULL,
`year` int(4) DEFAULT NULL,
`sample_size` varchar(20) DEFAULT NULL,
`author` text,
`title` text,
`n_words` int(11) DEFAULT NULL,
`active` tinyint(1) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `filename` (`filename`)
); CREATE TABLE IF NOT EXISTS `article_texts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` longtext,
`article_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `article_id` (`article_id`)
); CREATE TABLE IF NOT EXISTS `peaks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`table_id` int(11) DEFAULT NULL,
`number` int(11) DEFAULT NULL,
`region` text,
`hemisphere` varchar(100) DEFAULT NULL,
`ba` varchar(100) DEFAULT NULL,
`x` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`z` int(11) DEFAULT NULL,
`size` varchar(100) DEFAULT NULL,
`groups` text,
`statistic` varchar(100) DEFAULT NULL,
`p_value` varchar(100) DEFAULT NULL,
`columns` text,
`problems` text,
PRIMARY KEY (`id`),
KEY `table_id` (`table_id`)
); CREATE TABLE IF NOT EXISTS `tables` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`number` int(11) DEFAULT NULL,
`article_id` int(11) DEFAULT NULL,
`title` text,
`caption` text,
PRIMARY KEY (`id`),
KEY `article_id` (`article_id`)
); CREATE TABLE IF NOT EXISTS `terms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
`n_articles` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
); CREATE TABLE IF NOT EXISTS `tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`article_id` int(11) DEFAULT NULL,
`term_id` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `term_id` (`term_id`),
KEY `article_id` (`article_id`)
)
EOF
db = Mysql.real_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE)
sql.split(";").each { |s| db.query(s) }