如何在liquibase

时间:2016-08-26 18:48:15

标签: sql oracle liquibase

为了在liquibase中使用retry.attempts:

<sql>ALTER TABLE t set t.name = 'CI_CASE' where t.retry_attempts >= 1000</sql>

不确定如何将列添加到表CI_CASE

所以我尝试了一个更简单的陈述:

<sql>ALTER TABLE CI_CASE ADD COLUMN TNUM</sql>

但是我得到了例外:

liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE CI_CASE ADD COLUMN TNUM: ORA-00904: : invalid identifier

我试过追加“;”分号,并尝试:

<sql>ALTER TABLE t set t.name = 'CI_CASE' and t.column = 'TNUM' where t.retry_attempts >= 1000</sql>

这是我的最终目标,是使用retry.attempts for liquibase

所以错误是由语法引起的,并且传递了.sql文件中的以下SQL语句:

ALTER TABLE CI_CASE ADD TNUM varchar2(1) NOT NULL;

现在需要弄清楚如何使用:

将'max.retry.count'放入liquibase.property文件中。

例如parameter.max.retry.count = 30

也许作为一个论点,对于:

<sqlFile path="oracle/schemas/ci_case.sql"/>

我试过了:

ALTER TABLE CIS_CASE ADD TNUM varchar2(1)NOT NULL WHERE CIS_CASE.retry_attempts&gt; = $ {max.retry.count};

Liquibase update Failed: Migration failed for change set edata-changelog.xml::2016-08-25-cnwill::CW:
00:03:34.886      Reason: liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE CIS_CASE ADD TNUM varchar2(1) NOT NULL WHERE CIS_CASE.retry_attempts >=  $ax.retry.count}: ORA-01735: invalid ALTER TABLE option

