-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db: Drop constraint on lovelace database type
This is a workaround fix for: #351 This fix will not require the database to be re-synced, but will result in some bad values being display as negative value.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-- Hand written migration to create the custom types with 'DOMAIN' statements. | ||
|
||
CREATE FUNCTION migrate() RETURNS void AS $$ | ||
|
||
DECLARE | ||
next_version int; | ||
|
||
BEGIN | ||
SELECT stage_one + 1 INTO next_version FROM "schema_version"; | ||
IF next_version = 1 THEN | ||
EXECUTE 'ALTER DOMAIN lovelace DROP CONSTRAINT lovelace_check; '; | ||
EXECUTE 'CREATE DOMAIN txindex AS smallint CHECK (VALUE >= 0 AND VALUE < 1024);'; | ||
EXECUTE 'CREATE DOMAIN uinteger AS integer CHECK (VALUE >= 0);'; | ||
|
||
-- Blocks, transactions and merkel roots use a 32 byte hash. | ||
EXECUTE 'CREATE DOMAIN hash32type AS bytea CHECK (octet_length (VALUE) = 32);'; | ||
|
||
-- Addresses use a 28 byte hash (as do StakeholdIds). | ||
EXECUTE 'CREATE DOMAIN hash28type AS bytea CHECK (octet_length (VALUE) = 28);'; | ||
|
||
-- Stake addresses are a 28 byte hash prepended with a byte describing the address. | ||
EXECUTE 'CREATE DOMAIN addr29type AS bytea CHECK (octet_length (VALUE) = 29);'; | ||
|
||
-- 'maxBound :: Word128' as a decimal has 39 digits, so we only need to check that it | ||
-- is positive. | ||
EXECUTE 'CREATE DOMAIN word128type AS numeric (38, 0) CHECK (VALUE >= 0);'; | ||
|
||
-- 'maxBound :: Word64' as a decimal has 20 digits but not all 20 digit values are less than | ||
-- 'maxBound :: Word64'. | ||
EXECUTE 'CREATE DOMAIN word64type AS numeric (20, 0) CHECK (VALUE >= 0 AND VALUE <= 18446744073709551615);'; | ||
|
||
UPDATE "schema_version" SET stage_one = 1; | ||
RAISE NOTICE 'DB has been migrated to stage_one version %', next_version; | ||
END IF; | ||
END; | ||
|
||
$$ LANGUAGE plpgsql; | ||
|
||
SELECT migrate(); | ||
|
||
DROP FUNCTION migrate(); |