mvn flyway:baseline does not run my V1_0__baseline.sql script - mysql

I have an existing MySQL database. I dumped the schema out to a file named V1_0__baseline.sql which I placed in src/main/resources/db/migration.
My pom.xml looks just like the example in the docs.
mvn flyway:clean will destroy any existing tables and remove the database.
mvn flyway:baseline will create the database but only creates the schema_version table -- it does not seem to run any of the SQL in my V1_0__baseline.sql file.
mvn flyway:info reports:
+---------+------------------------+---------------------+---------+
| Version | Description | Installed on | State |
+---------+------------------------+---------------------+---------+
| 1.0 | baseline | 2016-03-16 00:15:24 | Success |
| 2.1 | oauth integrations | | Pending |
| 2.2 | base unified reporting | | Pending |
+---------+------------------------+---------------------+---------+
From reading the docs that is not what I expected. I thought it would run all the SQL in my V1_0__baseline.sql file and give me my starting schema.
Have I completely misunderstood or am I missing something that would make this work as I imagined?

Related

How to Sync MySQL Databases when offline?

My application that is running on a client uses a MySQL database running on a server. So multiple clients are connected to the same server. That works well when the server is online. But now I would like to enhance my application to be able to run in an offline mode.
+--------------+
| |
+-----------+ SERVER +----------+
| | | |
| +-------+------+ |
| | |
+------+-------+ +-------+------+ +-------+------+
| | | | | |
| Client 1 | | Client 2 | | Client X |
| | | | | |
+--------------+ +--------------+ +--------------+
Now comes the problem: what happens when the client is offline? I need a copy of my MySQL database on each client too. By default the application interacts with the MySQL on the server. If this server is not accessible (for what reason ever: server is offline or client has no internet connection) it should use the MySQL running on the client. If the client/server connection is available again the databases need to be synched automatically.
My question is now: how to achieve this? First of all I checked the MySQL-replication, but in my scenario I have multiple "masters" and an unknown number of clients. So I afraid that replication is not my solution. Is it possible to solve my problem with MaxScale? I never worked with that so I really appreciate any help.

FlywaySqlException: Unable to insert row for version `11` in Schema History table `schema_version`: Field `version_rank` doesn't have a default value

