Skip to content

Commit 55d2284

Browse files
committed
fix: database migrations for horizon
Signed-off-by: Tomás Migone <[email protected]>
1 parent 660ce64 commit 55d2284

File tree

2 files changed

+151
-79
lines changed

2 files changed

+151
-79
lines changed

packages/indexer-agent/src/db/migrations/21-add-tap-horizon-table.ts

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,32 @@ export async function up({ context }: Context): Promise<void> {
2626
primaryKey: true,
2727
autoIncrement: true,
2828
},
29-
allocation_id: {
30-
type: DataTypes.CHAR(40),
31-
allowNull: false,
32-
},
3329
signer_address: {
3430
type: DataTypes.CHAR(40),
3531
allowNull: false,
3632
},
33+
34+
// Values below are the individual fields of the EIP-712 receipt
3735
signature: {
3836
type: DataTypes.BLOB,
3937
allowNull: false,
4038
},
39+
collection_id: {
40+
type: DataTypes.CHAR(64),
41+
allowNull: false,
42+
},
43+
payer: {
44+
type: DataTypes.CHAR(40),
45+
allowNull: false,
46+
},
47+
data_service: {
48+
type: DataTypes.CHAR(40),
49+
allowNull: false,
50+
},
51+
service_provider: {
52+
type: DataTypes.CHAR(40),
53+
allowNull: false,
54+
},
4155
timestamp_ns: {
4256
type: DataTypes.DECIMAL(20),
4357
allowNull: false,
@@ -59,7 +73,7 @@ export async function up({ context }: Context): Promise<void> {
5973
RETURNS trigger AS
6074
$$
6175
BEGIN
62-
PERFORM pg_notify('tap_horizon_receipt_notification', format('{"id": %s, "allocation_id": "%s", "signer_address": "%s", "timestamp_ns": %s, "value": %s}', NEW.id, NEW.allocation_id, NEW.signer_address, NEW.timestamp_ns, NEW.value));
76+
PERFORM pg_notify('tap_horizon_receipt_notification', format('{"id": %s, "collection_id": "%s", "signer_address": "%s", "timestamp_ns": %s, "value": %s}', NEW.id, NEW.collection_id, NEW.signer_address, NEW.timestamp_ns, NEW.value));
6377
RETURN NEW;
6478
END;
6579
$$ LANGUAGE 'plpgsql';
@@ -72,8 +86,8 @@ export async function up({ context }: Context): Promise<void> {
7286
await queryInterface.sequelize.query(functionSQL)
7387
await queryInterface.sequelize.query(triggerSQL)
7488

75-
queryInterface.addIndex('tap_horizon_receipts', ['allocation_id'], {
76-
name: 'tap_horizon_receipts_allocation_id_idx',
89+
queryInterface.addIndex('tap_horizon_receipts', ['collection_id'], {
90+
name: 'tap_horizon_receipts_collection_id_idx',
7791
})
7892
queryInterface.addIndex('tap_horizon_receipts', ['timestamp_ns'], {
7993
name: 'tap_horizon_receipts_timestamp_ns_idx',
@@ -91,18 +105,32 @@ export async function up({ context }: Context): Promise<void> {
91105
primaryKey: true,
92106
autoIncrement: true,
93107
},
94-
allocation_id: {
95-
type: DataTypes.CHAR(40),
96-
allowNull: false,
97-
},
98108
signer_address: {
99109
type: DataTypes.CHAR(40),
100110
allowNull: false,
101111
},
112+
113+
// Values below are the individual fields of the EIP-712 receipt
102114
signature: {
103115
type: DataTypes.BLOB,
104116
allowNull: false,
105117
},
118+
collection_id: {
119+
type: DataTypes.CHAR(64),
120+
allowNull: false,
121+
},
122+
payer: {
123+
type: DataTypes.CHAR(40),
124+
allowNull: false,
125+
},
126+
data_service: {
127+
type: DataTypes.CHAR(40),
128+
allowNull: false,
129+
},
130+
service_provider: {
131+
type: DataTypes.CHAR(40),
132+
allowNull: false,
133+
},
106134
timestamp_ns: {
107135
type: DataTypes.DECIMAL(20),
108136
allowNull: false,
@@ -115,6 +143,10 @@ export async function up({ context }: Context): Promise<void> {
115143
type: DataTypes.DECIMAL(20),
116144
allowNull: false,
117145
},
146+
error_log: {
147+
type: DataTypes.TEXT,
148+
allowNull: true,
149+
},
118150
})
119151
}
120152

@@ -123,28 +155,29 @@ export async function up({ context }: Context): Promise<void> {
123155
} else {
124156
// Create the tap_horizon_ravs table if it doesn't exist
125157
await queryInterface.createTable('tap_horizon_ravs', {
158+
// Values below are the individual fields of the EIP-712 receipt
159+
signature: {
160+
type: DataTypes.BLOB,
161+
allowNull: false,
162+
},
126163
collection_id: {
127164
type: DataTypes.CHAR(64),
128165
allowNull: false,
129166
},
130-
sender_address: {
167+
payer: {
131168
type: DataTypes.CHAR(40),
132169
allowNull: false,
133170
},
134-
service_provider_address: {
171+
data_service: {
135172
type: DataTypes.CHAR(40),
136173
allowNull: false,
137174
},
138-
data_service_address: {
175+
service_provider: {
139176
type: DataTypes.CHAR(40),
140177
allowNull: false,
141178
},
142-
signature: {
143-
type: DataTypes.BLOB,
144-
allowNull: false,
145-
},
146179
timestamp_ns: {
147-
type: DataTypes.DECIMAL,
180+
type: DataTypes.DECIMAL(20),
148181
allowNull: false,
149182
},
150183
value_aggregate: {
@@ -155,16 +188,18 @@ export async function up({ context }: Context): Promise<void> {
155188
type: DataTypes.BLOB,
156189
allowNull: false,
157190
},
158-
final: {
191+
192+
last: {
159193
type: DataTypes.BOOLEAN,
160194
allowNull: false,
161195
defaultValue: false,
162196
},
163-
last: {
197+
final: {
164198
type: DataTypes.BOOLEAN,
165199
allowNull: false,
166200
defaultValue: false,
167201
},
202+
168203
redeemed_at: {
169204
type: DataTypes.DATE,
170205
allowNull: true,
@@ -182,7 +217,7 @@ export async function up({ context }: Context): Promise<void> {
182217

183218
logger.info(`Add primary key`)
184219
await queryInterface.addConstraint('tap_horizon_ravs', {
185-
fields: ['collection_id', 'sender_address', 'service_provider_address', 'data_service_address'],
220+
fields: ['payer', 'data_service', 'service_provider', 'collection_id'],
186221
type: 'primary key',
187222
name: 'pk_tap_horizon_ravs',
188223
})
@@ -197,15 +232,15 @@ export async function up({ context }: Context): Promise<void> {
197232
type: DataTypes.CHAR(64),
198233
allowNull: false,
199234
},
200-
sender_address: {
235+
payer: {
201236
type: DataTypes.CHAR(40),
202237
allowNull: false,
203238
},
204-
service_provider_address: {
239+
data_service: {
205240
type: DataTypes.CHAR(40),
206241
allowNull: false,
207242
},
208-
data_service_address: {
243+
service_provider: {
209244
type: DataTypes.CHAR(40),
210245
allowNull: false,
211246
},
@@ -239,7 +274,7 @@ export async function down({ context }: Context): Promise<void> {
239274
)
240275
await queryInterface.removeIndex(
241276
'tap_horizon_receipts',
242-
'tap_horizon_receipts_allocation_id_idx',
277+
'tap_horizon_receipts_collection_id_idx',
243278
)
244279
await queryInterface.removeIndex(
245280
'tap_horizon_receipts',

0 commit comments

Comments
 (0)