I’m trying to add some computed columns to a table I have in MariaDB. I’m using the following definitions:
- addColumn:
columns:
- column:
name: type AS (SUBSTRING_INDEX(permission_id, ':', 1))
computed: true
- column:
name: scope AS (SUBSTRING_INDEX(SUBSTRING_INDEX(permission_id, ':', -2), ':', 1))
computed: true
- column:
name: access AS (SUBSTRING_INDEX(permission_id, ':', -1))
computed: true
tableName: Permission
This generates the following completely incorrect add:
ALTER TABLE main.Permission
ADD `type AS (SUBSTRING_INDEX(permission_id, ':', 1))` NULL,
ADD `scope AS (SUBSTRING_INDEX(SUBSTRING_INDEX(permission_id, ':', -2), ':', 1))` NULL,
ADD `access AS (SUBSTRING_INDEX(permission_id, ':', -1))` NULL
It looks as though it’s completely ignoring the “computed” property for this database type. Is there another way to specify this or does liquibase simply not support adding virtual columns for MariaDB?
For reference the correct sql looks something like this:
ALTER TABLE main.Permission
ADD type VARCHAR(50) AS (SUBSTRING_INDEX(permission_id, ':', 1)),
ADD scope VARCHAR(50) AS (SUBSTRING_INDEX(SUBSTRING_INDEX(permission_id, ':', -2), ':', 1)),
ADD access VARCHAR(50) AS (SUBSTRING_INDEX(permission_id, ':', -1))
I had to add the VARCHAR(50) myself. Initially I had that in my definitions above, but this caused a NullPointerException in Liquibase