I have an existing database (version x), and I can generate ChangeLog file by using below command
mvn liquibase:generateChangeLog -Dliquibase.outputChangeLogFile=d:\output.xml
After that, I try to remove one table in database directly, How can I user Liquibase to rollback my database to version x ?
Once you have started using Liquibase, you should avoid making changes directly to the database.
Let's simplify the scenario to make it easier to describe. Say at version x your database has a single table called TABLE1 and nothing else. You run the generateChangeLog command, and you get a changelog that has a single changeset that says "create table TABLE1". When Liquibase creates that changeset, it gives it an id. After creating the changelog, you will then want to record in that database that the database and changelog are 'in sync' by running the liquibase changelogSync command - this creates a second table named DATABASECHANGELOG and adds a row to that table with the id of the changeset and some other information.
If you then manually delete the table, Liquibase doesn't 'know' that you have done this, so you would need to also manually let liquibase know that you had done that delete. You would do that by removing the row from the databasechangelog table. You could then re-create the table and get back to version x by running the liquibase update command.
Related
I have a problem with generating migration script from existing migration files, via command line, either Script-Migration or dotnet ef migrations script.
The migration file contains the following:
migrationBuilder.DropIndex(
name: "IX_CAR_CAR_ID",
schema: "AUTO",
table: "CARS",
column: "CAR_ID");
The generated SQL script contains SQL that fails during database update.
Expected result:
SQL script should contain schema in the drop index command: DROP INDEX "AUTO"."IX_CAR_CAR_ID"
Actual result:
SQL script does not contain schema in the drop index command: DROP INDEX "IX_CAR_CAR_ID"
I have fixed that by manual modification of the migration file, so instead of migrationBuilder.DropIndex, I use
migrationBuilder.Sql("DROP INDEX \"AUTO\".\"IX_CAR_CAR_ID\"").
Well, that solves the problem for me, but does not remove the cause, I suppose.
I have tried the same with MsSQL server and the result is valid:
DROP INDEX [IX_CAR_CAR_ID] ON [AUTO].[CARS];
so, I assume it might be Oracle only related issue.
Using:
Microsoft.EntityFrameworkCore version 5.0.17
Oracle.EntityFrameworkCore version 5.21.61
My question: does anybony know whether this could be a bug in one of the Oracle or EntityFramework packages?
I'm using liquibase with oracle database, after executing update command for a specific changeSet, and the log for this changeSet is inserted at DATABASECHANGELOG table, however if I executed a rollbackCount command to rollback that changeSet, the inserted log is deleted and i can't find the history of the changes that were executed and rolledback again.
Liquibase's DATABASECHANGELOG table only records what's in the database. It's not an audit history tool.
For audit, you can look at using Liquibase Hub which records update and rollback operations so you'll have a record of when the operation was performed.
You can also run rollback-*-sql command prior to running an actual rollback. For example, rollback-count-sql or rollback-sql or rollback-to-date-sql. These commands will output rollback SQL to console but not execute rollback on the database. You'll need to follow up with the actual rollback operation.
Run
liquibase rollback-count-sql 10
Examine the generated SQL or log it to a file. If happy with generated SQL then run:
liquibase rollback-count 10
I am using liquibase 4.3.3 to insert data to H2 DB using yaml changeset. But, when I try to start the server I get table not found while inserting even though the table exists. But, if I use the generated insert statement and disable liquibase and use spring.sql.init.data-locations to specify the sql file having insert SQL statement, this works. Can you please help me out with this weird problem?
I have a jhipster project which i am deploying on prod using the command
java -jar project.jar
but during development I renamed some columns in some tables, when I am redeploying the code I am getting error of liquibase, I am told if I run the command below it should fix.
./mvnw liquibase:changelogsync
I do not have the code on prod but only jar file, please advise , what should I do to resolve it?
Sounds like you should spend a little time with the jHipster or Liquibase documentation to understand what it is doing. You didn't mention what the error was, but I am guessing it was probably something like "checksum for changeset with id xxxx changed from yyyy to zzzz." If you were able to run changelogsync in production, it would just mark all the changesets in your changelog as run by updating the checksum in the databasechangelog table on production, but your database tables will not have the correct columns.
Presumably you have run things in production and you have a table with some column - lets pretend it is named A for example. You say you renamed the column, lets pretend the new name is B. If you did that change by just changing the create table statement in the changelog, then if you run changelogsync in production what happens is that liquibase would think that the changeset to create the table and the column with name B has been run, but in fact it has not been run.
Instead, revert the changelog to what it was before, and rather than renaming the column by changing the changeset, create a new changeset that uses the liquibase renameColumn change type to rename the column.
I want to generate a SQL file via liquibase for my oracle database. Is there a possibility to ensure that liquibase generates a commit; after every changeset? I thought of manually write after every changeset a commit in <SQL> tags but this is actually not a good approach so is there any command for it? I am using liquibase 3.5.5. and generate the SQL file like this:
.\liquibase --url=offline:oracle?
--changeLogFile="C:\Users\Ferid\Documents\Box Sync\PRIVATE_Ferid\liquibase-3.5.5-bin\cl.xml"
--outputFile="C:\Users\Ferid\Documents\Box Sync\PRIVATE_Ferid\liquibase-3.5.5-bin\output.sql"
updatesql