Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
Latest commit
181 lines (151 loc) · 6.56 KB
/
Copy pathschema.sql
File metadata and controls
181 lines (151 loc) · 6.56 KB
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
CREATETABLEOriginalTransactions (
TransactionId INTEGERPRIMARY KEYNOT NULL,
FromUserId INTEGERNOT NULL,
ToUserId INTEGERNOT NULL,
Value INTEGERNOT NULL
);
CREATETABLEProcessedTransactions (
TransactionId INTEGERPRIMARY KEYNOT NULL,
FromUserId INTEGERNOT NULL,
ToUserId INTEGERNOT NULL,
Value INTEGERNOT NULL,
Included INTEGERNOT NULL DEFAULT 1,
HeuristicValue INTEGER
);
CREATEINDEXProcessedTransactions_IndexFromUserId
ON ProcessedTransactions (FromUserId);
CREATEINDEXProcessedTransactions_IndexToUserId
ON ProcessedTransactions (ToUserId);
CREATEINDEXProcessedTransactions_IndexValue
ON ProcessedTransactions (Value);
CREATEVIEWProcessedTransactions_ViewIncludedAS
SELECT TransactionId, FromUserId, ToUserId, Value, HeuristicValue
FROM ProcessedTransactions
WHERE Included =1;
CREATEVIEWProcessedTransactions_ViewIncludedHeuristicAscAS
SELECT TransactionId, FromUserId, ToUserId, Value, HeuristicValue
FROM ProcessedTransactions
WHERE Included =1
ORDER BY HeuristicValue ASC, TransactionId ASC;
CREATEVIEWProcessedTransactions_ViewIncludedHeuristicDescAS
SELECT TransactionId, FromUserId, ToUserId, Value, HeuristicValue
FROM ProcessedTransactions
WHERE Included =1
ORDER BY HeuristicValue DESC, TransactionId ASC;
CREATETABLELastUserTransaction (
UserId INTEGERPRIMARY KEYNOT NULL,
LastTransactionId_FK INTEGERNOT NULL,
FOREIGN KEY (LastTransactionId_FK) REFERENCES ProcessedTransactions (TransactionId)
);
CREATETABLEChainInfo (
ChainInfoId INTEGERPRIMARY KEYNOT NULL,
MinimumValue INTEGERNOT NULL,
Length INTEGERNOT NULL,
TotalValue INTEGERNOT NULL,
NumberOfMinimumValues INTEGERNOT NULL
);
CREATETABLEChains (
ChainId INTEGERNOT NULL,
TransactionId_FK INTEGERNOT NULL,
ChainInfoId_FK INTEGERNOT NULL,
PRIMARY KEY (ChainId, TransactionId_FK),
FOREIGN KEY (TransactionId_FK) REFERENCES ProcessedTransactions (TransactionId),
FOREIGN KEY (ChainInfoId_FK) REFERENCES ChainInfo (ChainInfoId)
);
CREATETABLEBranchedTransactions (
ChainId_FK INTEGERNOT NULL,
FromTransactionId_FK INTEGERNOT NULL,
ToTransactionId_FK INTEGERNOT NULL,
PRIMARY KEY (ChainId_FK, FromTransactionId_FK, ToTransactionId_FK),
FOREIGN KEY (ChainId_FK) REFERENCES Chains (ChainId),
FOREIGN KEY (FromTransactionId_FK) REFERENCES ProcessedTransactions (TransactionId),
FOREIGN KEY (ToTransactionId_FK) REFERENCES ProcessedTransactions (TransactionId)
);
CREATETABLECandidateTransactions (
CandidateTransactionsId INTEGERNOT NULL UNIQUE,
ChainId_FK INTEGER,
TransactionFrom_FK INTEGER,
TransactionTo_FK INTEGERNOT NULL,
MinimumValue INTEGERNOT NULL,
Length INTEGERNOT NULL,
TotalValue INTEGERNOT NULL,
NumberOfMinimumValues INTEGERNOT NULL,
Included INTEGERNOT NULL DEFAULT 1,
HeuristicValue INTEGER,
PRIMARY KEY (ChainId_FK, TransactionFrom_FK, TransactionTo_FK),
FOREIGN KEY (ChainId_FK) REFERENCES Chains (ChainId),
FOREIGN KEY (TransactionFrom_FK) REFERENCES ProcessedTransactions (TransactionId),
FOREIGN KEY (TransactionTo_FK) REFERENCES ProcessedTransactions (TransactionId),
CHECK ((ChainId_FK ISNULL AND TransactionFrom_FK ISNULL) OR (ChainId_FK NOTNULL AND TransactionFrom_FK NOTNULL))
);
CREATEVIEWCandidateTransactions_ViewIncludedAS
SELECT CandidateTransactionsId, ChainId_FK, TransactionFrom_FK, TransactionTo_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, HeuristicValue
FROM CandidateTransactions
WHERE Included =1;
CREATEVIEWCandidateTransactions_ViewIncludedHeuristicAscAS
SELECT CandidateTransactionsId, ChainId_FK, TransactionFrom_FK, TransactionTo_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, HeuristicValue
FROM CandidateTransactions
WHERE Included =1
ORDER BY HeuristicValue ASC, TransactionTo_FK ASC;
CREATEVIEWCandidateTransactions_ViewIncludedHeuristicDescAS
SELECT CandidateTransactionsId, ChainId_FK, TransactionFrom_FK, TransactionTo_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, HeuristicValue
FROM CandidateTransactions
WHERE Included =1
ORDER BY HeuristicValue DESC, TransactionTo_FK ASC;
CREATETABLELoopInfo (
LoopId INTEGERPRIMARY KEYNOT NULL,
Active INTEGERNOT NULL DEFAULT 0,
FirstTransactionId_FK INTEGERNOT NULL,
LastTransactionId_FK INTEGERNOT NULL,
MinimumValue INTEGERNOT NULL,
Length INTEGERNOT NULL,
TotalValue INTEGERNOT NULL,
NumberOfMinimumValues INTEGERNOT NULL,
Included INTEGERNOT NULL DEFAULT 1,
HeuristicValue INTEGER,
FOREIGN KEY (FirstTransactionId_FK) REFERENCES ProcessedTransactions (TransactionId),
FOREIGN KEY (LastTransactionId_FK) REFERENCES ProcessedTransactions (TransactionId)
);
CREATEINDEXLoopInfo_IndexActive
ON LoopInfo (Active);
CREATEVIEWLoopInfo_ViewActiveAS
SELECT LoopId, FirstTransactionId_FK, LastTransactionId_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, Included, HeuristicValue
FROM LoopInfo
WHERE Active =1;
CREATEVIEWLoopInfo_ViewInactiveAS
SELECT LoopId, FirstTransactionId_FK, LastTransactionId_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, Included, HeuristicValue
FROM LoopInfo
WHERE Active =0;
CREATEVIEWLoopInfo_ViewIncludedAS
SELECT LoopId, FirstTransactionId_FK, LastTransactionId_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, Included, HeuristicValue
FROM LoopInfo
WHERE Included =1;
CREATEVIEWLoopInfo_ViewIncludedInactiveAS
SELECT LoopId, FirstTransactionId_FK, LastTransactionId_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, HeuristicValue
FROM LoopInfo
WHERE Included =1AND Active =0 ;
CREATEVIEWLoopInfo_ViewIncludedInactiveHeuristicAscAS
SELECT LoopId, FirstTransactionId_FK, LastTransactionId_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, HeuristicValue
FROM LoopInfo
WHERE Included =1AND Active =0
ORDER BY HeuristicValue ASC;
CREATEVIEWLoopInfo_ViewIncludedInactiveHeuristicDescAS
SELECT LoopId, FirstTransactionId_FK, LastTransactionId_FK, MinimumValue, Length, TotalValue, NumberOfMinimumValues, HeuristicValue
FROM LoopInfo
WHERE Included =1AND Active =0
ORDER BY HeuristicValue DESC;
CREATETABLELoops (
LoopId_FK INTEGERNOT NULL,
TransactionId_FK INTEGERNOT NULL,
PRIMARY KEY (LoopId_FK, TransactionId_FK),
FOREIGN KEY (LoopId_FK) REFERENCES LoopInfo (LoopId),
FOREIGN KEY (TransactionId_FK) REFERENCES ProcessedTransactions (TransactionId)
);
CREATEINDEXLoops_IndexTransactionId
ON Loops (TransactionId_FK);
CREATEINDEXLoops_IndexLoopId
ON Loops (LoopId_FK);
CREATEVIEWLoops_ViewActiveAS
SELECTLoops.LoopId_FK, Loops.TransactionId_FK
FROM Loops, LoopInfo
WHERELoopInfo.Active=1ANDLoops.LoopId_FK=LoopInfo.LoopId;