I'm getting this error when running my Spring Boot app with a new migration. It has worked for 10 migrations so far. The field does indeed not have a default value. There shouldn't be a need for a default because Flyway should be inserting the value 11 in that field.
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to insert row for version '11' in Schema History table `app`.`schema_version`
--------------------------------------------------------------------------------------------
SQL State : HY000
Error Code : 1364
Message : Field 'version_rank' doesn't have a default value
at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.doAddAppliedMigration(JdbcTableSchemaHistory.java:174) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.schemahistory.SchemaHistory.addAppliedMigration(SchemaHistory.java:170) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.command.DbMigrate.applyMigrations(DbMigrate.java:299) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.command.DbMigrate.migrateGroup(DbMigrate.java:244) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.command.DbMigrate.access$100(DbMigrate.java:53) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.command.DbMigrate$2.call(DbMigrate.java:163) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.command.DbMigrate$2.call(DbMigrate.java:160) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.database.mysql.MySQLNamedLockTemplate.execute(MySQLNamedLockTemplate.java:60) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.database.mysql.MySQLConnection.lock(MySQLConnection.java:80) ~[flyway-core-5.1.4.jar:na]
at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.lock(JdbcTableSchemaHistory.java:150) ~[flyway-core-5.1.4.jar:na]
pom.xml
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.1.4</version><!--$NO-MVN-MAN-VER$-->
</dependency>
application.properties
# Prevent complaints when starting migrations with existing tables.
flyway.baselineOnMigrate = true
flyway.table=schema_version
schema_version
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+-------------------+-------+
| version_rank | int(11) | NO | MUL | NULL | |
| installed_rank | int(11) | NO | MUL | NULL | |
| version | varchar(50) | NO | PRI | NULL | |
| description | varchar(200) | NO | | NULL | |
| type | varchar(20) | NO | | NULL | |
| script | varchar(1000) | NO | | NULL | |
| checksum | int(11) | YES | | NULL | |
| installed_by | varchar(100) | NO | | NULL | |
| installed_on | timestamp | NO | | CURRENT_TIMESTAMP | |
| execution_time | int(11) | NO | | NULL | |
| success | tinyint(1) | NO | MUL | NULL | |
How am I going to create a migration to add a default value if the migrations don't even work?
Flyway 5.1.4, Spring Boot 5.1.13, mysql Ver 15.1 Distrib 10.1.30-MariaDB, for CYGWIN (i686)
It looks like this problem occurs if you upgrade from Flyway 3.x straight to 5.x, bypassing 4.x.
Spring Boot 1.5 uses Flyway 3.x by default, whereas Spring Boot 2.x uses Flyway 5.x.
From the Flyway 5.0.0 release notes:
Important note for users upgrading from Flyway 3.x: This release no longer supports a schema history table upgrade from Flyway 3.x. You must upgrade to Flyway 4.2.0 first before upgrading to Flyway 5.0.0.
From the Spring Boot 2 Migration Guide:
Upgrading to Spring Boot 2 will upgrade Flyway from 3.x to 5.x. To make sure that the schema upgrade goes smoothly, please follow the following instructions:
First upgrade your 1.5.x Spring Boot application to Flyway 4 (4.2.0 at the time of writing), see the instructions for Maven and Gradle.
Once your schema has been upgraded to Flyway 4, upgrade to Spring Boot 2 and run the migration again to port your application to Flyway 5.
The migration guide also links to a blog post with an alternative approach.
There was issue raised about Spring Boot skipping Flyway 4.x and one against Flyway for the version_rank exception you were getting.
Looks like quite a few others have hit this same problem.
Had to
manually add a default value to the field by writing it into the top of the migration that already ran but would not save
alter table schema_version alter column version_rank set default 0;
comment the other lines in the migration because they already ran
-- alter table myTable add column createdAt date;
-- ...
migrate again to add the row to schema_version
mvn flyway:migrate -Dflyway.user=user -Dflyway.password= -Dflyway.url=jdbc:mysql://localhost:3306/app -Dflyway.table=schema_version
uncomment the lines in the migration so they will be applied down the pipeline
validate
mvn flyway:validate -Dflyway.user=user -Dflyway.password= -Dflyway.url=jdbc:mysql://localhost:3306/app -Dflyway.table=schema_version
[ERROR] -> Applied to database : 1445435712
[ERROR] -> Resolved locally : -1275756780
copy the checksum into the schema_version table manually so it won't complain in development anymore
update schema_version set checksum = -1275756780 where version = 11;
Hopefully it will just work in staging & production.
Maybe FlyWay should use Rails migrations to manage its own schema?
I know DB versioning is a hard problem and FlyWay is supposed to make it easier, but sometimes it feels like it's more work than just using custom SQL scripts or manual deployment checklists. I couldn't find any mention of this problem, and my last migration was around the end of July. Maybe everyone had stopped using it by now? I've only been using it since May and have had so many problems (table name change, checksum calculation change, now this).

How to install federated engine to my mariadb?

I know many of post have mention mariadb in xampp already include federated engine, but unfortunately the federated engine hasn't installed in my mariadb as you can see in the table below.
MariaDB [information_schema]> show engines;
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| CSV | YES | CSV storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, foreign keys and encryption for tables | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| SEQUENCE | YES | Generated tables filled with sequential values | YES | NO | YES |
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.00 sec)
I also tried to follow the guide here and run this command INSTALL PLUGIN federated SONAME 'ha_federatedx.so'; but got error ERROR 1126 (HY000): Can't open shared library 'D:\xampp\mysql\lib\plugin\ha_federatedx.so.dll' (errno: 2, The specified module could not be found. . Can anyone tell me how to install the federated engine without re-install xampp? My database version is mysql Ver 15.1 Distrib 10.1.10-MariaDB, for Win32 (AMD64)
I know this answer likely comes several years too late, but I was having the same problem this morning on a Windows development machine. I tried ...
INSTALL PLUGIN federated SONAME 'ha_federatedx.so';
... but it didn't work, and I received the same error as Deno did. After some searching, I found that *.so files are Linux shared library files, so I tried the following command ...
INSTALL PLUGIN federated SONAME 'ha_federatedx.dll';
... and it worked! The only caveat is I am working with an actual install of MariaDB, not the version installed in XAMPP, so the actual DLL file might need to be installed in XAMPP.
Hopefully, this will help someone else who is experiencing the same problem.

