> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/spring/spring-features/spring-persistence/liquibase/use-case.md).

# Use Case

## Scenario 1

We had around 10 Liquibase change log entries in the `databasechangelog` table. Unfortunately, the table was accidentally deleted, and now our Spring Boot service fails to start due to a Liquibase error.

When the `databasechangelog` table is deleted, Liquibase loses track of which changesets have already been applied. Without this history, Liquibase attempts to reapply all changesets, which can cause conflicts and prevent your Spring Boot application from starting.

Here's a step-by-step approach to resolve this issue:

#### 1. **Recreate the `databasechangelog` Table Manually**

* If we have access to the original `databasechangelog` structure, recreate the table. Here is a simplified SQL script to recreate the basic `databasechangelog` table (adjust column types as necessary for our database):

  ```sql
  CREATE TABLE databasechangelog (
      ID VARCHAR(255) NOT NULL,
      AUTHOR VARCHAR(255) NOT NULL,
      FILENAME VARCHAR(255) NOT NULL,
      DATEEXECUTED TIMESTAMP NOT NULL,
      ORDEREXECUTED INT NOT NULL,
      EXECTYPE VARCHAR(10) NOT NULL,
      MD5SUM VARCHAR(35) NULL,
      DESCRIPTION VARCHAR(255) NULL,
      COMMENTS VARCHAR(255) NULL,
      TAG VARCHAR(255) NULL,
      LIQUIBASE VARCHAR(20) NULL,
      CONTEXTS VARCHAR(255) NULL,
      LABELS VARCHAR(255) NULL,
      DEPLOYMENT_ID VARCHAR(10) NULL,
      PRIMARY KEY (ID, AUTHOR, FILENAME)
  );
  ```

#### 2. **Insert Entries for Already Applied Changesets**

* If we know which changesets had already been applied (for example, from previous logs or backups), insert entries into the recreated `databasechangelog` table for each of those changesets. Here’s an example SQL insert statement:

  ```sql
  INSERT INTO databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, EXECTYPE)
  VALUES ('1', 'your_author', 'db/changelog/db.changelog-master.xml', CURRENT_TIMESTAMP, 1, 'EXECUTED');
  ```

  * Adjust `ID`, `AUTHOR`, `FILENAME`, and `ORDEREXECUTED` values as per your changesets.

#### 3. **Re-run Liquibase to Verify State**

* After recreating the `databasechangelog` table and adding entries for applied changes, restart your Spring Boot application. Liquibase should recognize the changesets as "executed" and not attempt to reapply them.

#### 4. **Use `liquibase validate` (Optional)**

* To ensure the changelog integrity, you can run the `liquibase validate` command to check for any discrepancies in the changelog files.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/spring/spring-features/spring-persistence/liquibase/use-case.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
