I'll try to filter to have a one to one join in subclasses,
I set the filter condition in key column field, in a simple query it works, in more complicated it does not resolve alias.
is there a trick for setting the alias in the second column??
<join table="Aview" inverse="true">
**<key column="ID_A and ID_C=:MyFilter.IdCC" />**
<property name="IdBlabla" insert ="false" update ="false" column="ID_BlaBla"/>
<property name="Tipo" insert ="false" update ="false" />
<many-to-one name="CC" column="ID_C" cascade="none" insert ="false" update ="false"/>
</join>
Related
In liquibase, I created a table, one of column is like below
<column name="identifier" type=""varchar2(50)">
<constraint nullable="false"/>
</column>
This changeset is already executed
Now I need to set this column as
<constraint nullable="true"/>
I am using MySql
If you want to change a column to nullable='true' in Liquibase, you can use the modifyColumn tag.
<modifyColumn tableName="table_name">
<column name="identifier" type="varchar2(50)">
<constraint nullable="true"/>
</column>
</modifyColumn>
Note: in Mysql, the equivalent for varchar2 is varchar; So ur modifyColumn tag should look like this:
<modifyColumn tableName="table_name">
<column name="identifier" type="varchar(50)">
<constraint nullable="true"/>
</column>
</modifyColumn>
<modifyDataType
tableName="unspecified"
columnName="identifier"
newDataType="VARCHAR(50) NOT NULL"/>
I want to insert multiple rows to the xxx_table with liquibase.
<changeSet id="XXX" author="XXX">
<comment>Add default values to xxx_table table</comment>
<insert tableName="xxx_table">
<column name="group_id"
valueComputed="(SELECT group_id FROM subscriber)"/>
<column name="business_name"
valueComputed="(SELECT business_name FROM subscriber)"/>
<column name="created_stamp" valueComputed="CURRENT_TIMESTAMP"/>
<column name="last_updated_stamp" valueComputed="CURRENT_TIMESTAMP"/>
</insert>
<rollback/>
</changeSet>
Liquibase script fails because more than one row is returned from '(SELECT business name FROM subscriber)'. How can I insert multiple raw to a table?
I'm trying to use Liquibase for our project. We mainly use Oracle database and some other database less often. I'm trying to figureout how to specify column order in case of indexes. Below is a typical create index change set.
<createIndex indexName="PK_xxxxxxx" tableName="xxxxx" unique="true">
<column name="column_1"/>
<column name="column_2"/>
<column name="column_3"/>
</createIndex>
When it comes to performance and application scalablity, column order in index matters a lot. Can you please guide me if there is a way to specify same while creating index?
PS: As per column tag documentation, attributes afterColumn, position exists and they are applicable only for create table I assume. Here is what documentation says about it.
If used in an 'addColumn' command, this attribute allows you to control where in the table column order the new column goes. Only one of beforeColumn, afterColumn or position are allowed. Since 3.1
Liquibase will use the order of columns as listed in the createIndex tag - very much like the DBMS uses the order specified in the create index statement.
The following changeset:
<changeSet author="arthur" id="1">
<createTable tableName="foo">
<column name="col_1" type="integer"/>
<column name="col_2" type="integer"/>
<column name="col_3" type="integer"/>
</createTable>
<createIndex indexName="ix_one" tableName="foo">
<column name="col_1"/>
<column name="col_2"/>
<column name="col_3"/>
</createIndex>
<createIndex indexName="ix_two" tableName="foo">
<column name="col_3"/>
<column name="col_2"/>
<column name="col_1"/>
</createIndex>
<createIndex indexName="ix_three" tableName="foo">
<column name="col_2"/>
<column name="col_3"/>
<column name="col_1"/>
</createIndex>
</changeSet>
will produce the following statements (when e.g. run with updateSQL):
CREATE TABLE public.foo (col_1 INT, col_2 INT, col_3 INT);
CREATE INDEX ix_one ON public.foo(col_1, col_2, col_3);
CREATE INDEX ix_two ON public.foo(col_3, col_2, col_1);
CREATE INDEX ix_three ON public.foo(col_2, col_3, col_1);
I am not able to update the database table correctly using JdbcBatchItemWriter. Below is the code fragment. insert on an empty table is getting correct response but update is not happening on input table.
<bean id="odbWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource"></property>
<property name="sql">
<value>
<![CDATA[
update employeethree set salary = :salary, designation = :designation, promotioneligibility = :promotionEligibility
]]>
</value>
</property>
<property name="itemSqlParameterSourceProvider">
<bean
class="batchjobreaddb.CustomBeanPropertyItemSqlParameterSourceProvider" />
</property>
If i change the query inside CDATA to :
insert into employeetwo values(:empId, :empName, :dept , :salary, :designation, :experienceInMonths, :promotionEligibility)
then it's getting me the desired results. (EmployeeTwo has same structure but is empty.)
Please help. Thanks :)
Your UPDATE query has no WHERE clause. How are you to know which record to update?
For proper update behavior, you must specify a WHERE clause that properly identifies the record(s) you wish to modify with the UPDATE query.
This is obviously not necessary with an INSERT query, because you are creating a brand new record and not modifying an existing one.
Assuming from your example INSERT query that the employee id field is empid, try modifying your JdbcBatchItemWriter to set the sql value to:
<property name="sql">
<value>
<![CDATA[
UPDATE employeethree
SET salary = :salary,
designation = :designation,
promotioneligibility = :promotionEligibility
WHERE empid = :empId
]]>
</value>
</property>
I am using liquibase in my project.
I have tenant table with tenant_id as primary key. And the remaining tables have tenant_id as a column.
Now what will be the better way to handle master data with different tenants
Tables:
<createTable tableName="tenant">
<column name="tenant_id" autoIncrement="true" type="int">
<constraints primaryKey="true" nullable="false"
primaryKeyName="pk_tenant_id" />
</column>
<column name="name" type="varchar(100)"></column>
</createTable>
<createTable tableName="base_entity">
<column name="base_entity_id" autoIncrement="true" type="int">
<constraints primaryKey="true" nullable="false"
primaryKeyName="pk_base_entity_id" />
</column>
<column name="tenant_id" type="int">
<constraints nullable="false" />
</column>
</createTable>
-- Data: --
Currently I am handling data like this
<property name="#tenant_id_1"
value="(select tenant_id from tenant where name='test1') " dbms="mysql" />
<property name="#tenant_id_2"
value="(select tenant_id from tenant where name='test2') " dbms="mysql" />
<insert tableName="tenant">
<column name="name">test1</column>
</insert>
<insert tableName="tenant">
<column name="name">test2</column>
</insert>
<insert tableName="base_entity">
<column name="name">testBase_Entity</column>
<column name="tenant_id" valueComputed="${#tenant_id_1}" />
</insert>
<insert tableName="base_entity">
<column name="name">testBase_Entity</column>
<column name="tenant_id" valueComputed="${#tenant_id_2}" />
</insert>
But I have 'n' no of tenants, for every entry of tenant I've to insert the data.
Is there any option in liquibase do this in a better way ?
Thanks in advance.