Linux Mint trigger slowly query on mysql on system booting

My debian-based is booting so slow after I installed MySQL and imported some databases on it. Looking for some statement, I found this one during boot:
mysql> show full processlist;
+----+------------------+-----------+------+---------+------+----------------+----------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------------------+-----------+------+---------+------+----------------+----------------------------------------------------------------------+
| 9 | debian-sys-maint | localhost | NULL | Query | 12 | Opening tables | select count(*) into #discard from `information_schema`.`PARTITIONS` |
| 10 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
+----+------------------+-----------+------+---------+------+----------------+----------------------------------------------------------------------+
2 rows in set (0.00 sec)
Here the statement that causing trouble:
select count(*) into #discard from `information_schema`.`PARTITIONS`
I have +-10 databases totaling over 8gb of data.
Is there any configuration to disable this query on system booting ? If yes, why run it during boot ?
Information
I have a standard MySQL installation without custom configs.
Best regards.
It seems Debian, whose Linux Mint is based upon, have scripts that get executed when the mysql server is started or restarted, to check for corrupted tables and make an alert for that.
In my Debian server, the culprit seems to be /etc/mysql/debian-start bash script, which in turn calls /usr/share/mysql/debian-start.inc.sh , so check both scripts and comment out the function that is iterating all your tables, from a quick look it seems the following:
check_for_crashed_tables;
which is called from the debian-start script I mentioned above.

how to pass parameters from html page to batch file

I have the following requirement. I need to pass parameters from html page to batch file which in turn passes the paramter to xml file.I need to know how to pass parameters from html to batch file and from batch file to xml file
Thanks
What kind of "parameters"? What kind of "html page"? What kind of "batch file"? What kind of "xml file"?
Assuming that you mean that data from a HTML form should be processed by a batch file and written to disc as XML:
Data from HTML forms is always processed using the CGI protocol, and it's possible to do it with a batch script, probably even a Windows batch file.
However, this is going to be extremely uncomfortable, error-prone and insecure. It's much better to have a language or framework specifically geared towards web applications handle the low-level CGI stuff for you.
Common choices are: PHP, Perl, Java servlets or ASP.
While it's possible to write XML simply by outputting strings, you're virtually guaranteed to get malformed XML eventually.
It's much better to use a real XML framework to produce the XML - there are several to choose from for pretty much any language worth using.
m.mahesh.2000, it might be worth you drawing a little diagram of the various parts of the puzzle. HTML and XML files are not programs!
Consider these possible diagrams:
CGI Approach:
+--------------+ +----------------+
| Browser | | Web Server |
| | | (eg: Apache) |
| +----------+ | | +------------+ |
| |HTML | | --> | | CGI | |
| |Javascript| | | | | |
| +----------+ | | | +-------+ | |
+--------------+ | | | Perl | | |
| | +-------+ | |
| +------------+ |
+----------------+
Servlet Container Approach:
+--------------+ +------------------+
| Browser | | Tomcat |
| | | |
| +----------+ | | +-------------+ |
| |HTML | | --> | | Servlet | |
| |Javascript| | | | Container | |
| +----------+ | | | +---------+ | |
+--------------+ | | | Servlet | | |
| | +---------+ | |
| +-------------+ |
+------------------+
The browser renders your HTML, executes any javascript, and sends HTTP requests to your server - be this Apache, Tomcat, or other? Do you know what kind of server you have?
Apache spawns child CGI processes to act on certain HTTP requests. CGI processes are typically PHP or Perl scripts.
Tomcat has a number of threads to act on HTTP requests. Some requests are handled by Servlet instances hosted within a Servlet container.
Either the CGI process, or the servlet, will do the work of creating your XML file on the server, and contacting your database.
Hope this helps.
Are the batch file and xml file client or server side?
Either way you will need to add some script to the html file. Or even use server side scripting to generate the html...