diff --git a/schema/migration-2-0002-20200625.sql b/schema/migration-2-0002-20200625.sql new file mode 100644 index 000000000..061c19bf0 --- /dev/null +++ b/schema/migration-2-0002-20200625.sql @@ -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 = 2 THEN + EXECUTE 'CREATe TABLE "tx_body"("id" SERIAL8 PRIMARY KEY UNIQUE,"hash" hash32type NOT NULL,"body" bytea NOT NULL)' ; + EXECUTE 'ALTER TABLE "tx_body" ADD CONSTRAINT "unique_tx_body" UNIQUE("hash")' ; + -- Hand written SQL statements can be added here. + UPDATE schema_version SET stage_two = 2 ; + RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ; + END IF ; +END ; +$$ LANGUAGE plpgsql ; + +SELECT migrate() ; + +DROP FUNCTION migrate() ; diff --git a/schema/migration-4-0001-20200605.sql b/schema/migration-4-0001-20200605.sql deleted file mode 100644 index 843ca6c7d..000000000 --- a/schema/migration-4-0001-20200605.sql +++ /dev/null @@ -1,30 +0,0 @@ --- 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 if not exists tx_body (id serial8 primary key unique, - hash hash32type not null unique, - body bytea not null)'; - EXECUTE 'CREATE INDEX if not exists idx_tx_body_hash ON tx_body(hash);'; -END; - -$$ LANGUAGE plpgsql; - -SELECT migrate(); - -DROP FUNCTION migrate();