简单地说,是
如何使用longblob s.t将longblob从MySQL迁移到Postgres。如果列被注释为@Lob和@Basic(fetch= FetchType.LAZY),Hibernate会很高兴。
全文
因此,我正在(或至少尝试)将一个MySQL数据库迁移到postgres。我现在正试图正确地移动这张桌子:

我当前的pgloader脚本非常简单:
LOAD DATABASE
FROM mysql://foo:bar@localhost:3306/foobar
INTO postgresql://foo:bar@localhost:5432/foobar
CAST
type int to integer drop typemod,
type bigint with extra auto_increment to bigserial drop typemod,
type bigint to bigint drop typemod
ALTER TABLE NAMES MATCHING 'User' RENAME TO 'users'
ALTER TABLE NAMES MATCHING ~/./ SET SCHEMA 'public'
;这足以加载数据并使外键工作。
postgres表如下所示:

然而,File是一个java实体,其内容是带注释的@Lob。
@Entity
@Inheritance(strategy= InheritanceType.JOINED)
public class File extends BaseEntity {
@NotNull
private String name;
@Column
@Size(max = 4096)
private String description;
@NotNull
private String mimeType;
@Lob
@Basic(fetch= FetchType.LAZY)
private transient byte[] content;
...
}这就是为什么应用程序无法用错误连接到迁移的数据库的原因:
Schema-validation: wrong column type encountered in column [content] in table [File];
found [bytea (Types#BINARY)], but expecting [oid (Types#BLOB)]我怎样才能让这种迁移工作呢?
我确实试过
spring.jpa.properties.hibernate.jdbc.use_streams_for_binary=false正如proper hibernate annotation for byte[]中所建议的,但这并没有起到任何作用。
发布于 2020-08-11 14:35:30
嗯..。我想我可以像Migrate PostgreSQL text/bytea column to large object?建议的那样,在事实之后创建一个小块
这意味着迁移脚本将得到一个扩展:
LOAD DATABASE
FROM mysql://foo:bar@localhost:3306/foobar
INTO postgresql://foo:bar@localhost:5432/foobar
CAST
type int to integer drop typemod,
type bigint with extra auto_increment to bigserial drop typemod,
type bigint to bigint drop typemod
ALTER TABLE NAMES MATCHING 'User' RENAME TO 'users'
ALTER TABLE NAMES MATCHING ~/./ SET SCHEMA 'public'
AFTER LOAD DO
$$
ALTER TABLE file RENAME COLUMN content TO content_bytes;
$$,
$$
ALTER TABLE file ADD COLUMN content OID;
$$,
$$
UPDATE file SET
content = lo_from_bytea(0, content_bytes::bytea),
content_bytes = NULL
;
$$,
$$
ALTER TABLE file DROP COLUMN content_bytes
$$
;https://stackoverflow.com/questions/63359543
复制相似问题