Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is no longer possible to create calculated columns on mssql #2283

Closed
nickshoe opened this issue Dec 20, 2021 · 6 comments · Fixed by #2340
Closed

It is no longer possible to create calculated columns on mssql #2283

nickshoe opened this issue Dec 20, 2021 · 6 comments · Fixed by #2340

Comments

@nickshoe
Copy link

nickshoe commented Dec 20, 2021

Environment

Liquibase Version: 4.6.1

Liquibase Integration & Version: maven

Liquibase Extension(s) & Version:

  • liquibase-hibernate5: 4.6.1

Database Vendor & Version:

  • Microsoft SQL Server Developer (64-bit) 15.0.2080.9

Operating System Type & Version:

  • Windows 10 Pro (10.0)

Description

Liquibase 4.6.1 (and lower?) seems to require a value for the type property for the column specified in a addColumn change, this prevents the possibility to create a computed column on mssql as the generated SQL statement leads to a syntax error

Steps to reproduce

The following changeset worked with Liquibase 4.3.5:

<changeSet id="20200123095600-1" author="me" dbms="mssql">
    <addColumn tableName="event">
        <column name="payload_id AS JSON_VALUE(payload,'$.id')"
                       type=""
                       computed="true">
        </column>
    </addColumn>
    <createIndex tableName="event" indexName="idx_payload_id">
        <column name="payload_id"/>
    </createIndex>
</changeSet>

But, 4.6.1 gives me the following error:

liquibase.exception.ValidationFailedException: Validation Failed:
     1 changes have validation failures
          columnType is empty, config/liquibase/changelog/20200123110200_create_index_entity_Event.xml::20200123095600-1::me

It complains that the type attribute of the column specified in the addColumn change is empty.
If I specify the correct type as follows...

        <column name="payload_id AS JSON_VALUE(payload,'$.id')"
                       type="nvarchar(4000)"
                       computed="true">
        </column>

...Liquibase compiles it to the following SQL statement, which leads to a syntax error on mssql:

[Failed SQL: (102) ALTER TABLE event ADD payload_id AS JSON_VALUE(payload,'$.id') nvarchar(4000)]

Expected/Desired Behavior

I expect the pre-existing addColumn block for creating computed columns on mssql to be working even in 4.6.1, either without specifying the type property or by correctly specifying it and having the generated SQL statement to be correct.

@nickshoe
Copy link
Author

nickshoe commented Dec 21, 2021

Maybe, the correct way to add such a column is to use a sql block:

<changeSet id="20200123095600-1" author="me" dbms="mssql">
     <sql>
         ALTER TABLE event ADD payload_id AS JSON_VALUE(payload,'$.id')
    </sql>
    <createIndex tableName="event" indexName="idx_payload_id"
        <column name="payload_id"/>
    </createIndex>
</changeSet>

@nickshoe nickshoe changed the title Cannot longer create computed column mssql It is no longer possible to create calculated columns on mssql Dec 21, 2021
@kataggart
Copy link
Contributor

@nickshoe thanks for submitting this issue -- we are reviewing it and will definitely get back to you.

Also, if you haven't had a chance to check out https://forum.liquibase.org/ make sure to swing by -- it's becoming a pretty solid place for questions, community help, etc.

@nickshoe
Copy link
Author

nickshoe commented Dec 21, 2021

@kataggart thanks. Please, be aware that I've experienced this issue on Microsoft SQL Server (mssql).

@anjiB72
Copy link

anjiB72 commented Jan 7, 2022

Currently having the same issue as recently upgraded from 13.10.3 to 4.5.0. Unable to update the changelog as it is our initial log that has been released. The type was not specified (type=''") as it is a computed column but it is now failing validation upon updateSQL goal being run in maven.

@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Jan 21, 2022
@yodzhubeiskyi
Copy link
Contributor

This issue is fixed by #2340

Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Feb 14, 2022
@nickshoe
Copy link
Author

Thanks @yodzhubeiskyi, I'll try it out.

@nvoxland nvoxland added this to the v4.8.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants