From 25fbc4685ef500c7329e2ea27d3450b2017a3b20 Mon Sep 17 00:00:00 2001 From: Matthew Eric Bassett Date: Mon, 8 Jun 2020 15:02:30 +0100 Subject: [PATCH] mod - idempotent migration file. the handwritten migration file itself is silly, persistent should take care of it. but while its here it is a lot less problematic if you use "if not exists" statements, as it allows db-sync to startup without crashing. we could also use the migration version numbers as found in the other migration files, but I opted not to do that because I was worried about breaking things for other migrations. --- schema/migration-4-0001-20200605.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/schema/migration-4-0001-20200605.sql b/schema/migration-4-0001-20200605.sql index 62b4094ea..843ca6c7d 100644 --- a/schema/migration-4-0001-20200605.sql +++ b/schema/migration-4-0001-20200605.sql @@ -17,11 +17,10 @@ CREATE FUNCTION migrate() RETURNS void AS $$ BEGIN - EXECUTE 'create table tx_body (id serial8 primary key unique, - hash hash32type not null, + 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 idx_tx_body_hash ON tx_body(hash);'; - EXECUTE 'ALTER TABLE "tx_body" ADD CONSTRAINT "unique_tx_body" UNIQUE("hash")' ; + EXECUTE 'CREATE INDEX if not exists idx_tx_body_hash ON tx_body(hash);'; END; $$ LANGUAGE plpgsql;