Get local createTable's tableName attribute value

Hi,

Is there a way to retrieve the value of the attribute tableName on tag (or another attribute) without declaring a property or passing as parameter?
I want the value inside of the tag , like the local tag attributes. For example {local.tableName} or {local.createTable.tableName} where it returns the tableName, something like the example bellow:

<changeSet author="authorName" id="createTable.Table1">
	<createTable tableName="Table1">
		<column name="COLUMN1" type="TEXT" />
		<column name="COLUMN2" type="INT" defaultValueConstraintName="${local.tableName}" defaultValueNumeric="0" />
		<column name="COLUMN3" type="INT" defaultValueConstraintName="${local.createTable.tableName}" defaultValueNumeric="0" />
	</createTable>
</changeSet>

Thanks

Hi @LazyLeecher ,

Are you asking if there is another way to set {local.createTable.tableName} other than declaring a property in the changelog? If so, yes, you can. You can see all the ways you can set a property (including cli, and env variable are possible sources). Check out the docs.

Hi @LazyLeecher ,

Are you expecting the tablename itself as the output of the property substitution syntax you have used ${...} ?

Could you be more precise on what you are expecting as an output changeset?

Thanks!
Rakhi Agrawal

Hi @ronak ,

That’s exactly what I don’t want to do. I don’t want to declare it just use the current name set at the changeset tag attribute tableName.

Sorry for the delay, life.
Thanks

Hi @rakhi ,

That’s it, I don’t want to declare it just get the current value at the tag attribute tableName.

In my example when the liquibase compile run it should substitute the property “local.tableName” by “Table1” (just saw that my example is a bit confusing).

Again, the example below

<changeSet author="authorName" id="createTable.Table1">
	<createTable tableName="Table1">
		<column name="COLUMN1" type="TEXT" />
		<column name="COLUMN2" type="INT" defaultValueConstraintName="DF_${local.tableName}_${local.columnName}" defaultValueNumeric="0" />
		<column name="COLUMN3" type="INT" defaultValueConstraintName="DF_${local.tableName}_${local.columnName}" defaultValueNumeric="1" />
	</createTable>
</changeSet>

should create the falowing sql scripts:

CREATE TABLE Table1 (
	COLUMN1		TEXT,
	COLUMN2		INT CONSTRAINT DF_Table1_COLUMN2 DEFAULT 0,
	COLUMN3		INT CONSTRAINT DF_Table1_COLUMN3 DEFAULT 1
)

Sorry for the delay, life.
Thanks

Hi @LazyLeecher ,

I get your point now. But I don’t think we have any such functionality to get the values of local variables/properties and use it elsewhere. ( The idea seems cool though :slight_smile: )

However, don’t you think defining a property would also help you here? Just like below:

<property  name="table.name"  value="Table1"/>
<property  name="local.columnName2"  value="COLUMN2"/>
<property  name="local.columnName3"  value="COLUMN3"/>
<changeSet author="authorName" id="createTable.Table1">
	<createTable tableName="${table.name}">
		<column name="COLUMN1" type="TEXT" />
		<column name="COLUMN2" type="INT" defaultValueConstraintName="DF_${table.name}_${local.columnName2}" defaultValueNumeric="0" />
		<column name="COLUMN3" type="INT" defaultValueConstraintName="DF_${table.name}_${local.columnName3}" defaultValueNumeric="1" />
	</createTable>
</changeSet>

I know your requirement is different, but I think this way will also help you achive the goal! What do you think?

P.S : In Liquibase, we have the provision of using property substitution in multiple ways as mentioned by Ronak in his first comment.

Thanks!
Rakhi Agrawal