Thunderforge
Thunderforge

Reputation: 20585

How can I rename a sequence with liquibase?

I have a sequence in my database, which I generated through Liquibase. During refactoring, we decided that we didn't like the name that we gave it, and we would like to rename it, preserving all data that currently exists for it.

It seems possible to alter a sequence, but I'm not seeing anything about how to rename the sequence. Is there a way to do it, or a reasonable workaround?

(If it matters, I'm using Oracle SQL)

Upvotes: 4

Views: 4308

Answers (2)

jFrenetic
jFrenetic

Reputation: 5552

Although not documented, this refactoring is supported by Liquibase. Not sure what version this change was implemented in, but the class supporting the feature was commited on 30 Jan 2014. What's interesting though, is that the original issue is still unresolved.

Anyway, the refactoring is supposed to be working only on Oracle and Postgres. I've tested it on Oracle with Liquibase 3.4.1:

databaseChangeLog:
  - changeSet:
      id: change_set_id
      author: me
      dbms: oracle
      changes:
        - renameSequence:
            oldSequenceName: old_name_seq
            newSequenceName: new_name_seq

The above refactoring is in YAML format, but you could easily guess its XML counterpart.

On Oracle, this generates the following statement:

RENAME old_name_seq TO new_name_seq;

2 other supported parameters are catalogName and schemaName.

Upvotes: 7

SteveDonie
SteveDonie

Reputation: 9016

There is not currently a built-in refactoring to rename a sequence. If your database engine supports it, you could execute whatever methods are supported using a <sql> or <sqlFile> change.

You said you were using Oracle SQL. The RENAME statement allows for renaming a sequence. So your Liquibase script would look like this:

<sql>RENAME old_sequence_name TO new_sequence_name</sql>

Upvotes: 6

Related Questions