This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,970 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/var/run/postgresql:5432:smash:*:* |
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,22 @@ | ||
-- Hand written migration that creates a 'schema_version' table and initializes it. | ||
|
||
CREATE FUNCTION init() RETURNS void AS $$ | ||
|
||
DECLARE | ||
emptyDB boolean; | ||
|
||
BEGIN | ||
SELECT NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='schema_version') INTO emptyDB; | ||
IF emptyDB THEN | ||
CREATE TABLE "schema_version" (id SERIAL PRIMARY KEY UNIQUE, stage_one INT8 NOT NULL, stage_two INT8 NOT NULL, stage_three INT8 NOT NULL); | ||
INSERT INTO "schema_version" (stage_one, stage_two, stage_three) VALUES (0, 0, 0); | ||
|
||
RAISE NOTICE 'DB has been initialized'; | ||
END IF; | ||
END; | ||
|
||
$$ LANGUAGE plpgsql; | ||
|
||
SELECT init(); | ||
|
||
DROP FUNCTION init(); |
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,33 @@ | ||
-- 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 | ||
CREATE DOMAIN lovelace AS bigint CHECK (VALUE >= 0 AND VALUE <= 45000000000000000); | ||
CREATE DOMAIN txindex AS smallint CHECK (VALUE >= 0 AND VALUE < 1024); | ||
CREATE DOMAIN uinteger AS integer CHECK (VALUE >= 0); | ||
|
||
-- Base16 encoded values use a 64 byte hash. | ||
CREATE DOMAIN base16type AS bytea CHECK (octet_length (VALUE) = 64); | ||
|
||
-- Blocks, transactions and merkel roots use a 32 byte hash. | ||
CREATE DOMAIN hash32type AS bytea CHECK (octet_length (VALUE) = 32); | ||
|
||
-- Addresses use a 28 byte hash (as do StakeholdIds). | ||
CREATE DOMAIN hash28type AS bytea CHECK (octet_length (VALUE) = 28); | ||
|
||
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(); |
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,20 @@ | ||
-- 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 = 1 THEN | ||
CREATe TABLE "tx_metadata"("id" SERIAL8 PRIMARY KEY UNIQUE,"hash" base16type NOT NULL,"metadata" json NOT NULL); | ||
ALTER TABLE "tx_metadata" ADD CONSTRAINT "unique_tx_metadata" UNIQUE("hash"); | ||
-- Hand written SQL statements can be added here. | ||
UPDATE schema_version SET stage_two = 1 ; | ||
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ; | ||
END IF ; | ||
END ; | ||
$$ LANGUAGE plpgsql ; | ||
|
||
SELECT migrate() ; | ||
|
||
DROP FUNCTION migrate() ; |
Oops, something went wrong.