how to read file in liquibase changeset sql script on spring boot application

128 views Asked by At

I am developing a spring boot application written in Kotlin. We create sql, migrate and populate some data using liquibase.

create script:

CREATE TABLE maps (
   id            BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
   camera_map    OID                                     NOT NULL
);

kotlin entity:

@Entity
@Table(
name = "maps", schema = "fleet",
)
class SavedMapEntity : BaseEntity() {

@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "camera_map", nullable = false)
var cameraMap: Blob? = null

}

changelog script:

<changeSet id="11-map-v_1.0.0_00006" author="fleet_management">
    <sqlFile path="liquibase/sql/script/v1/11-map/v_1.0.0_000006_insert_map.sql"
             splitStatements="false"/>
    <comment>
        Add default sim floor, department, and map
    </comment>
</changeSet>

I tried a few different SQL. give an example

v_1.0.0_000006_insert_map.sql:

DO
$$
DECLARE
    temp_camera_map    bytea;
    temp_camera_map_oid     oid;
BEGIN

    temp_camera_map := pg_read_binary_file('classpath:liquibase/camera_map')::bytea;

    temp_camera_map_oid :=
            lo_import('/tmp/temp_camera_map.bin');

    INSERT INTO maps (camera_map)
    VALUES (temp_image_oid);

END
$$;

but classpath:liquibase/map/camera_map cannot find this file.

Caused by: org.postgresql.util.PSQLException: ERROR: could not open file "classpath:liquibase/map/sim_occupancy_map" for reading: No such file or directory

but the file is under the resources/liquibase/map/ folder, how can I solve it?

And also project structure:

enter image description here

0

There are 0 answers