0

How can I create tablespace for my Postgres DB dynamically using flyway and java? Trying to create tablespace before executing SQL queries

Flyway flyway = Flyway.configure().dataSource(jdbcTemplate.getDataSource()).baselineOnMigrate(true).locations(migScriptLoc)
                .schemas(schemaName).tablespace("test").locations(locations).load();

This gives me below error

enter code hereWrapped by: org.flywaydb.core.internal.sqlscript.FlywaySqlScriptException: 
Migration  failed
-----------------
SQL State  : 42704
Error Code : 0
Message    : ERROR: tablespace "test" does not exist
Location   :  ()
Line       : 1
Statement  : CREATE TABLE "master"."flyway_schema_history" (
    "installed_rank" INT NOT NULL,
    "version" VARCHAR(50),
    "description" VARCHAR(200) NOT NULL,
    "type" VARCHAR(20) NOT NULL,
    "script" VARCHAR(1000) NOT NULL,
    "checksum" INTEGER,
    "installed_by" VARCHAR(100) NOT NULL,
    "installed_on" TIMESTAMP NOT NULL DEFAULT now(),
    "execution_time" INTEGER NOT NULL,
    "success" BOOLEAN NOT NULL
) TABLESPACE "test" 
rohit kumbhar
  • 121
  • 1
  • 8
  • Either set it to a tablespace that exists (ask your DBA), or just leave it blank, and it will be created in the default tablespace for your database. – Mike Organek Aug 13 '20 at 11:02
  • Recommendation: don't use tablespaces. – Laurenz Albe Aug 13 '20 at 11:11
  • 1
    You could look into using [flyway initSql](https://flywaydb.org/documentation/commandline/migrate#initSql) to do this, or maybe a [beforeMigrate callback](https://flywaydb.org/documentation/callbacks). – Philip Liddell Aug 14 '20 at 08:58

0 Answers0