Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ fromAlonzoTx pp (blkIndex, tx) =

encodeData :: Alonzo.Data StandardAlonzo -> ByteString
encodeData dt = LBS.toStrict $ Aeson.encode $
Api.scriptDataToJson Api.ScriptDataJsonDetailedSchema $ Api.fromAlonzoData dt
Api.scriptDataToJson Api.ScriptDataJsonNoSchema $ Api.fromAlonzoData dt
Copy link
Contributor

@sorki sorki Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this one? Wouldn't we loose some expressiveness regarding constructors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DetailedSchema doesn't seem very user friendly

Copy link
Contributor

@sorki sorki Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should keep using DetailedSchema to have the full representational capacity as outlined in https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L238-L299

Quoting the most relevant part

It also means any script data can be converted into the JSON and
back without loss. That is we can round-trip the script data via the JSON and
also round-trip schema-compliant JSON via script data.

which according to my understanding means that NoSchema is lossy as in some cases you can't convert NoSchema JSON to original ScriptData.

If an explorer or some tool wants to display user-friendly NoSchema it can convert DetailedSchema to ScriptData and then build NoSchema one.


txDataWitness :: [TxDatum]
txDataWitness =
Expand Down
4 changes: 2 additions & 2 deletions cardano-db/src/Cardano/Db/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ share
minPoolCost DbLovelace Maybe sqltype=lovelace

coinsPerUtxoWord DbLovelace Maybe sqltype=lovelace
costModelsId CostModelsId Maybe
costModelsId CostModelsId Maybe OnDeleteCascade
priceMem Double Maybe -- sqltype=rational
priceStep Double Maybe -- sqltype=rational
maxTxExMem DbWord64 Maybe sqltype=word64type
Expand Down Expand Up @@ -452,7 +452,7 @@ share
nonce ByteString Maybe sqltype=hash32type

coinsPerUtxoWord DbLovelace Maybe sqltype=lovelace
costModelsId CostModelsId Maybe
costModelsId CostModelsId Maybe OnDeleteCascade
priceMem Double Maybe -- sqltype=rational
priceStep Double Maybe -- sqltype=rational
maxTxExMem DbWord64 Maybe sqltype=word64type
Expand Down
23 changes: 23 additions & 0 deletions schema/migration-2-0024-20210910.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Persistent generated migration.

CREATE FUNCTION migrate() RETURNS void AS $$
DECLARE
next_version int ;
BEGIN
SELECT stage_two + 1 INTO next_version FROM schema_version ;
IF next_version = 24 THEN
EXECUTE 'ALTER TABLE "redeemer" ADD CONSTRAINT "redeemer_datum_id_fkey" FOREIGN KEY("datum_id") REFERENCES "datum"("id") ON DELETE CASCADE ON UPDATE RESTRICT' ;
EXECUTE 'ALTER TABLE "param_proposal" DROP CONSTRAINT "param_proposal_cost_models_id_fkey"' ;
EXECUTE 'ALTER TABLE "param_proposal" ADD CONSTRAINT "param_proposal_cost_models_id_fkey" FOREIGN KEY("cost_models_id") REFERENCES "cost_models"("id") ON DELETE CASCADE ON UPDATE RESTRICT' ;
EXECUTE 'ALTER TABLE "epoch_param" DROP CONSTRAINT "epoch_param_cost_models_id_fkey"' ;
EXECUTE 'ALTER TABLE "epoch_param" ADD CONSTRAINT "epoch_param_cost_models_id_fkey" FOREIGN KEY("cost_models_id") REFERENCES "cost_models"("id") ON DELETE CASCADE ON UPDATE RESTRICT' ;
-- Hand written SQL statements can be added here.
UPDATE schema_version SET stage_two = next_version ;
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
END IF ;
END ;
$$ LANGUAGE plpgsql ;

SELECT migrate() ;

DROP FUNCTION migrate() ;