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
|
# File 'lib/peatio/sql/schema.rb', line 13
def create_tables(options = {})
statements = []
statements << "DROP TABLE IF EXISTS `operations`;" if options[:drop_if_exists]
statements << <<-EOF
CREATE TABLE IF NOT EXISTS `operations` (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
code TINYINT UNSIGNED NOT NULL,
account_id INT UNSIGNED NOT NULL,
reference INT UNSIGNED NOT NULL,
debit DECIMAL(32, 16) NOT NULL,
credit DECIMAL(32, 16) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
INDEX `balance_key` (account_id, debit, credit)
) ENGINE = InnoDB;
EOF
statements << "DROP TABLE IF EXISTS `orders`;" if options[:drop_if_exists]
statements << <<EOF
CREATE TABLE IF NOT EXISTS`orders` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`uid` INT(11) UNSIGNED NOT NULL,
`bid` VARCHAR(5) NOT NULL,
`ask` VARCHAR(5) NOT NULL,
`market` VARCHAR(10) NOT NULL,
`price` DECIMAL(32,16) DEFAULT NULL,
`volume` DECIMAL(32,16) NOT NULL,
`fee` DECIMAL(32,16) NOT NULL DEFAULT '0.0000000000000000',
`type` TINYINT UNSIGNED NOT NULL,
`state` TINYINT UNSIGNED NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
EOF
statements << "DROP TABLE IF EXISTS `trades`;" if options[:drop_if_exists]
statements << <<EOF
CREATE TABLE IF NOT EXISTS `trades` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`market` varchar(10) NOT NULL,
`volume` decimal(32,16) NOT NULL,
`price` decimal(32,16) NOT NULL,
`ask_id` int(11) NOT NULL,
`bid_id` int(11) NOT NULL,
`ask_uid` int(11) NOT NULL,
`bid_uid` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
EOF
statements.each do |statement|
puts statement
client.query(statement)
end
end
|