Play evolution not loading 1.sql - scala

I'm running Play with Slick integration, Evolutions and an H2 database. When starting Play in dev mode and visiting localhost:9000 (I am using https) I am told database "default" needs evolution. However the script I have in conf/evolutions/default/1.sql is not display below. Rather it only shows:
1# --- Rev:1,Ups - da39a3e
However my script reads:
# --- ! Ups
create table "USERS" ("ID" VARCHAR NOT NULL PRIMARY KEY, "ACTION" VARCHAR);
# --- ! Downs
drop table "USERS";
Naturally all transactions on this table fail. Am I missing a bit of configuration?

There must not be a space between the exclamation mark and the command:
# --- ! Ups
Wrong!
# --- !Ups
Right!

Related

DataJpaTest: Numeric scale default seems to be 0 with spring-boot-starter 2.7.1

I have a DataJpaTest with some schema.sql and data.sql for preparing the postgresql in-memory database. I've just upgraded spring-boot-starter-parent from 2.6.3 to 2.7.1, and now the test fails.
schema:
CREATE TABLE IF NOT EXISTS some_table(
id BIGSERIAL,
name TEXT,
problematic_number NUMERIC NOT NULL
);
data:
INSERT INTO some_table (name, problematic_number) VALUES ('something', 1.4321);
For some reason a test is failing now with:
org.opentest4j.AssertionFailedError:
Expected :1.4321
Actual :1
I also connected to the h2 database and I got really "1" in here instead of "1.4321". Before my spring upgrade, the test was fine.
Did the default scale for numeric maybe change? if I change my schema.sql to NUMERIC(10,4), the test succeeds.

Spring Boot 2 - H2 Database - #SpringBootTest - Failing on org.h2.jdbc.JdbcSQLException: Table already exists

Unable to test Spring Boot & H2 with a script for creation of table using schema.sql.
So, what’s happening is that I have the following properties set:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.initialization-mode=always
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:city;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
and, I expect the tables to be created using the schema.sql. The application works fine when I run gradle bootRun. However, when I run tests using gradle test, my tests for Repository passes, but the one for my Service fails stating that it’s trying to create the table when the table already exists:
Exception raised:
Caused by: org.h2.jdbc.JdbcSQLException: Table "CITY" already exists;
SQL statement:
CREATE TABLE city ( id BIGINT NOT NULL, country VARCHAR(255) NOT NULL, map VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, state VARCHAR(2555) NOT NULL, PRIMARY KEY (id) ) [42101-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:117)
at org.h2.command.CommandContainer.update(CommandContainer.java:101)
at org.h2.command.Command.executeUpdate(Command.java:260)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:192)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:164)
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:471)
... 105 more
The code is setup and ready to recreate the scenario. README has all the information ->
https://github.com/tekpartner/learn-spring-boot-data-jpa-h2
If the tests are run individually, they pass. I think the problem is due to schema.sql being executed twice against the same database. It fails the second time as the tables already exist.
As a workaround, you could set spring.datasource.continue-on-error=true in application.properties.
Another option is to add the #AutoConfigureTestDatabase annotation where appropriate so that a unique embedded database is used for each test.
There are 2 other possible solutions you could try:
Add a drop table if exists [tablename] in your schema.sql before you create the table.
Change the statement from CREATE TABLE to CREATE TABLE IF NOT EXISTS

play framewok postgresql : Database 'default' needs evolution

i deployed my very simple app in heroku by following tutorials
it works well in my localhost when i run it by sbt run
but it crashes on heroku!
here is my 1.sql:
# --- !Ups
create table contact (
id SERIAL UNIQUE,
name varchar(255),
email varchar(255),
phone varchar(255),
constraint pk_contact primary key (id)
);
create sequence contact_seq;
# --- !Downs
drop table if exists contact;
drop sequence if exists contact_seq;
heroku's log:
p.a.d.DefaultDBApi - Database [default] connected at jdbc:postgresql://...
!!! WARNING! This script contains DOWNS evolutions that are likely destructive
[warn] p.a.d.e.ApplicationEvolutions - Your production database [default] needs evolutions, including downs!
drop table if exists contact;
# --- Rev:1,Downs - a56ada6
name varchar(255),
drop sequence if exists contact_seq;
email varchar(255), phone varchar(255),
# --- Rev:1,Ups - 53110fe
create table contact (
);
id SERIAL UNIQUE,
constraint pk_contact primary key (id)
create sequence contact_seq;
[warn] p.a.d.e.ApplicationEvolutions - Run with -Dplay.evolutions.db.default.autoApply=true and -Dplay.evolutions.db.default.autoApplyDowns=true if you want to run them automatically, including downs (be careful, especially if your down evolutions drop existing data)
[info] application - ApplicationTimer demo: Starting application at 2017-04-28T08:59:05.048Z
Oops, cannot start the server.
#73o5pe90c: Database 'default' needs evolution!
and i also added
play.evolutions.db.default.autoApply=true
at end of my aplication.conf
Run with
-Dplay.evolutions.db.default.autoApply=true
and
-Dplay.evolutions.db.default.autoApplyDowns=true
If you want to run them automatically, including downs (be careful, especially if your down evolutions drop existing data).
You can set these by running:
heroku config:set JAVA_OPTS="-Dplay.evolutions.db.default.autoApply=true -Dplay.evolutions.db.default.autoApplyDowns=true"

Evolution not seen

I have began a Play Scala project and made it have a database by uncommenting in application.conf:
default.driver = org.h2.Driver
default.url = "jdbc:h2:mem:play"
Then, I created an evolution in conf/evolutions/default/1.sql:
CREATE SEQUENCE task_id_seq;
CREATE TABLE task (
id integer NOT NULL DEFAULT nextval('task_id_seq'),
label varchar(255)
);
# --- !Downs
DROP TABLE task;
DROP SEQUENCE task_id_seq;
So, when I am accessing localhost:9000 I am expecting to see the message:
Database default needs evolution!. However, this does not appear.
I am running in development mode and I don't have the code evolutionplugin=disabled anywhere in my project.
Why is the evolution not seen?
You need to add evolutions to the list of your library dependencies, as described in the docs https://www.playframework.com/documentation/2.4.0/Evolutions.

Is there any way to skip migrations which are failing?

I want to run migration on my server for ruby on rails project but I am getting this kind of error with postgres-
PGError: ERROR: relation "last_message_read" already exists
: CREATE TABLE "last_message_read" ("id" serial primary key, "message" character varying(255), "company_id" integer)
So, I want to continue with my migration but it is not happening - I want to ignore those migration which are failing and continue with the rest....
Something's wrong with your migrations. Just reset your db (rake db:reset).