注意错误日志中缺少的{和m,不知道为什么会这样?

我试过了:

for Database/oracle/schemas/eldata/eldata-changelog.xml

<changeSet id="2016-08-25-cna-01" author="Ch Wills">
                <comment>
                        Testing retry logic on liquibase
                </comment>
                <sqlFile path="oracle/schemas/eldata/2016-08/2016-08-25-cna-01/20160825_01_upd-data-elis2data-cis_case_kr.sql"/>
        </changeSet>

这样可行,但现在我们想要合并一个变量max.retry.count 所以我使用属性文件:

liquibase.property

使用:

parameter.max.retry.count=30

并在变更集中将其称为:

<changeSet id="2016-08-25-cna-01" author="Ch Wills">
                <comment>
                        Testing retry logic on liquibase
                </comment>
                <sqlFile path="oracle/schemas/eldata/2016-08/2016-08-25-cna-01/20160825_01_upd-data-eldata-cis_case_kr.sql”/>
                    <property name="max.retry.count" value="100" />
        </changeSet>

错误:

 [ERROR] [system.err] Liquibase update Failed: Error parsing line 10730 column 50 of /opt/jenkins/workspace/EL-FT-DBV-LIQUIBASE-RETRY/Apps/Database/oracle/schemas/eldata/eldata-changelog.xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of 
'{"http://www.liquibase.org/xml/ns/dbchangelog":comment, "http://www.liquibase.org/xml/ns/dbchangelog":createTable, "http://www.liquibase.org/xml/ns/dbchangelog":dropTable, "http://www.liquibase.org/xml/ns/dbchangelog":createView, "http://www.liquibase.org/xml/ns/dbchangelog":renameView, "http://www.liquibase.org/xml/ns/dbchangelog":dropView, "http://www.liquibase.org/xml/ns/dbchangelog":insert, "http://www.liquibase.org/xml/ns/dbchangelog":addColumn, "http://www.liquibase.org/xml/ns/dbchangelog":sql, "http://www.liquibase.org/xml/ns/dbchangelog":createProcedure, "http://www.liquibase.org/xml/ns/dbchangelog":sqlFile, "http://www.liquibase.org/xml/ns/dbchangelog":renameTable, "http://www.liquibase.org/xml/ns/dbchangelog":renameColumn, "http://www.liquibase.org/xml/ns/dbchangelog":dropColumn, "http://www.liquibase.org/xml/ns/dbchangelog":mergeColumns, "http://www.liquibase.org/xml/ns/dbchangelog":modifyDataType, "http://www.liquibase.org/xml/ns/dbchangelog":createSequence, "http://www.liquibase.org/xml/ns/dbchangelog":alterSequence, "http://www.liquibase.org/xml/ns/dbchangelog":dropSequence, "http://www.liquibase.org/xml/ns/dbchangelog":createIndex, "http://www.liquibase.org/xml/ns/dbchangelog":dropIndex, "http://www.liquibase.org/xml/ns/dbchangelog":addNotNullConstraint, "http://www.liquibase.org/xml/ns/dbchangelog":dropNotNullConstraint, "http://www.liquibase.org/xml/ns/dbchangelog":addForeignKeyConstraint, "http://www.liquibase.org/xml/ns/dbchangelog":dropForeignKeyConstraint, "http://www.liquibase.org/xml/ns/dbchangelog":dropAllForeignKeyConstraints, "http://www.liquibase.org/xml/ns/dbchangelog":addPrimaryKey, "http://www.liquibase.org/xml/ns/dbchangelog":dropPrimaryKey, "http://www.liquibase.org/xml/ns/dbchangelog":addLookupTable, "http://www.liquibase.org/xml/ns/dbchangelog":addAutoIncrement, "http://www.liquibase.org/xml/ns/dbchangelog":addDefaultValue, "http://www.liquibase.org/xml/ns/dbchangelog":dropDefaultValue, "http://www.liquibase.org/xml/ns/dbchangelog":addUniqueConstraint, "http://www.liquibase.org/xml/ns/dbchangelog":dropUniqueConstraint, "http://www.liquibase.org/xml/ns/dbchangelog":customChange, "http://www.liquibase.org/xml/ns/dbchangelog":update, "http://www.liquibase.org/xml/ns/dbchangelog":delete, "http://www.liquibase.org/xml/ns/dbchangelog":loadData, "http://www.liquibase.org/xml/ns/dbchangelog":loadUpdateData, "http://www.liquibase.org/xml/ns/dbchangelog":executeCommand, "http://www.liquibase.org/xml/ns/dbchangelog":stop, "http://www.liquibase.org/xml/ns/dbchangelog":rollback, WC[##other:"http://www.liquibase.org/xml/ns/dbchangelog"], "http://www.liquibase.org/xml/ns/dbchangelog":modifySql}' is expected.

所以这似乎是我可以使用的属性名称列表

因此,似乎liqubibase没有任何“RETRY”属性。

似乎SQL本身根据收到的错误代码提供循环:

BEGIN
  FOR i IN 1..5 LOOP  -- Try transaction at most 5 times.

    DBMS_OUTPUT.PUT('Try #' || i);

    BEGIN  -- sub-block begins

       SAVEPOINT start_transaction;

       -- transaction begins

       DELETE FROM results WHERE res_answer = 'NO';

       INSERT INTO results (res_name, res_answer) VALUES (name, answer);

       -- Nonunique name raises DUP_VAL_ON_INDEX.

       -- If transaction succeeded:

       COMMIT;
       DBMS_OUTPUT.PUT_LINE(' succeeded.');
       EXIT;

    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
        DBMS_OUTPUT.PUT_LINE(' failed; trying again.');
        ROLLBACK TO start_transaction;    -- Undo changes.
        suffix := suffix + 1;             -- Try to fix problem.
        name := name || TO_CHAR(suffix);
    END;  -- sub-block ends

  END LOOP;
END;

这是唯一的方法,我可以在liquibase中为SQL提供重试吗?如果是这样,那么,有没有办法在1..5循环中使用变量代替5?

0 个答案:

没有答案