OSDN Git Service

doc: add fed sql schema (#134)
[bytom/vapor.git] / docs / federation / federation.sql
1 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
2 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
3 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
4 /*!40101 SET NAMES utf8 */;
5 /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
6 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
7 /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
8
9 CREATE SCHEMA IF NOT EXISTS `federation`;
10
11 USE `federation`;
12
13 # Dump of table warders
14 # ------------------------------------------------------------
15
16 DROP TABLE IF EXISTS `warders`;
17
18 CREATE TABLE `warders` (
19   `id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT,
20   `pubkey` varchar(64) NOT NULL,
21   `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
22   `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
23   PRIMARY KEY (`id`),
24   UNIQUE KEY `pubkey` (`pubkey`)
25 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
26
27 LOCK TABLES `warders` WRITE;
28 UNLOCK TABLES;
29
30
31 # Dump of table chains
32 # ------------------------------------------------------------
33
34 CREATE TABLE `chains` (
35   `id` tinyint(1) NOT NULL AUTO_INCREMENT,
36   `name` varchar(64) NOT NULL,
37   `block_height` int(11) DEFAULT '0',
38   `block_hash` char(64) NOT NULL,
39   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
40   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
41   PRIMARY KEY (`id`),
42   UNIQUE KEY `name` (`name`),
43   UNIQUE KEY `block_hash` (`block_hash`)
44 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
45
46 LOCK TABLES `chains` WRITE;
47 /*!40000 ALTER TABLE `chains` DISABLE KEYS */;
48
49 INSERT INTO `chains`
50 (`id`, `name`, `block_height`, `block_hash`, `created_at`, `updated_at`)
51 VALUES
52 (1,'btm',0,'a75483474799ea1aa6bb910a1a5025b4372bf20bef20f246a2c2dc5e12e8a053','2018-09-13 05:10:43','2018-11-27 09:42:06');
53
54 /*!40000 ALTER TABLE `chains` ENABLE KEYS */;
55 UNLOCK TABLES;
56
57
58 # Dump of table cross_transactions
59 # ------------------------------------------------------------
60
61 CREATE TABLE `cross_transactions` (
62   `id` int(11) NOT NULL AUTO_INCREMENT,
63   `chain_id` int(11) NOT NULL,
64   `block_height` int(11) NOT NULL,
65   `block_hash` char(64) NOT NULL,
66   `tx_index` int(11) NOT NULL,
67   `mux_id` char(64) NOT NULL,
68   `tx_hash` char(64) NOT NULL,
69   `raw_transaction` mediumtext NOT NULL,
70   `status` tinyint(1) DEFAULT '0',
71   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
72   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
73   PRIMARY KEY (`id`),
74   UNIQUE KEY `mux_id` (`mux_id`),
75   UNIQUE KEY `tx_hash` (`tx_hash`),
76   UNIQUE KEY `raw_transaction` (`raw_transaction`),
77   UNIQUE KEY `blockhash_txidx` (`block_hash`,`tx_index`),
78   UNIQUE KEY `blockheight_txidx` (`chain_id`,`block_height`,`tx_index`),
79   CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`chain_id`) REFERENCES `chains` (`id`)
80 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
81
82 LOCK TABLES `cross_transactions` WRITE;
83 UNLOCK TABLES;
84
85
86 # Dump of table cross_transaction_inputs
87 # ------------------------------------------------------------
88 CREATE TABLE `cross_transaction_inputs` (
89   `id` int(11) NOT NULL AUTO_INCREMENT,
90   `tx_id` int(11) NOT NULL,
91   `source_pos` int(11) NOT NULL,
92   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
93   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
94   PRIMARY KEY (`id`),
95   UNIQUE KEY `input_id` (`tx_id`,`source_pos`),
96   CONSTRAINT `cross_transaction_inputs_ibfk_1` FOREIGN KEY (`tx_id`) REFERENCES `cross_transactions` (`id`)
97 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
98
99 LOCK TABLES `cross_transaction_inputs` WRITE;
100 UNLOCK TABLES;
101
102
103 # Dump of table cross_transaction_signs
104 # ------------------------------------------------------------
105 CREATE TABLE `cross_transaction_signs` (
106   `id` int(11) NOT NULL AUTO_INCREMENT,
107   `cross_transaction_id` int(11) NOT NULL,
108   `warder_id` int(11) NOT NULL,
109   `signatures` text NOT NULL,
110   `status` tinyint(1) NOT NULL,
111   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
112   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
113   PRIMARY KEY (`id`),
114   UNIQUE KEY `sign_id` (`cross_transaction_id`,`warder_id`),
115   CONSTRAINT `cross_transaction_signs_ibfk_1` FOREIGN KEY (`warder_id`) REFERENCES `warders` (`id`),
116   CONSTRAINT `cross_transaction_signs_ibfk_1` FOREIGN KEY (`cross_transaction_id`) REFERENCES `cross_transactions` (`id`)
117 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
118
119 LOCK TABLES `cross_transaction_signs` WRITE;
120 UNLOCK TABLES;