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 << "CREATE TABLE IF NOT EXISTS `operations` (\nid INT UNSIGNED NOT NULL AUTO_INCREMENT,\ncode TINYINT UNSIGNED NOT NULL,\naccount_id INT UNSIGNED NOT NULL,\nreference INT UNSIGNED NOT NULL,\ndebit DECIMAL(32, 16) NOT NULL,\ncredit DECIMAL(32, 16) NOT NULL,\ncreated_at DATETIME NOT NULL,\nupdated_at DATETIME NOT NULL,\nPRIMARY KEY (id),\nINDEX `balance_key` (account_id, debit, credit)\n) ENGINE = InnoDB;\n"
statements << "DROP TABLE IF EXISTS `orders`;" if options[:drop_if_exists]
statements << "CREATE TABLE IF NOT EXISTS`orders` (\n `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n `uid` INT(11) UNSIGNED NOT NULL,\n `bid` VARCHAR(5) NOT NULL,\n `ask` VARCHAR(5) NOT NULL,\n `market` VARCHAR(10) NOT NULL,\n `price` DECIMAL(32,16) DEFAULT NULL,\n `volume` DECIMAL(32,16) NOT NULL,\n `fee` DECIMAL(32,16) NOT NULL DEFAULT '0.0000000000000000',\n `type` TINYINT UNSIGNED NOT NULL,\n `state` TINYINT UNSIGNED NOT NULL,\n `created_at` DATETIME NOT NULL,\n `updated_at` DATETIME NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n"
statements << "DROP TABLE IF EXISTS `trades`;" if options[:drop_if_exists]
statements << "CREATE TABLE IF NOT EXISTS `trades` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `market` varchar(10) NOT NULL,\n `volume` decimal(32,16) NOT NULL,\n `price` decimal(32,16) NOT NULL,\n `ask_id` int(11) NOT NULL,\n `bid_id` int(11) NOT NULL,\n `ask_uid` int(11) NOT NULL,\n `bid_uid` int(11) NOT NULL,\n `created_at` datetime NOT NULL,\n `updated_at` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n"
statements.each do |statement|
puts statement
client.query(statement)
end
end
|