1
1
-- Table for Mk12 or Boost deals
2
2
CREATE TABLE market_mk12_deals (
3
3
uuid TEXT NOT NULL ,
4
- <<<<<<< HEAD
5
4
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE ' UTC' ,
6
- =======
7
5
sp_id BIGINT NOT NULL ,
8
6
9
- created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE(' UTC' , NOW()),
10
-
11
- >>>>>>> 48e953d (poller redesign)
12
7
signed_proposal_cid TEXT NOT NULL ,
13
8
proposal_signature BYTEA NOT NULL ,
14
9
proposal jsonb NOT NULL ,
@@ -41,33 +36,13 @@ CREATE TABLE market_mk12_deals (
41
36
unique (signed_proposal_cid)
42
37
);
43
38
44
- -- Table for old lotus market deals. This is just for deal
45
- -- which are still alive. It should not be used for any processing
46
- CREATE TABLE market_legacy_deals (
47
- signed_proposal_cid TEXT ,
48
- proposal_signature BYTEA ,
49
- proposal jsonb,
50
- piece_cid TEXT ,
51
- piece_size BIGINT ,
52
- offline BOOLEAN ,
53
- verified BOOLEAN ,
54
- sp_id BIGINT ,
55
- start_epoch BIGINT ,
56
- end_epoch BIGINT ,
57
- publish_cid TEXT ,
58
- fast_retrieval BOOLEAN ,
59
- chain_deal_id BIGINT ,
60
- created_at TIMESTAMPTZ ,
61
- sector_num BIGINT ,
62
-
63
- primary key (sp_id, piece_cid, signed_proposal_cid)
64
- );
65
-
66
39
-- This table is used for storing piece metadata (piece indexing)
67
40
CREATE TABLE market_piece_metadata (
68
41
piece_cid TEXT NOT NULL PRIMARY KEY ,
42
+
69
43
version INT NOT NULL DEFAULT 2 ,
70
44
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE ' UTC' ,
45
+
71
46
indexed BOOLEAN NOT NULL DEFAULT FALSE,
72
47
indexed_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE ' UTC' ,
73
48
@@ -157,13 +132,9 @@ CREATE TABLE market_mk12_deal_pipeline (
157
132
started BOOLEAN DEFAULT FALSE,
158
133
159
134
piece_cid TEXT NOT NULL ,
160
- <<<<<<< HEAD
161
135
piece_size BOOLEAN NOT NULL ,
162
- =======
163
- piece_size BIGINT NOT NULL ,
164
- file_size BIGINT DEFAULT NULL , -- raw piece size
136
+ raw_size BIGINT DEFAULT NULL ,
165
137
166
- >>>>>>> 48e953d (poller redesign)
167
138
offline BOOLEAN NOT NULL ,
168
139
169
140
url TEXT DEFAULT NULL ,
@@ -181,52 +152,94 @@ CREATE TABLE market_mk12_deal_pipeline (
181
152
after_find_deal BOOLEAN DEFAULT FALSE,
182
153
183
154
sector BIGINT ,
155
+ reg_seal_proof INT NOT NULL ,
184
156
sector_offset BIGINT ,
185
157
186
158
sealed BOOLEAN DEFAULT FALSE,
159
+
160
+ should_index BOOLEAN DEFAULT FALSE,
161
+ indexing_created_at TIMESTAMPTZ ,
162
+ indexing_task_id BIGINT DEFAULT NULL ,
187
163
indexed BOOLEAN DEFAULT FALSE,
188
164
165
+ complete BOOLEAN NOT NULL DEFAULT FALSE,
166
+
189
167
constraint market_mk12_deal_pipeline_identity_key unique (uuid)
190
168
);
191
169
170
+ -- This function creates indexing task based from move_storage tasks
171
+ CREATE OR REPLACE FUNCTION create_indexing_task (task_id BIGINT , sealing_table TEXT )
172
+ RETURNS VOID AS $$
173
+ DECLARE
174
+ query TEXT ; -- Holds the dynamic SQL query
175
+ pms RECORD; -- Holds each row returned by the query in the loop
176
+ BEGIN
177
+ -- Construct the dynamic SQL query based on the sealing_table
178
+ IF sealing_table = ' sectors_sdr_pipeline' THEN
179
+ query := format(
180
+ ' SELECT
181
+ dp.uuid,
182
+ ssp.reg_seal_proof
183
+ FROM
184
+ %I ssp
185
+ JOIN
186
+ market_mk12_deal_pipeline dp ON ssp.sp_id = dp.sp_id AND ssp.sector_num = dp.sector
187
+ WHERE
188
+ ssp.task_id_move_storage = $1' , sealing_table);
189
+ ELSIF sealing_table = ' sectors_snap_pipeline' THEN
190
+ query := format(
191
+ ' SELECT
192
+ dp.uuid,
193
+ (SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = ssp.sp_id AND sector_num = ssp.sector_num) AS reg_seal_proof
194
+ FROM
195
+ %I ssp
196
+ JOIN
197
+ market_mk12_deal_pipeline dp ON ssp.sp_id = dp.sp_id AND ssp.sector_num = dp.sector
198
+ WHERE
199
+ ssp.task_id_move_storage = $1' , sealing_table);
200
+ ELSE
201
+ RAISE EXCEPTION ' Invalid sealing_table name: %' , sealing_table;
202
+ END IF;
203
+
204
+ -- Execute the dynamic SQL query with the task_id parameter
205
+ FOR pms IN EXECUTE query USING task_id
206
+ LOOP
207
+ -- Update the market_mk12_deal_pipeline table with the reg_seal_proof and indexing_created_at values
208
+ UPDATE market_mk12_deal_pipeline
209
+ SET
210
+ reg_seal_proof = pms .reg_seal_proof ,
211
+ indexing_created_at = NOW() AT TIME ZONE ' UTC'
212
+ WHERE
213
+ uuid = pms .uuid ;
214
+ END LOOP;
215
+
216
+ -- If everything is successful, simply exit
217
+ RETURN;
218
+
219
+ EXCEPTION
220
+ WHEN OTHERS THEN
221
+ -- Rollback the transaction and raise the exception for Go to catch
222
+ ROLLBACK ;
223
+ RAISE EXCEPTION ' Failed to create indexing task: %' , SQLERRM;
224
+ END;
225
+ $$ LANGUAGE plpgsql;
226
+
192
227
-- This table can be used to track remote piece for offline deals
193
228
-- The entries must be created by users
194
229
CREATE TABLE market_offline_urls (
195
- piece_cid TEXT NOT NULL ,
230
+ uuid TEXT NOT NULL ,
196
231
197
- url TEXT NOT NULL ,
198
- headers jsonb NOT NULL DEFAULT ' {}' ,
232
+ url TEXT NOT NULL ,
233
+ headers jsonb NOT NULL DEFAULT ' {}' ,
199
234
200
- raw_size BIGINT NOT NULL ,
235
+ raw_size BIGINT NOT NULL ,
201
236
202
- unique (piece_cid)
237
+ CONSTRAINT market_offline_urls_uuid_fk FOREIGN KEY (uuid)
238
+ REFERENCES market_mk12_deal_pipeline (uuid)
239
+ ON DELETE CASCADE ,
240
+ CONSTRAINT market_offline_urls_uuid_unique UNIQUE (uuid)
203
241
);
204
242
205
- -- indexing tracker is separate from
206
- CREATE TABLE market_indexing_tasks (
207
- uuid TEXT NOT NULL ,
208
-
209
- sp_id BIGINT NOT NULL ,
210
- sector_number BIGINT NOT NULL ,
211
- reg_seal_proof INT NOT NULL ,
212
-
213
- piece_offset BIGINT NOT NULL ,
214
- piece_size BIGINT NOT NULL ,
215
- raw_size BIGINT NOT NULL ,
216
- piece_cid TEXT NOT NULL ,
217
- <<<<<<< HEAD
218
- created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE ' UTC' ,
219
- =======
220
-
221
- created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE(' UTC' , NOW()),
222
-
223
- >>>>>>> 48e953d (poller redesign)
224
- task_id BIGINT DEFAULT NULL ,
225
-
226
- constraint market_indexing_tasks_identity_key
227
- unique (id, sp_id, sector_number, piece_offset, piece_size, piece_cid, reg_seal_proof)
228
- )
229
-
230
243
CREATE TABLE libp2p_keys (
231
244
sp_id BIGINT NOT NULL ,
232
245
priv_key BYTEA NOT NULL ,
@@ -255,33 +268,38 @@ CREATE TABLE direct_deals (
255
268
keep_unsealed_copy BOOLEAN
256
269
);
257
270
271
+ -- Add host column to allow local file based
272
+ -- piece park
258
273
ALTER TABLE parked_piece_refs
259
274
ADD COLUMN host text ;
260
275
261
- create table file_parked_pieces (
262
- id bigserial primary key ,
263
- created_at timestamp default current_timestamp ,
264
- piece_cid text not null ,
265
- piece_padded_size bigint not null ,
266
- piece_raw_size bigint not null ,
267
- complete boolean not null default false,
268
- task_id bigint default null ,
269
- cleanup_task_id bigint default null ,
270
- unique (piece_cid)
271
- );
276
+ -- Table for old lotus market deals. This is just for deal
277
+ -- which are still alive. It should not be used for any processing
278
+ CREATE TABLE market_legacy_deals (
279
+ signed_proposal_cid TEXT ,
280
+ sp_id BIGINT ,
272
281
273
- /*
274
- * This table is used to keep track of the references to the file parked pieces
275
- * so that we can delete them when they are no longer needed.
276
- *
277
- * All references into the file_parked_pieces table should be done through this table.
278
- */
279
- create table file_parked_piece_refs (
280
- ref_id bigserial primary key ,
281
- piece_id bigint not null ,
282
- data_url text not null ,
283
- node text not null ,
284
- foreign key (piece_id) references file_parked_pieces(id) on delete cascade
282
+ proposal_signature BYTEA ,
283
+ proposal jsonb,
284
+
285
+ piece_cid TEXT ,
286
+ piece_size BIGINT ,
287
+
288
+ offline BOOLEAN ,
289
+ verified BOOLEAN ,
290
+
291
+ start_epoch BIGINT ,
292
+ end_epoch BIGINT ,
293
+
294
+ publish_cid TEXT ,
295
+ chain_deal_id BIGINT ,
296
+
297
+ fast_retrieval BOOLEAN ,
298
+
299
+ created_at TIMESTAMPTZ ,
300
+ sector_num BIGINT ,
301
+
302
+ primary key (sp_id, piece_cid, signed_proposal_cid)
285
303
);
286
304
287
305
0 commit comments