-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateDB.txt
151 lines (127 loc) · 4.91 KB
/
CreateDB.txt
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
CREATE DATABASE apphub;
CREATE USER 'bits'@'localhost' IDENTIFIED BY 'fixit';
GRANT ALL PRIVILEGES ON apphub.* TO 'bits'@'localhost';
GRANT USAGE ON apphub.* TO 'bits'@'localhost' IDENTIFIED BY 'fixit';
use apphub;
/* Ledgers are for accounting : most communication responses will include a
reference to either OperatorLedger or AppLedger
Operator Ledger is primarily for AppHub accounting and consistency
E.g. Adding a new user, Re-charge of accounts, setting App Credit limits etc.
Each SWiFiIC operation ends up hitting either OperatorLedger or AppLedger (minimum once)
Periodically (possibly hourly) Audit runs, close off (garbage collect) completed info
and abort timed-out transactions (e.g. pending for > 1 week).
*/
CREATE TABLE OperatorLedger
/* user additions + credits - i.e. Operator has physical interaction with real world */
/* access to this table should be limited i.e. do not use GRANT *.* - TBD XXX */
(
LogId BIGINT UNSIGNED AUTO_INCREMENT, /* Unique Id for each Ledger entry*/
EventNotes VARCHAR(256), /* description of the Ledger entry*/
ReqUserId INT, /* User Id of the User who requested the Ledger entry*/
ReqDeviceId INT, /* Device Id , where the Ledger Request came from*/
CreditDeviceId INT, /* Id of the device to be credited */
DebitDeviceId INT, /* Id od the device to be debited */
Details VARCHAR(1024), /* Details of the Ledger Entry - Credit or Debit */
Time TIMESTAMP, /* Timestamp of the ledger entry
AuditLogId BIGINT, /* LogId of the Audit that fulfills the current ledger entry */
AuditNotes BIGINT, /* Small note about the audit*/
/* The above two fields are filled from the settlement script as the ledger entry gets audited */
Amount BIGINT , /* Amount to be credited or debited */
PRIMARY KEY (LogId)
);
CREATE TABLE AppLedger
(
LogId BIGINT UNSIGNED AUTO_INCREMENT,
EventNotes VARCHAR(256),
ReqUserId INT,
ReqAppId INT,
ReqAppRole VARCHAR(64),
ReqDeviceId INT,
CreditDeviceId INT,
DebitDeviceId INT,
Details VARCHAR(1024),
TimeReq TIMESTAMP,
TimeCommitted TIMESTAMP,
ReqOrCommitID BIGINT,
DevSeqId BIGINT,
Value INT,
Status ENUM('audited','success', 'failed', 'aborted', 'commit-pending','ack-pending','others'),
StatusNotes VARCHAR(64), /* especially for others */
AlibiDevDetails VARCHAR(256),
AuditLogId BIGINT,
AuditNotes BIGINT,
PRIMARY KEY (LogId)
);
/* Audit runs like cron jobs, or on user request - e.g. account closure
All entries in Ledgers are sanitized if pending for too long */
CREATE TABLE Audit
(
AuditId BIGINT UNSIGNED AUTO_INCREMENT, /* Unique Id for each Audit entry*/
AuditNotes VARCHAR(256), /* Details about who did the audit etc.. */
StartedAt TIMESTAMP, /* Start time of the audit*/
CompletedAt TIMESTAMP, /*End time of the audit */
FirstAffectedOperatorLogId BIGINT UNSIGNED, /* LogId of the First Ledger entry in the current audit*/
LastAffectedOperatorLogId BIGINT UNSIGNED,/* LogId of the Last Ledger entry in the current audit*/
NumAffectedOperatorLogId INT UNSIGNED,/* Number of ledger entries audited */
FirstAffectedAppLogId BIGINT UNSIGNED,
LastAffectedAppLogId BIGINT UNSIGNED,
NumAffectedAppLogId INT UNSIGNED,
NumValueTransfers INT UNSIGNED, /* Total number of ledger entries audited */
TotalValueTransferAmount INT UNSIGNED, /* total amount (both credit and debit) in the current audit */
AuditType ENUM('periodic','user-requested','billing','others'),
/* type of the audit */
PRIMARY KEY (AuditId)
);
/** following is for 0.1.0 release - target **/
CREATE TABLE User
(
UserId INT UNSIGNED AUTO_INCREMENT,
Name VARCHAR(64),
Alias VARCHAR(64), /* Alias name of the user */
EmailAddress VARCHAR(64),
MobileNumber VARCHAR(32),
Address VARCHAR(256),
ImageFile BLOB , /* Profile pic of the User */
IdProofFile BLOB , /* IdProof image */
AddrProofFile BLOB , /* Address Proof image */
AddressVerificationNotes VARCHAR(256), /* Address Notes */
CreateTime DATETIME, /* TimeStamp when the user is added*/
CreatedLedgerId BIGINT,
RemainingCreditPostAudit INT, /* Credit in the User's account after the recent audit */
Status ENUM('active', 'suspended', 'deleted', 'operator'), /* at least one operator should exist */
Password VARCHAR(128),
LastAuditedActivityAt TIMESTAMP, /* Timestamp when the user's credit is last audited */
PRIMARY KEY (UserId)
);
CREATE TABLE Device
(
DeviceID INT AUTO_INCREMENT,
MAC VARCHAR(64),
UserId INT,
CreatedLedgerEntry BIGINT,
Notes VARCHAR(64),
CreateTime DATETIME,
PeriodicAuditTime TIMESTAMP,
PeriodicAuditNotes VARCHAR(256),
LastAuditedActivityAt TIMESTAMP,
PRIMARY KEY (DeviceId)
);
CREATE TABLE App
(
AppId VARCHAR(64),
AppName VARCHAR(64),
PRIMARY KEY (AppId)
);
CREATE TABLE AppUserMaps
(
AppId VARCHAR(64),
UserId INT,
Role VARCHAR(64), /* May need Revisit */
PRIMARY KEY (AppId,UserId,Role)
);
CREATE TABLE PearlApp
(
AppId VARCHAR(64),
AppName VARCHAR(64),
PRIMARY KEY (AppId)
);