Skip to content

Commit

Permalink
mod - idempotent migration file.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthew Eric Bassett committed Jul 8, 2020
1 parent b1302e0 commit 25fbc46
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions schema/migration-4-0001-20200605.sql
Expand Up @@ -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;
Expand Down

0 comments on commit 25fbc46

Please sign in to comment.