I have this portion of XML Liquibase script, to creates some columns in a table:
<column name="send_time" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="delivery_time" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="read_time" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="payload" type="json">
<constraints nullable="true"/>
</column>
<column name="created_date" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="created_by" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="last_modified_date" type="timestamp"/>
<column name="last_modified_by" type="varchar(50)"/>
<column name="deleted_date" type="timestamp"/>
<column name="deleted_by" type="varchar(50)"/>
Could anyone explain why the result is like in the attached image?
In other words, this set to field 'send_time', the Default/Expression.
Why this?
I am using Jhipster and developing SpringBoot and AngularJS. Jhipster is using liquibase for creating the table, loading data, update e.t.c
I am using Mysql Database.
creating table Studio
<changeSet id="00000000000002" author="Mehbub"> <createTable tableName="studioname">
<column name="studioname_id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="studioname_name" type="varchar(50)">
<constraints unique="true" nullable="false" />
</column> </createTable>
</changeSet>
creating CategoryStudio table
<changeSet id="00000000000002" author="admin">
<createTable tableName="categorystudio">
<column name="categorystudio_id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="categorystudio_title" type="varchar(50)">
<constraints unique="true" nullable="false" />
</column>
<column name="studio_id" type="bigint">
<constraints nullable="false" />
</column>
</createTable> </<changeSet>
Constraints:
<changeSet id="00000000000002-1" author="Mehbub">
<addForeignKeyConstraint baseColumnNames="studio_id"
baseTableName="categorystudio"
constraintName="fk_studioname_id"
referencedColumnNames="studioname_id"
referencedTableName="studioname"
deleteCascade="true"
onDelete="CASCADE"/>
</changeSet>
Creating another table "tvshow"
<changeSet id="00" author="Mehbub">
<createTable tableName="tvshow">
<column name="tvshow_id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="tvshow_name" type="varchar(50)">
<constraints unique="true" nullable="false" />
</column>
<column name="movieCategory_id" type="bigint">
<constraints nullable="false" />
</column>
<column name="genreCategory_id" type="bigint">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
Contsraints:
<addForeignKeyConstraint baseColumnNames="movieCategory_id"
baseTableName="tvshow"
constraintName="fk_tvshow_movieCategory_id"
referencedColumnNames="categorystudio_id"
referencedTableName="categorystudio"
deleteCascade="true"
onDelete="CASCADE"/>
<addForeignKeyConstraint baseColumnNames="genreCategory_id"
baseTableName="tvshow"
constraintName="fk_tvshow_genreCategory_id"
referencedColumnNames="genresCategory_id"
referencedTableName="genresCategory"
deleteCascade="true"
onDelete="CASCADE"/>
</changeSet>
another table: genresCategory
<changeSet id="00" author="admin">
<createTable tableName="genresCategory">
<column name="genresCategory_id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="genresCategory_name" type="varchar(50)">
<constraints unique="true" nullable="false" />
</column>
</createTable>
</changeSet>
If i am adding only one foriegn key then it's working fine.But, when i added second foriegn key, it's throing the below error.
my equation is , each category have many tv shows and each tvshows have many Genres
i am getting the error as:
liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/00_constraints_tvShow.xml::00::Mehbub:
Reason: liquibase.exception.DatabaseException: Can't create table `allcomiclibrary`.`#sql-2ad_3ac` (errno: 150 "Foreign key constraint is incorrectly formed") [Failed SQL: ALTER TABLE allComicLibrary.tvshow ADD CONSTRAINT fk_tvshow_genreCategory_id FOREIGN KEY (genreCategory_id) REFERENCES allComicLibrary.genresCategory (genresCategory_id) ON DELETE CASCADE] at liquibase.changelog.ChangeSet.execute(ChangeSet.java:619) at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51) at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:79) at liquibase.Liquibase.update(Liquibase.java:214) at liquibase.Liquibase.update(Liquibase.java:192) at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:431) at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:388) at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:103) at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:83) at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:68) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
Can you please help me out what i am doing wrong here.
I was creating db tvshow first and then genres .. so it was hitting error .. changed the change log sequence and worked fine
I need to insert 200k records into MySQL database, using liferay service builder.
Currently it is taking 20+ minutes to process.
Is there a way to optimize this? I want to reduce processing time by 40-50%
Bulk processing and multiple values insertion is not feasible as it will require changes in configuration.
Below is the service.xml file
<entity name="table1"
table="iguv_table1" data-source="defaultdbDataSource"
local-service="true" remote-service="false" session-factory="defaultdbSessionFactory"
tx-manager="defaultdbTransactionManager">
<!-- PK Fields -->
<column name="orderNo" type="String" primary="true" />
<!-- Group instance -->
<column name="groupId" type="long" />
<!-- Audit Fields -->
<column name="companyId" type="long" />
<column name="createrUserId" type="long" />
<column name="createDate" type="Date" />
<column name="lastUpdaterUserId" type="long" />
<column name="modifiedDate" type="Date" />
<column name="approverUserId" type="long" />
<!-- Other Fields -->
<column name="rmsOrderNo" type="String" />
<column name="supplier" type="String" />
<column name="currencyCode" type="String" />
<column name="terms" type="String" />
<column name="notBeforeDate" type="Date" />
<column name="notAfterDate" type="Date" />
<column name="otbEowDate" type="Date" />
<column name="dept" type="int" />
<column name="status" type="String" />
<column name="exchangeRate" type="double" />
<column name="includeOnOrdInd" type="String" />
<column name="orderDetailsId" type="String" />
<column name="origInd" type="String" />
<column name="ediPoInd" type="String" />
<column name="preMarkInd" type="String" />
<column name="supplierName" type="String" />
<column name="hasNewItems" type="boolean" />
<column name="retryCount" type="int"></column>
<column name="successfullyPostedToRMS" type="boolean" convert-null="false"></column>
<finder name="rmsOrderNo" return-type="PurchaseOrder">
<finder-column name="rmsOrderNo" />
</finder>
<finder name="notSyncedPurchaseOrders" return-type="Collection">
<finder-column name="successfullyPostedToRMS"></finder-column>
<finder-column name="status"></finder-column>
</finder>
</entity>
I try to create a new table via a liquibase changeset that looks like:
<createTable tableName="mytable">
<column name="id" type="number" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="description" type="varchar(255)"/>
<column name="image_path" type="varchar(255)"/>
</createTable>
this fails with following error:
liquibase.exception.DatabaseException:
Error executing SQL CREATE TABLE
kkm.mytable (id numeric AUTO_INCREMENT NOT NULL, name VARCHAR(50) NULL, description
VARCHAR(255) NULL, image_path VARCHAR(255) NULL,
CONSTRAINT PK_BOUFFE PRIMARY KEY (id)):
Incorrect column specifier for column 'id'
if I set autoIncrement="false", this works perfectly.
Is this a known issue ?
EDIT:
this is working:
<createTable tableName="mytable">
<column name="id" type="number" autoIncrement="false">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="description" type="varchar(255)"/>
<column name="image_path" type="varchar(255)"/>
</createTable>
<addAutoIncrement
columnDataType="int"
columnName="id"
incrementBy="1"
startWith="1"
tableName="mytable"/>
Change type="number" to type="BIGINT".
i,e
<createTable tableName="mytable">
<column name="id" type="BIGINT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="description" type="varchar(255)"/>
<column name="image_path" type="varchar(255)"/>
</createTable>
Hope it works..!!!!
I am not a sql expert.
I want to implement a query equivalent to this condition
If ( (first-access-of-error1 = first-access-of-error2 and
second-access-of-error1 = second-access-of-error2) OR
(first-access-of-error1 = second-access-of-error2 and
second-accessr-of-error1 = first-access-of-error2) )
I attempted it with something like:
select d.id,
concat(a.variable_name,"|",a.file_url,"|",a.line_number,"|",a.stacktrace)
as FirstAccess_Params,
concat(b.variable_name,"|",b.file_url,"|",b.line_number,"|",b.stacktrace)
as SecondA_Params
from defect d
right join (accessor a, accessor b)
on (d.id=a.defect_id and d.id=b.defect_id and a.id<b.id)
where d.category_id=0 and d.relationship_id!=-1
group by FirstAccess_Params,SecondA_Params
With above query I am able to work this condition out:
(first-access-of-error1 = first-access-of-error2 and
second-access-of-error1 = second-access-of-error2)
But I am having trouble like how to accomplish this condition:
(first-access-of-error1 = second-access-of-error2 and
second-accessr-of-error1 = first-access-of-error2)
Any help is appreciated? Any ideas are welcome..
This is schema for Accessor table
<createTable tableName="accessor">
<column autoIncrement="true" name="id" type="BIGINT UNSIGNED">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="defect_id" type="BIGINT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="operation" type="TINYINT UNSIGNED"/>
<column name="variable_name" type="VARCHAR(128)"/>
<column name="object_address" type="VARCHAR(64)"/>
<column name="type" type="TINYINT UNSIGNED"/>
<column name="module_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="file_url" type="VARCHAR(256)"/>
<column name="function_name" type="VARCHAR(64)"/>
<column name="line_number" type="SMALLINT UNSIGNED"/>
<column name="accessing_order" type="TINYINT UNSIGNED"/>
<column name="stacktrace_type" type="TINYINT UNSIGNED"/>
<column name="stacktrace" type="VARCHAR(2048)"/>
<column name="parameter" type="VARCHAR(5120)"/>
</createTable>
And this is schema for defect Table
<createTable tableName="defect">
<column autoIncrement="true" name="id" type="BIGINT UNSIGNED">
<constraints nullable="false" primaryKey="true"/>
</column>
<column defaultValueNumeric="0" name="rule_id" type="SMALLINT UNSIGNED">
<constraints nullable="false"/>
</column>
<column defaultValueBoolean="false" name="hide" type="BIT">
<constraints nullable="false"/>
</column>
<column defaultValueNumeric="0" name="relationship_id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="category_id" type="SMALLINT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="sub_category_id" type="SMALLINT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="module1_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="module2_id" type="INT UNSIGNED"/>
<column name="execution_instance_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="application_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="project_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="target_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="testsuite_id" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="timestamp" type="INT UNSIGNED">
<constraints nullable="false"/>
</column>
<column name="priority" type="BIT"/>
<column name="status" type="BIT"/>
<column name="assignee" type="VARCHAR(64)"/>
<column name="label_ids" type="VARCHAR(1024)"/>
<column name="remark" type="VARCHAR(512)"/>
<column name="accessor_ids" type="VARCHAR(1024)"/>
<column name="parameter" type="VARCHAR(2048)"/>
<column defaultValueNumeric="0" name="parent_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
Consider this jsFiddle: http://sqlfiddle.com/#!2/c25e1/1 . It doesn't show duplicates. Also think about using DISTINCT sql command.
For the completeness of answer:
To accomplish first condition:
(first-access-of-error1 = first-access-of-error2 and
second-access-of-error1 = second-access-of-error2)
My code was sort of correct. Look at similar thing here https://stackoverflow.com/a/347300/1229355
The challenging part was to accomplish second condition:
(first-access-of-error1 = second-access-of-error2 and
second-accessr-of-error1 = first-access-of-error2)
For This: I created a new table. Though I started with the view, then moved to temporary table and then final to table. With view, I was having trouble in performance. As query was spending a lot of time in copying tmp table. With temporary table, I cannot use it in one query more then once, so it was not an option for me. So I had to stick with the table only.
Created table like this:
create table myDraceView (index(id)) as select d.id,concat_ws('|',a.variable_name,a.file_url,a.line_number,a.stacktrace) as FirstAccess_Params,"
+ "concat_ws('|',b.variable_name,b.file_url,b.line_number,b.stacktrace) as SecondA_Params from defect d right join (accessor a, accessor b) on (d.id=a.defect_id and d.id=b.defect_id and a.id<b.id) where d.category_id=0 and d.relationship_id!=-1 and d.defect_level='"
+ type
+ "' and "
+ mdaCondition;
(Sorry rushing.. have no time to write the query formally... shall do it later)
Then I did:
"select ids from (select concat( if( e1.id <= e2.id, e1.id, e2.id ),"
+ CONCAT_SEP
+ ",if( e1.id > e2.id, e1.id, e2.id ) ) as ids,e1.FirstAccess_Params as e1_FA,e1.SecondA_Params as e1_SA from myDraceView e1 join myDraceView e2 where e1.FirstAccess_Params=e2.SecondA_Params and e1.SecondA_Params=e2.FirstAccess_Params and e1.id!=e2.id group by e1.FirstAccess_Params,e1.SecondA_Params ) as l group by ids";
Any suggestions are welcome if anybody see any possible improvements that i can make.