pgloader-如何将longblob导入为oid?

简而言之

如何使用longblob s.t将pgloader从MySQL迁移到Postgres。如果列被注释为@Lob@Basic(fetch= FetchType.LAZY),Hibernate很高兴?

完整故事

因此,我正在将MySQL数据库迁移(或至少尝试)到postgres。我现在正尝试正确移动此表:

pgloader-如何将longblob导入为oid?

我当前的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表如下:

pgloader-如何将longblob导入为oid?

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[]中的建议,但这没有任何作用。

iCMS 回答:pgloader-如何将longblob导入为oid?

嗯……我想我可以根据Migrate PostgreSQL text/bytea column to large object?的建议在该事实之后创建blob。

意味着迁移脚本将获得扩展名:

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://www.f2er.com/1765685.html

大家都在问