title: Apply migration on multiple schemas using Java and Liquibase
body: <p>I'm trying to apply migration over my multi tenant system where I have one database with multiple schemas,<br>
  And I do so by first getting all the tenants then loop over them and execute the update on <code>liquibase</code> after changing the schema, but it seems that the schema is not changed cause after performing the migration on the first tenant the second tenant throws an error complaining about table already exist.<br></p>
  <pre><code>    @Override
      @SneakyThrows
      public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
          Connection connection = null;
          Statement statement = null;
          Liquibase liquibase = null;
          try {
              connection = dataSource.getConnection();
              statement = connection.createStatement();
              ResultSet result = statement.executeQuery(&quot;SELECT nspname FROM pg_namespace WHERE nspname like 'tenant_%'&quot;);
  
              
              List&lt;String&gt; schemas = new ArrayList&lt;&gt;();
              while (result.next()) {
                  schemas.add(result.getString(1));
              }
              
              for (String schemaName:schemas) {
                  
                  connection.setSchema(schemaName);
  
                  Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
                  database.setDefaultSchemaName(schemaName);
  
                  log.info(&quot;Schema Name: {}&quot;,connection.getSchema());
  
                  liquibase = new Liquibase(CHANGE_LOG_FILE, new ClassLoaderResourceAccessor(), database);
                  liquibase.update(new Contexts(), new LabelExpression());
              }
          } catch (SQLException | DatabaseException e) {
              e.printStackTrace();
          }finally {
              if(liquibase!=null) {
                  liquibase.close();
              }
              if(statement!=null&amp;&amp;!statement.isClosed()) {
                  statement.close();
              }
              if(connection!=null&amp;&amp;!connection.isClosed()){
                  connection.close();
              }
          }
      }
  </code></pre>
  <br>
  Note: the reason I made it in different loops and not using `try-with-resource` is that the connection closes after getting the first row of the result set and updating the database so I had to close it myself