与Postgres和H2兼容的Playframework Evolution文件 [英] Playframework evolutions files compatible with both postgres and h2

查看:97
本文介绍了与Postgres和H2兼容的Playframework Evolution文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用H2作为后端使用Play框架(scala)开发网站.测试已很好地集成在一起,尤其是能够针对内存中的H2数据库运行测试.

I've been developing a web site with the Play framework (scala) using H2 as a backend. Testing is nicely integrated, especially with the ability to run tests against an in-memory H2 db.

现在,出于各种便利原因,我想将数据存储区移至Postgres.这给我带来了一个问题:如何在每次测试运行时继续测试并保持新数据库的简单性?我在网上看到有人设法对抗postgres进行现场测试并针对H2进行了测试.但是,两者在SQL级别上并不完全兼容(即使与Postgres兼容模式下的H2兼容).例如,H2不支持SERIAL,BIGSERIAL和BYTEA.

Now I'd like to move my datastore over to Postgres for various convenience reasons. This leaves me with a problem: How to continue to test and retain the simplicity of a fresh db for each test run? I see on the net that some people manage to run live against postgres and test against H2. However the two are not entirely compatible at the SQL level (even with H2 in Postgres compatibility mode). For instance SERIAL, BIGSERIAL and BYTEA are not supported on H2.

我可以通过使用两种方言的受限兼容交集来做到这一点吗,或者我还缺少另一种技术?

Can I do this by using a constrained compatible intersection of both dialects, or is there another technique I'm missing?

感谢您的帮助.

亚历克斯

推荐答案

由于演化文件直接使用SQL,除非您将自己限制为SQL的跨数据库兼容的通用子集,否则可能会遇到问题.

As evolution files use SQL directly, unless you limited yourself to a common cross-db-compatible subset of SQL you may have issues.

对此没有真正的解决方案,但是您仍然可以使用新的数据库进行测试.只需设置以下内容:

There is no real solution on that, but you can still use a fresh db for testing. Just set the following:

%test.jpa.ddl=create-drop
%test.db.driver=org.postgresql.Driver
%test.db=<jdbc url>
//etc

这应该创建一个新的postgres连接进行测试,从头开始创建数据库,运行演化,进行测试,并在完成后删除所有数据.

This should create a new postgres connection for test, create the db from scratch, run the evolutions, do the tests and remove all data once done.

这篇关于与Postgres和H2兼容的Playframework Evolution文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