How to change the directory to look up in flyway? - flyway

Usually flyway looks in /sql for queries.
But i wana give some different location..say c:/User/Queries.
How to configure flyway to look into diff folder?

Use the flyway.locationsproperty.
Example: flyway.locations=filesystem:c:/User/Queries

To pass this in command line arguments.
For Flyway Info
flyway info -locations=filesystem:./migration -user=username -password=password -url=jdbc:postgresql://localhost:portNo/dBName
For Flyway Migrate
flyway migrate -locations=filesystem:./migration -user=username -password=password -url=jdbc:postgresql://localhost:portNo/dBName

Related

Flyway migrate says schema is up to date

I have installed Flyway in my server and trying to execute a My-sql file which I placed in sql folder of flyway.
I have done Flyway baseline, and when I run flyway migrate it says "Schema xyz is up to date. No migration necessary." No matter what I do it always gives me the same result.
My sql files are named 1__act.sql, 2__act.sql, 3__act.sql.
My config file has
flyway.url=jdbc:mysql://mysql:port/xyz
flyway.user=flywayuser
flyway.password=flywaypassword
flyway.baselineVersion=1
You haven't followed the naming conventions for Versioned SQL migrations, they should be prefixed with a V. e.g. V1__act.sql.
Note that the prefix is configurable, but above is the default.
/src/main/resources/db/migration needs to be a source folder in Eclipse/Spring Tool Suite. Right-click it, Build Path, Use as Source Folder.

how Database.Migrate() method work? can it downgrade database?

I can't find official documentation of this method.
All I found is that it apply migrations that didn't applied yet (and create db if not exists).
but how it work?
is it look at the db Migration History table to see which migration missed?
and what if somehow it see that Migration History table has more migrations than in migrations folder? is it downgrade them?
thanks!
Does it look at the db Migration History table to see which migration are missing?
Yes, and applies any missing migrations in chronological order.
What if somehow it sees that the Migration History table has more migrations than in the migrations folder? Does it revert them?
It does nothing. They might be for a different model/DbContext/application that is using the same database.

How to run module migrations programatically in FuelPHP?

For some of my tests, I need the setUpBeforeClass method to run migrations on any modules present, and the tearDownAfterClass to migrate the modules back down again. Via the command line this is easy to do:
oil r migrate --modules
...to run the module migrations, and then:
oil r migrate --modules --version=0
...to reset them. However, in the tests I need to do this programatically, and I can't figure out how to execute the above commands using FuelPHP's Migrate class. Both the latest and version methods seem to require you to specify a module name, but I just want to migrate any modules that are present. Is this possible?
You need some hack to make this working.
Here is how oil does it:
https://github.com/fuel/core/blob/1.8/develop/tasks/migrate.php#L101
Alternatively you can use Module::loaded() to get the loaded modules.
You can then run migrations for each module.
Migrations are run by the Migrate class, so you can use that in your code if you want to run migrations:
$results = Migrate::up(null, 'mymodulename', 'module');
Similarly to the task you can also use down() and current().
Note that this will not load the module, so if one of your module migrations requires a class from the module, make sure to load the module first!

Is it possible to override flyway.url setting in flyway.conf from command line in flyway?

Is it possible to override url that is given in .conf file when invoking migrate from command line?
flyway -flyway.url=jdbc:jtds:sqlserver://test_sqlserver:1433/mydatabase migrate
This above does not seem to work.
Yes. Command-line options are not prefixed with flyway.
In your case this would mean
flyway -url=jdbc:jtds:sqlserver://test_sqlserver:1433/mydatabase migrate
To expand on that comment:
-D sets a system property (in this case flyway.baselineVersion), it's a parameter to java, not to flyway.
-baselineVersion=1 is a parameter to flyway
Both happen to work only because flyway uses both command line arguments and system properties (in addition to the configuration file), they are not otherwise related.

How use only one schema on flyway

I need to work only with one schema on flyway.
but when i use
Flyway flyway = new Flyway();
flyway.setDataSource(ConectorWatson);
flyway.setSchemas("db_watson");
flyway.migrate();
the flyway create one schema_version on my pulic schema and db_watson.
can i only use db_watson ?
tks
Flyway only creates a schema_version table in the first schema configured. This defaults to the one of the connection. When you set flyway.setSchemas() it changes it to the first of that list, and uses that one.
In your case this means, with the configuration you have there, Flyway only creates a schema_version table in the db_watson schema.
If you noticed something different, please file an issue with exact steps to reproduce.

Resources