Created
August 10, 2022 17:52
-
-
Save sascha1337/e510b2a0f8cd5b25fb5c4ada59d4afe6 to your computer and use it in GitHub Desktop.
IBC-ETL FTW
This file contains hidden or 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
func createTables(db *sql.DB) error { | |
txs := "CREATE TABLE IF NOT EXISTS txs ( " + | |
"hash bytea PRIMARY KEY, " + | |
"block_time TIMESTAMP NOT NULL, " + | |
"chainid TEXT NOT NULL, " + | |
"block_height BIGINT NOT NULL, " + | |
"raw_log JSONB NOT NULL," + | |
"code INT NOT NULL, " + | |
"fee_amount TEXT, " + | |
"fee_denom TEXT, " + | |
"gas_used BIGINT NOT NULL," + | |
"gas_wanted BIGINT NOT NULL" + | |
")" | |
transfer := "CREATE TABLE IF NOT EXISTS msg_transfer (" + | |
"tx_hash bytea," + | |
"msg_index INT," + | |
"signer TEXT NOT NULL," + | |
"sender TEXT NOT NULL," + | |
"receiver TEXT NOT NULL," + | |
"amount TEXT NOT NULL," + | |
"denom TEXT NOT NULL," + | |
"src_chan TEXT NOT NULL," + | |
"src_port TEXT NOT NULL," + | |
"route TEXT NOT NULL," + | |
"PRIMARY KEY (tx_hash, msg_index)," + | |
"FOREIGN KEY (tx_hash) REFERENCES txs(hash) ON DELETE CASCADE" + | |
")" | |
recvpacket := "CREATE TABLE IF NOT EXISTS msg_recvpacket ( " + | |
"tx_hash bytea," + | |
"msg_index INT," + | |
"signer TEXT NOT NULL," + | |
"src_chan TEXT NOT NULL," + | |
"dst_chan TEXT NOT NULL," + | |
"src_port TEXT NOT NULL," + | |
"dst_port TEXT NOT NULL," + | |
"PRIMARY KEY (tx_hash, msg_index)," + | |
"FOREIGN KEY (tx_hash) REFERENCES txs(hash) ON DELETE CASCADE" + | |
")" | |
timeout := "CREATE TABLE IF NOT EXISTS msg_timeout (" + | |
"tx_hash bytea," + | |
"msg_index INT," + | |
"signer TEXT NOT NULL," + | |
"src_chan TEXT NOT NULL," + | |
"dst_chan TEXT NOT NULL," + | |
"src_port TEXT NOT NULL," + | |
"dst_port TEXT NOT NULL," + | |
"PRIMARY KEY (tx_hash, msg_index)," + | |
"FOREIGN KEY (tx_hash) REFERENCES txs(hash) ON DELETE CASCADE" + | |
")" | |
acks := "CREATE TABLE IF NOT EXISTS msg_ack (" + | |
"tx_hash bytea," + | |
"msg_index INT," + | |
"signer TEXT NOT NULL," + | |
"src_chan TEXT NOT NULL," + | |
"dst_chan TEXT NOT NULL," + | |
"src_port TEXT NOT NULL," + | |
"dst_port TEXT NOT NULL," + | |
"PRIMARY KEY (tx_hash, msg_index)," + | |
"FOREIGN KEY (tx_hash) REFERENCES txs(hash) ON DELETE CASCADE" + | |
")" | |
tables := []string{txs, transfer, recvpacket, timeout, acks} | |
for _, table := range tables { | |
if _, err := db.Exec(table); err != nil { | |
return err | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment