View definition on CloudSQL becoming invalid if the data type of a column chnages

my database is in Google CloudSQL. and below is my liquibase script that

  1. creates a simple table
  2. creates first view based on that table definition
  3. creates second view based on the first view definition
  4. and then change the data type of a column in the table
<?xml version="1.0" encoding="UTF-8"?>
	<changeSet author="satkon" id="createTable">

		<createTable tableName="MYTABLE">
			<column name="UUID" type="java.sql.Types.VARCHAR(36)">
				<constraints nullable="false" />
			<column name="NAME" type="java.sql.Types.VARCHAR(255)">
				<constraints nullable="false" />
			<column name="DESCRIPTION" type="TEXT" />

			<column name="SPEC_CONTENT" type="TEXT" />


	<changeSet author="satkon" id="createFirstView">
		<createView replaceIfExists="true" viewName="MYVIEW1">
            FROM MYTABLE
	<changeSet author="satkon" id="createSecondView">
		<createView replaceIfExists="true" viewName="MYVIEW2">
            FROM MYVIEW1
	<changeSet author="satkon" id="updateDataType">
		<modifyDataType tableName="MYTABLE"
			columnName="SPEC_CONTENT" newDataType="MEDIUMTEXT" />


by the end of this script execution, the definition of MYVIEW2 is becoming invalid and throws “eferences invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them” error. This is happening only on CloudSQL database. If I generate the SQL statements from liquibase using “updateSQL” option and execute those SQLs manually, then issue does not occur.

If liquibase is not involved there does not seem to be any issue. Can someone please help on this issue?

Welcome, @satkon !

Can you share the exact error text you’re getting? I’m not familiar with CloudSQL, and will need to ask the team next week who can help with this, and having the exact error may help.

thank you for the reply @tabbyfoo

It is pretty easy to reproduce this error on CloudSQL

once the liquibase script that I shared in the earlier post gets executed, if you run the query “desc MYVIEW2”, you will receive an error “Error Code: 1356. View ‘MYVIEW2’ references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them”

I’m not at all familiar with CloudSQL, but this is common object validation behavior in DBMS platforms when it comes to object dependencies and structure changes.

Same thing happens in Oracle. Now the way things are revalidated may differ between DBMS platforms. In oracle, I would add changesets after the table modification to compile each of the views:

alter view myview1 compile;
alter view myview2 compile;

Some changes may actually break the view to the point it needs to be recreated, so your mileage may vary.

Oracle will also automatically revalidate on first usage of the views, but proactively compiling them will make it so they never look invalid.

Maybe some of what I supplied will help you.

thanks @daryldoak … but for CloudSQL (or mysql) there doesn’t seem to be an equivalent of ‘alter view compile’ but looks like recreating the views when the table structure changes is a good practice to follow anyway…