1
votes

I currently have a .sql file with the likes of:

DROP VIEW IF EXISTS vw_example;

CREATE VIEW vw_example as
SELECT a FROM b;

When running this command as part of a flyway migration, if the view already exists, it fails, as if the create command is not waiting for the DROP IF EXISTS to finish.

I know SQL server has a GO type keyword. Is there a way to sort of tell cockroachdb to wait for the first command?

1
I don't think this is a batching issue in CockroachDB. Try copy-pasting the following several times into the cockroach sql shell (or demo if you're on 19.2+): \| echo "DROP VIEW IF EXISTS vw_example; CREATE VIEW vw_example as SELECT count(1) from pg_settings;". Are you sure slick is executing those statements in the stated order/from a file?Peter Vandivier
@PeterVandivier - I suppose so, but it all runs part of a Flyway migration. I'm not sure if there is code there to parse the file and run statements concurrently - wouldn't make much sense to me, but maybe? When I ran these using DataGrip they always worked as expected.turtlepick

1 Answers

2
votes

As per the issue mentioned in the link, it is better to have the drop and create scripts in different migration files as flyway runs each migration in a single transaction.