-
Notifications
You must be signed in to change notification settings - Fork 501
/
1_initial_schema.sql
362 lines (244 loc) · 9.74 KB
/
1_initial_schema.sql
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
-- +migrate Up
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: history_accounts; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_accounts (
id bigint NOT NULL,
address character varying(64)
);
--
-- Name: history_effects; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_effects (
history_account_id bigint NOT NULL,
history_operation_id bigint NOT NULL,
"order" integer NOT NULL,
type integer NOT NULL,
details jsonb
);
--
-- Name: history_ledgers; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_ledgers (
sequence integer NOT NULL,
ledger_hash character varying(64) NOT NULL,
previous_ledger_hash character varying(64),
transaction_count integer DEFAULT 0 NOT NULL,
operation_count integer DEFAULT 0 NOT NULL,
closed_at timestamp without time zone NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
id bigint,
importer_version integer DEFAULT 1 NOT NULL,
total_coins bigint NOT NULL,
fee_pool bigint NOT NULL,
base_fee integer NOT NULL,
base_reserve integer NOT NULL,
max_tx_set_size integer NOT NULL
);
--
-- Name: history_operation_participants; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_operation_participants (
id integer NOT NULL,
history_operation_id bigint NOT NULL,
history_account_id bigint NOT NULL
);
--
-- Name: history_operation_participants_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE history_operation_participants_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: history_operation_participants_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE history_operation_participants_id_seq OWNED BY history_operation_participants.id;
--
-- Name: history_operations; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_operations (
id bigint NOT NULL,
transaction_id bigint NOT NULL,
application_order integer NOT NULL,
type integer NOT NULL,
details jsonb,
source_account character varying(64) DEFAULT ''::character varying NOT NULL
);
--
-- Name: history_transaction_participants; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_transaction_participants (
id integer NOT NULL,
history_transaction_id bigint NOT NULL,
history_account_id bigint NOT NULL
);
--
-- Name: history_transaction_participants_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE history_transaction_participants_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: history_transaction_participants_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE history_transaction_participants_id_seq OWNED BY history_transaction_participants.id;
--
-- Name: history_transactions; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE history_transactions (
transaction_hash character varying(64) NOT NULL,
ledger_sequence integer NOT NULL,
application_order integer NOT NULL,
account character varying(64) NOT NULL,
account_sequence bigint NOT NULL,
fee_paid integer NOT NULL,
operation_count integer NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
id bigint,
tx_envelope text NOT NULL,
tx_result text NOT NULL,
tx_meta text NOT NULL,
tx_fee_meta text NOT NULL,
signatures character varying(96)[] DEFAULT '{}'::character varying[] NOT NULL,
memo_type character varying DEFAULT 'none'::character varying NOT NULL,
memo character varying,
time_bounds int8range
);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY history_operation_participants ALTER COLUMN id SET DEFAULT nextval('history_operation_participants_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY history_transaction_participants ALTER COLUMN id SET DEFAULT nextval('history_transaction_participants_id_seq'::regclass);
--
-- Name: history_operation_participants_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY history_operation_participants
ADD CONSTRAINT history_operation_participants_pkey PRIMARY KEY (id);
--
-- Name: history_transaction_participants_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY history_transaction_participants
ADD CONSTRAINT history_transaction_participants_pkey PRIMARY KEY (id);
--
-- Name: by_account; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX by_account ON history_transactions USING btree (account, account_sequence);
--
-- Name: by_hash; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX by_hash ON history_transactions USING btree (transaction_hash);
--
-- Name: by_ledger; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX by_ledger ON history_transactions USING btree (ledger_sequence, application_order);
--
-- Name: hist_e_by_order; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX hist_e_by_order ON history_effects USING btree (history_operation_id, "order");
--
-- Name: hist_e_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX hist_e_id ON history_effects USING btree (history_account_id, history_operation_id, "order");
--
-- Name: hist_op_p_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX hist_op_p_id ON history_operation_participants USING btree (history_account_id, history_operation_id);
--
-- Name: hs_ledger_by_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX hs_ledger_by_id ON history_ledgers USING btree (id);
--
-- Name: hs_transaction_by_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX hs_transaction_by_id ON history_transactions USING btree (id);
--
-- Name: index_history_accounts_on_address; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_accounts_on_address ON history_accounts USING btree (address);
--
-- Name: index_history_accounts_on_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_accounts_on_id ON history_accounts USING btree (id);
--
-- Name: index_history_effects_on_type; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_history_effects_on_type ON history_effects USING btree (type);
--
-- Name: index_history_ledgers_on_closed_at; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_history_ledgers_on_closed_at ON history_ledgers USING btree (closed_at);
--
-- Name: index_history_ledgers_on_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_ledgers_on_id ON history_ledgers USING btree (id);
--
-- Name: index_history_ledgers_on_importer_version; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_history_ledgers_on_importer_version ON history_ledgers USING btree (importer_version);
--
-- Name: index_history_ledgers_on_ledger_hash; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_ledgers_on_ledger_hash ON history_ledgers USING btree (ledger_hash);
--
-- Name: index_history_ledgers_on_previous_ledger_hash; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_ledgers_on_previous_ledger_hash ON history_ledgers USING btree (previous_ledger_hash);
--
-- Name: index_history_ledgers_on_sequence; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_ledgers_on_sequence ON history_ledgers USING btree (sequence);
--
-- Name: index_history_operations_on_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_operations_on_id ON history_operations USING btree (id);
--
-- Name: index_history_operations_on_transaction_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_history_operations_on_transaction_id ON history_operations USING btree (transaction_id);
--
-- Name: index_history_operations_on_type; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_history_operations_on_type ON history_operations USING btree (type);
--
-- Name: hist_tx_p_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX hist_tx_p_id ON history_transaction_participants USING btree (history_account_id, history_transaction_id);
--
-- Name: index_history_transactions_on_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX index_history_transactions_on_id ON history_transactions USING btree (id);
--
-- Name: trade_effects_by_order_book; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX trade_effects_by_order_book ON history_effects USING btree (((details ->> 'sold_asset_type'::text)), ((details ->> 'sold_asset_code'::text)), ((details ->> 'sold_asset_issuer'::text)), ((details ->> 'bought_asset_type'::text)), ((details ->> 'bought_asset_code'::text)), ((details ->> 'bought_asset_issuer'::text))) WHERE (type = 33);
-- +migrate Down
drop table history_transactions cascade;
drop table history_transaction_participants cascade;
drop table history_operations cascade;
drop table history_operation_participants cascade;
drop table history_ledgers cascade;
drop table history_effects cascade;
drop table history_accounts cascade;