-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: postgres support not ready obvi
postgres changes to almost sync successfully
- Loading branch information
Showing
46 changed files
with
1,380 additions
and
1,114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Add down migration script here | ||
DROP TABLE IF EXISTS "block"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Add up migration script here | ||
|
||
CREATE TABLE IF NOT EXISTS "block" ( | ||
multihash BYTEA NOT NULL, | ||
bytes BYTEA NOT NULL, | ||
PRIMARY KEY(multihash) | ||
); | ||
|
||
SELECT multihash, bytes FROM "block" where false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- Add down migration script here | ||
|
||
DROP TABLE IF EXISTS interest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Add up migration script here | ||
|
||
CREATE TABLE IF NOT EXISTS interest ( | ||
order_key BYTEA NOT NULL, -- network_id sort_value controller StreamID event_cid | ||
ahash_0 BIGINT NOT NULL CHECK (ahash_0 >= 0 AND ahash_0 < '4294967296'::BIGINT), -- the ahash is decomposed as [u32; 8] | ||
ahash_1 BIGINT NOT NULL CHECK (ahash_1 >= 0 AND ahash_1 < '4294967296'::BIGINT), | ||
ahash_2 BIGINT NOT NULL CHECK (ahash_2 >= 0 AND ahash_2 < '4294967296'::BIGINT), | ||
ahash_3 BIGINT NOT NULL CHECK (ahash_3 >= 0 AND ahash_3 < '4294967296'::BIGINT), | ||
ahash_4 BIGINT NOT NULL CHECK (ahash_4 >= 0 AND ahash_4 < '4294967296'::BIGINT), | ||
ahash_5 BIGINT NOT NULL CHECK (ahash_5 >= 0 AND ahash_5 < '4294967296'::BIGINT), | ||
ahash_6 BIGINT NOT NULL CHECK (ahash_6 >= 0 AND ahash_6 < '4294967296'::BIGINT), | ||
ahash_7 BIGINT NOT NULL CHECK (ahash_7 >= 0 AND ahash_7 < '4294967296'::BIGINT), | ||
PRIMARY KEY(order_key) | ||
); | ||
|
||
SELECT order_key, ahash_0, ahash_1, ahash_2, ahash_3, ahash_4, ahash_5, ahash_6, ahash_7 FROM interest WHERE false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- Add down migration script here | ||
|
||
DROP TABLE IF EXISTS "event"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- Add up migration script here | ||
|
||
CREATE TABLE IF NOT EXISTS "event" ( | ||
order_key BYTEA NOT NULL UNIQUE, -- network_id sep_key sep_value controller stream_id event_cid | ||
ahash_0 BIGINT NOT NULL CHECK (ahash_0 >= 0 AND ahash_0 < '4294967296'::BIGINT), -- the ahash is decomposed as [u32; 8] | ||
ahash_1 BIGINT NOT NULL CHECK (ahash_1 >= 0 AND ahash_1 < '4294967296'::BIGINT), | ||
ahash_2 BIGINT NOT NULL CHECK (ahash_2 >= 0 AND ahash_2 < '4294967296'::BIGINT), | ||
ahash_3 BIGINT NOT NULL CHECK (ahash_3 >= 0 AND ahash_3 < '4294967296'::BIGINT), | ||
ahash_4 BIGINT NOT NULL CHECK (ahash_4 >= 0 AND ahash_4 < '4294967296'::BIGINT), | ||
ahash_5 BIGINT NOT NULL CHECK (ahash_5 >= 0 AND ahash_5 < '4294967296'::BIGINT), | ||
ahash_6 BIGINT NOT NULL CHECK (ahash_6 >= 0 AND ahash_6 < '4294967296'::BIGINT), | ||
ahash_7 BIGINT NOT NULL CHECK (ahash_7 >= 0 AND ahash_7 < '4294967296'::BIGINT), | ||
cid BYTEA NOT NULL, -- the cid of the event as bytes no 0x00 prefix | ||
discovered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
delivered BIGINT UNIQUE, -- monotonic increasing counter indicating this can be delivered to clients | ||
PRIMARY KEY(cid) | ||
); | ||
|
||
SELECT order_key, ahash_0, ahash_1, ahash_2, ahash_3, ahash_4, ahash_5, ahash_6, ahash_7, cid, discovered, delivered FROM "event" WHERE false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Add down migration script here | ||
DROP TABLE IF EXISTS event_block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- Add up migration script here | ||
CREATE TABLE IF NOT EXISTS event_block ( | ||
event_cid BYTEA NOT NULL, | ||
block_multihash BYTEA NOT NULL, | ||
codec BIGINT NOT NULL, -- the codec of the block | ||
idx INTEGER NOT NULL, -- the index of the block in the CAR file | ||
"root" BOOL NOT NULL, -- when true the block is a root in the CAR file | ||
PRIMARY KEY(event_cid, block_multihash), | ||
foreign KEY(event_cid) references event(cid), | ||
foreign KEY(block_multihash) references block(multihash) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_event_block_multihash ON event_block (block_multihash); | ||
|
||
SELECT event_cid, block_multihash, codec, idx, "root" FROM event_block WHERE false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Add down migration script here | ||
DROP TABLE IF EXISTS "root"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- Add up migration script here | ||
CREATE TABLE IF NOT EXISTS "root" ( | ||
tx_hash BYTEA NOT NULL, | ||
"root" BYTEA NOT NULL, | ||
block_hash TEXT NOT NULL, | ||
"timestamp" BIGINT NOT NULL, | ||
PRIMARY KEY(tx_hash) | ||
); | ||
|
||
SELECT tx_hash, "root", block_hash, "timestamp" FROM "root" WHERE false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# pip install multiformats | ||
# pip install cbor2 | ||
import multiformats | ||
import cbor2 | ||
import sys | ||
|
||
# # usage | ||
# > cat something.car | python3 car_view.py | ||
|
||
# CAR file format | ||
# | length | Header | | ||
# | length | CID | block | | ||
# ... | ||
# | length | CID | block | | ||
|
||
car_bytes = sys.stdin.buffer.read() # read the car file from stdin | ||
length, _, rest = multiformats.varint.decode_raw(car_bytes) # file starts with the header length varint | ||
head = cbor2.loads(rest[:length]) # read the header CBOR object {'roots': [CID], 'version': 1} | ||
rest = rest[length:] # move up the pointer | ||
print(head) | ||
|
||
while rest: | ||
# | length | CID | block | | ||
length, _, rest = multiformats.varint.decode_raw(rest) # read the block length varint | ||
cid_and_block = rest[:length] | ||
cid = multiformats.CID.decode(cid_and_block[:36]) # CID first 36 bytes | ||
block = cid_and_block[36:] # block rest bytes | ||
obj = cbor2.loads(block) if cid.codec.name == "dag-cbor" else block | ||
rest = rest[length:] # move up the pointer | ||
print(cid.encode(base="base16"), obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.