Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

java - Flyway H2 Postgressql模式迁移不起作用(Flyway h2 postgressql mode migration not working)

I have to following migration working in postgres:

(我必须在postgres中进行以下迁移:)

ALTER TABLE task_def
  DROP COLUMN retry_count,
  DROP COLUMN timeout_seconds;

(and running in prod) but now i want to switch to h2 for my unit test but h2 doesnt seem to accept it My database config in spring boot:

((并在prod中运行),但是现在我想切换到h2进行单元测试,但是h2似乎不接受它。)

spring.datasource.url=jdbc:h2:./target/testdb;MODE=PostgreSQL
spring.datasource.username="sa"
spring.datasource.password=""
spring.jpa.hibernate.ddl-auto=none
spring.datasource.driver-class-name=org.postgresql.Driver

spring.flyway.url=jdbc:h2:./target/testdb;MODE=PostgreSQL
spring.flyway.user="sa"
spring.flyway.password=""
spring.flyway.schemas=

The error:

(错误:)

 Migration V3__.....sql failed
---------------------------------------
SQL State  : 42S22
Error Code : 42122
Message    : Column "DROP" not found; SQL statement:
ALTER TABLE task_def
  DROP COLUMN retry_count,
  DROP COLUMN timeout_seconds [42122-200]
Location   : db/migration/V3__.....sql
Line       : 1
Statement  : ALTER TABLE task_def
  DROP COLUMN retry_count,
  DROP COLUMN timeout_seconds
  ask by Robert Stevens translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no portable way to drop multiple columns at once, ALTER TABLE … DROP COLUMN is a standard command, but only for one column.

(没有一种可移植的方式一次删除多列, ALTER TABLE … DROP COLUMN是标准命令,但仅适用于一列。)

Some databases, however, including PostgreSQL and H2, support such non-standard feature, but their syntax is different.

(但是,某些数据库(包括PostgreSQL和H2)支持这种非标准功能,但是它们的语法不同。)

PostgreSQL expects

(PostgreSQL期望)

ALTER TABLE tableName DROP COLUMN columnName1, DROP COLUMN columnName2, …

https://www.postgresql.org/docs/12/sql-altertable.html

(https://www.postgresql.org/docs/12/sql-altertable.html)

H2 expects

(H2期望)

ALTER TABLE tableName DROP COLUMN columnName1, columnName2, …

https://h2database.com/html/commands.html#alter_table_drop_column

(https://h2database.com/html/commands.html#alter_table_drop_column)

If you use different databases, you should avoid non-portable commands when possible.

(如果使用其他数据库,则应尽可能避免使用非便携式命令。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...