Skip to content

Commit

Permalink
add - table mapping tx hashes to bodies.
Browse files Browse the repository at this point in the history
it would make sense for this just to sit in the tx table, but see
doc/plugin-system.md
also note that I used a hand written migration file.  see comment in the file
about being unable to get the migration tool to run. :(
  • Loading branch information
Matthew Eric Bassett committed Jul 8, 2020
1 parent 362b09e commit b1302e0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cardano-db/src/Cardano/Db/Insert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Cardano.Db.Insert
, insertStakeAddress
, insertStakeRegistration
, insertTx
, insertTxBody
, insertTxIn
, insertTxOut
, insertWithdrawal
Expand Down Expand Up @@ -58,6 +59,7 @@ insertPoolHash = insertByReturnKey "PoolHash"
insertPoolMetaData :: (MonadBaseControl IO m, MonadIO m) => PoolMetaData -> ReaderT SqlBackend m PoolMetaDataId
insertPoolMetaData = insertByReturnKey "PoolMetaData"


insertPoolOwner :: (MonadBaseControl IO m, MonadIO m) => PoolOwner -> ReaderT SqlBackend m PoolOwnerId
insertPoolOwner = insertByReturnKey "PoolOwner"

Expand Down Expand Up @@ -85,6 +87,9 @@ insertStakeRegistration = insertByReturnKey "StakeRegistration"
insertTx :: (MonadBaseControl IO m, MonadIO m) => Tx -> ReaderT SqlBackend m TxId
insertTx = insertByReturnKey "Tx"

insertTxBody :: (MonadBaseControl IO m, MonadIO m) => TxBody -> ReaderT SqlBackend m TxBodyId
insertTxBody = insertByReturnKey "TxBody"

insertTxIn :: (MonadBaseControl IO m, MonadIO m) => TxIn -> ReaderT SqlBackend m TxInId
insertTxIn = insertByReturnKey "TxIn"

Expand Down
5 changes: 5 additions & 0 deletions cardano-db/src/Cardano/Db/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ share
size Word64 sqltype=uinteger
UniqueTx hash

TxBody
hash ByteString sqltype=hash32type
body ByteString sqltype=bytea
UniqueTxBody hash

TxOut
txId TxId -- This type is the primary key for the 'tx' table.
index Word16 sqltype=txindex
Expand Down
31 changes: 31 additions & 0 deletions schema/migration-4-0001-20200605.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Hand written migration because I cann't get the schema migration tool to work.
-- see doc/schema-management.md for context.
-- `cabal run cardano-db-sync-db-tool -- create-migration --mdir schema/` does not work.
-- I've tried running it from within nix-shell. I get the following:
--
--
-- cabal: Could not resolve dependencies:
-- [__0] trying: cardano-binary-test-1.3.0 (user goal)
-- [__1] unknown package: quickcheck-instances (dependency of
-- cardano-binary-test)
-- [__1] fail (backjumping, conflict set: cardano-binary-test,
-- quickcheck-instances)
-- After searching the rest of the dependency tree exhaustively, these were the
-- goals I've had most trouble fulfilling: cardano-binary-test,
-- quickcheck-instances

CREATE FUNCTION migrate() RETURNS void AS $$

BEGIN
EXECUTE 'create table tx_body (id serial8 primary key unique,
hash hash32type not null,
body bytea not null)';
EXECUTE 'CREATE INDEX idx_tx_body_hash ON tx_body(hash);';
EXECUTE 'ALTER TABLE "tx_body" ADD CONSTRAINT "unique_tx_body" UNIQUE("hash")' ;
END;

$$ LANGUAGE plpgsql;

SELECT migrate();

DROP FUNCTION migrate();

0 comments on commit b1302e0

Please sign in to comment.