-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db: Update the schema wrt to multi-assets
* Add a new table `multi_asset` which includes the asset fingerprint. * Add a reference from `ma_tx_mint` and `ma_tx_out` to `multi_asset`. * Drop the `policy` and `name` fields of `ma_tx_mint` and `ma_tx_out`. Closes: #868
- Loading branch information
Showing
6 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
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,30 @@ | ||
-- 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 = 2 THEN | ||
EXECUTE 'CREATe TABLE "multi_asset"("id" SERIAL8 PRIMARY KEY UNIQUE,"policy" hash28type NOT NULL,"name" asset32type NOT NULL,"fingerprint" VARCHAR NOT NULL)' ; | ||
EXECUTE 'ALTER TABLE "multi_asset" ADD CONSTRAINT "unique_multi_asset" UNIQUE("policy","name")' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_mint" ADD COLUMN "ident" INT8 NOT NULL' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_mint" DROP COLUMN "policy"' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_mint" DROP COLUMN "name"' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_mint" DROP CONSTRAINT IF EXISTS "unique_ma_tx_mint"' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_mint" ADD CONSTRAINT "unique_ma_tx_mint" UNIQUE("ident","tx_id")' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_out" ADD COLUMN "ident" INT8 NOT NULL' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_out" DROP COLUMN "policy"' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_out" DROP COLUMN "name"' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_out" DROP CONSTRAINT IF EXISTS "unique_ma_tx_out"' ; | ||
EXECUTE 'ALTER TABLE "ma_tx_out" ADD CONSTRAINT "unique_ma_tx_out" UNIQUE("ident","tx_out_id")' ; | ||
-- 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() ; |