I want to execute multiple SQL file using flyway with same version.
Solution 1
I try multiple SQL script bind into single SQL script and execute it. But now after some days new script will come and I merge into before create SQL file. That show error. My requirement is I only execute one single SQL file and my database is going to update.
Is there any way to do that?
Solution 2
I try version name with timestamp but that is not satisfied ou requirement. I want only one SQL file and when I migrate then it successfully migrate SQL file as well as when I again migrate new script then it successfully migrate it but all of this process do in single script.
Is there any way to do it?
I am using FlyWay Version 4.2.0.
Flyway uses a history table (flyway_schema_history) to track which migrations were already applied. More than that, this table has a checksum column which is done based on the content of the migration, which means if you change it, checksum will fail and your application start also.
Maybe giving the reasons behind your choice would help to give you some light on helping you.
I have been given a java web application for which I have the source code to. The application queries an Oracle database to return data back to the user in web page. I need to update a value for the returned data in the database, without knowing the table or column names. Is there a general way to determine what query the application is submitting to return the data for a particular page so I can find the right tables and columns?
I am new to java and web development so not sure where to start looking.
Thanks!
Well, there's always the old fashioned way of finding out. You can find the source code for the specific page you're looking at and identify the query that's being executed to retrieve the data. I'm assuming that's not what you're looking for, though.
Some other options include using JDBC (Enabling and Using JDBC Logging) logging feature or JProfiler (the JDBC probe shows you all SQL statements in the events view). Once you find the SQL statement, you can use standard text search features within your IDE to locate the specific code and make alterations.
Hope that helps!
If you can run a controlled test (e.g., you are the only person on that web application), you could turn on SQL tracing on the DB connection and then run your transaction several times. To do this
look at all the connections from that application using v$session -- you can control this by tweaking your connection pool setting (e.g., set min and max connection to 1). Assuming this is your test environment.
turn on 10046 trace (see https://oracle-base.com/articles/misc/sql-trace-10046-trcsess-and-tkprof -- there are many other examples).
The 10046 trace will show you what the application is doing -- SQL by SQL. You can even set the level to 12 to get the bind variable values (assuming you are using prepared statements).
I use JDBC and created h2 database called usaDB from sql script. Then I filled all tables with jdbc.
The problem is that after I connect to usaDB at localhost:8082 I cannot see on the left tree
my tables. There is only INFORMATION_SCHEMA database and rootUser which I specified creating usaDB.
How to view the content of tables in my h2 database?
I tried query SELECT * FROM INFORMATION_SCHEMA.TABLES.
But it returned many table names except those I created. My snapshot:
I had the same issue and the answer seems to be really stupid: when you type your database name you shouldn't add ".h2.db" suffix, for example, if you have db file "D:\somebase.h2.db" your connection string should be like "jdbc:h2:file:/D:/somebase". In other way jdbc creates new empty database file named "somebase.h2.db.h2.db" and you see what you see: only system tables.
You can use the SHOW command:
Using this command, you can lists the schemas, tables, or the columns of a table. e.g.:
SHOW TABLES
This problem drove me around the twist and besides this page I read many (many!) others until I solved it.
My Use Case was to see how a SpringBatch project created in STS using :: Spring Boot :: (v1.3.1.RELEASE) was going to behave with the H2 database; to do the latter, I needed to be able to get the H2 console running as well to query the DB results of the batch run.
This is what I did and found out:
Created an Web project in STS using Spring Boot:
Added the following to the pom.xml of the latter:
Added a Spring configuration file as follows to the project:
This solves the Web project deficiencies in STS. If you run the project now, you can access the H2 console as follows: http://localhost:8080/console
Now create a SpringBatch project in STS as follows (the alternative method creates a different template missing most of the classes for persisting data. This method creates 2 projects: one Complete, and the other an initial. Use the Complete in the following.):
The SpringBatch project created with STS uses an in memory H2 database that it CLOSES once the application run ends; once you run it, you can see this in the logging output.
So what we need is to create a new DataSource that overrides the default that ships with the project (if you are interested, just have a look at the log messages and you will see that it uses a default datasource...this is created from:
o.s.j.d.e.EmbeddedDatabaseFactory with the following parameters:
Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa')
So, it starts an in memory, and then closes it. You have no chance of seeing the data with the H2 console; it has come and gone.
So, create a DataSource as follows:
You can of course use a properties file to map the parameters, and profiles for different DataSource instances...but I digress.
Now, make sure you set the bit that the red arrow in the picture is pointing to, to a location on your computer where a file can be persisted.
Running the SpringBatch (Complete project) you should now have a db file in that location after it runs (persisting Person data)
Run the Web project you configured previously in these steps, and you WILL :=) see your data, and all the Batch job and step run data (et voila!):
Painful but rewarding. Hope it helps you to really BOOTSTRAP :=)
I have met exactly this problem.
From what you describe, I suppose that you connect your jdbc with the "real" h2 server, but you are connecting on web application to database by the wrong mode (embedded-in-memory mode, aka h2mem). It means that h2 will create a new database in-memory, instead of using your true database stored elsewhere.
Please make sure that when you connect to this database, you use the mode Generic H2 (Server), NOTGeneric H2 (Embedded). You can refer to the picture below.
Version of jar file and installed h2 database should be same.
If in case you have created and populated H2 database table using maven dependency in spring boot, then please do change the JDBC URL as jdbc:h2:mem:testdb while connecting to H2 using web console.
It is an old question, but I came across the same problem. Eventually I found out that the default JDBC URL is pointing a test server rather than my application. After correcting it, I could access the right DB.
I tried with both Generic H2 (Embedded) and the Generic H2 (Server) options, both worked as long as the JDBC URL: is provided correctly.
In grails 4.0.1 the jdbc URL for development is jdbc:h2:mem:devDb. Check your application.yml file for the exact URL.
For the people who are using H2 in embedded(persistent mode) and want to "connect" to it from IntelliJ(other IDEs probably apply too).
Using for example jdbc url as follows: jdbc:h2:./database.h2
Note, that H2 does not allow implicit relative paths, and requires adding explicit ./
Relative paths are relative to current workdir
When you run your application, your workdir is most likely set to your project's root dir
On the other hand, IDE's workdir is most likely not your project's root
Hence, in IDE when "connecting" to your database you need to use absolute path like: jdbc:h2:/Users/me/projects/MyAwesomeProject/database.h2
For some reason IntelliJ by default also adds ;MV_STORE=false. It disables MVStore engine which in fact is currently used by default in H2.
So make sure that both your application and your IDE use the same store engine, as MVStore and PageStore have different file layouts.
Note that you cannot "connect" to your database if your application is using it because of locking. The other way around applies too.
In my case the issue was caused by the fact that I didn't set the h2 username, password in java. Unfortunatelly, Spring didn't display any errors to me, so it was not easy to figure out. Adding this lines to dataSource method helped me fix the issue:
dataSource.setUsername("sa");
dataSource.setPassword("");
Also, I should have specified the schema when creating tables in schema.sql
Selecting Generic H2 (Server) solved for me. We tempted to use default Generic H2 (Embedded) which is wrong.
Actually when running Selenium test case. I takes the live (Main Database) database which is configured in Glassfish. If we add records for testing purpose then it will replicate in the Main database. This is not good know. So is there any way to have separate DataBase for Selenium test case.
For Glassfish:
Define your JDBC Connection Pool resource to refer to different databases for your production server vs your development server.
If you're not running two different servers, then your first step is to fix that, and be running different servers. And different database servers. Never point your development machine/server at production data, or even the production database server.
If you are trying to do a unit test that should run on deployment, then you must create a second connection in your unit test program.
You might want to use an in memory database for this, maybe HSQL which comes bundled with the java sdk so you don't need to install any drivers and also you won't need to cleanup anything after the tests are run.
How you create the second connection depends on what you are using, hopefully you will have a central class or method to get the database connections, something like this:
Connection c = MyConnectionClass.getConnection();
so you will have it easy modifying the getConnection method so you can point out to the HSQL direct connection for your tests, with something like this:
public Connection getConnection(){
if(testing){
Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:mymemdb", "SA", "");
}else{
//get your connection from your pool or whatever you are doing right now
}
}
or also you can be more correct and create a mock for this class. But I'm not sure if selenium supports this out of he box.
And of course, you will need to create your database schema into the in memory database before beginning the tests. If you use hibernate or JPA for example then that should be simple (be sure that you add a second persistence unit and use that in this case), if not then you should have the scripts for your database and run them with JDBC as you would run them in any database.
Also if you don't want to run the scripts every time the tests are run use hsql but in file mode (change the jdbc:hsqldb:mem for jdbc:hsqldb:file it will use a file to store the database).
here's some info about the hsql database if you want to know more: link
Also if you dont like hsql you can try sqlite (only for file mode) which I think has more tools for accessing it
Is it possible to create an initial database changelog xml file from the existing state of the database?
I believe I've generated the schema using generateChangeLog, but it doesn't seem to return the stored procedures (or the data).
I'm using SQL Sever 2008
You can return the data using a diffTypes flag that includes "DATA". See http://www.liquibase.org/documentation/diff.html.
Liquibase cannot currently output stored procedures, however. For that you will need to use a different tool and include them in the generated changelog using the tag.
download liquibase.jar , database driver and save to one directory (Ex:/home/mySystem/liquibase), in the command line change the directory to (/home/mySystem/liquibase) and run the below mentioned command
java -jar liquibase.jar --driver=org.postgresql.Driver --classpath=postgresql-42.1.3.jar --changeLogFile=db.changelog.xml --url="jdbc:postgresql://localhost:5432/<databasename>" --username=<username> --password=<password> update
Reference link:
http://www.liquibase.org/documentation/generating_changelogs.html
I just yesterday discovered SQL Power Architect, which seems to be able to generate Liquibase configurations:
http://www.sqlpower.ca/page/architect
For more info on this combination see this blog post:
http://blog.mgm-tp.com/2010/11/data-modeling-part2/