Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute multiple inserts when using LIQUIBASE WITHOUT CHANGELOGS

Tags:

liquibase

As per this documentation

Liquibase can execute multiple sql files in a given path without the need of any changelogs. However when I created the file with below inserts

insert into address (id, line1, line2) values (1, '121 Main Ave', null);
insert into address (id, line1, line2) values (2, '662 Broadway', 'Suite 3317');
insert into address (id, line1, line2) values (3, '412 Riverview', null);

I get the following error

Invalid sql syntax

like image 642
Bibhu Biswal Avatar asked Nov 25 '15 04:11

Bibhu Biswal


People also ask

How does liquibase keep track of changes?

Liquibase tracks changes using its own tables in your schema to ensure consistency and to avoid corruption due to incorrectly altered changelogs. It records a hash of each changeset. While it's running updates, it puts a "lock" on your database so you can't accidentally run two changelogs concurrently.

How should stored procedures be managed liquibase?

Managing Stored Procedures: Try to maintain separate changelog for Stored Procedures and use runOnChange=”true”. This flag forces LiquiBase to check if the changeset was modified. If so, liquibase executes the change again. What do they mean by "maintain separate changelog for stored procedures"?

Does liquibase support DML?

What are the supported features of the Liquibase Cloud Spanner extension? The Cloud Spanner Liquibase extension allows you to use Liquibase to target Cloud Spanner databases. The extension supports most of the available features of both Liquibase and Cloud Spanner and supports most DML and DDL commands.

What is runOnChange liquibase?

The runOnChange changeset attribute runs the change the first time it is detected and each time the changeset is modified. Liquibase determines that a changeset has been modified by comparing the MD5 checksum for the changeset to the checksum stored in the DATABASECHANGELOG table.


1 Answers

Liquibase is not recognising your sql file . Add these 2 lines on top of you sql file :

--liquibase formatted sql
--changeset {authorName}:{id}

change authorName and id as per your wish . You can also do something like this in your changelog.xml file:

<changeSet author="authorName" id=”id”>
  <sqlFile path="insertcommands.sql"/>
</changeSet>

In this case you need not put on top of your insertcommands.sql file

--liquibase formatted sql
--changeset {authorName}:{id}

as you did earlier.

PS - Tested on liquibase-3.4 and mysql5.5

like image 68
Chandra kant Avatar answered Jun 11 '23 01:06

Chandra kant