Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@

<createTable tableName="${table_prefix}LOCKS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="LOCK_NAME" type="VARCHAR(40)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, LOCK_NAME" tableName="${table_prefix}LOCKS"/>

<createTable tableName="${table_prefix}FIRED_TRIGGERS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="ENTRY_ID" type="VARCHAR(95)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
Expand Down Expand Up @@ -55,7 +54,6 @@
<column name="IS_NONCONCURRENT" type="BOOLEAN"/>
<column name="REQUESTS_RECOVERY" type="BOOLEAN"/>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, ENTRY_ID" tableName="${table_prefix}FIRED_TRIGGERS"/>

<createIndex tableName="${table_prefix}FIRED_TRIGGERS" indexName="IDX_${table_prefix}FT_INST_JOB_REQ_RCVRY">
<column name="SCHED_NAME"/>
Expand Down Expand Up @@ -92,33 +90,31 @@

<createTable tableName="${table_prefix}CALENDARS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="CALENDAR_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="CALENDAR" type="${blob_type}">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, CALENDAR_NAME" tableName="${table_prefix}CALENDARS"/>

<createTable tableName="${table_prefix}PAUSED_TRIGGER_GRPS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, TRIGGER_GROUP" tableName="${table_prefix}PAUSED_TRIGGER_GRPS"/>

<createTable tableName="${table_prefix}SCHEDULER_STATE">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="INSTANCE_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="LAST_CHECKIN_TIME" type="BIGINT">
<constraints nullable="false"/>
Expand All @@ -127,17 +123,16 @@
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, INSTANCE_NAME" tableName="${table_prefix}SCHEDULER_STATE"/>

<createTable tableName="${table_prefix}JOB_DETAILS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="JOB_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="JOB_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="DESCRIPTION" type="VARCHAR(250)"/>
<column name="JOB_CLASS_NAME" type="VARCHAR(250)">
Expand All @@ -157,7 +152,6 @@
</column>
<column name="JOB_DATA" type="${blob_type}"/>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, JOB_NAME, JOB_GROUP" tableName="${table_prefix}JOB_DETAILS"/>

<createIndex tableName="${table_prefix}JOB_DETAILS" indexName="IDX_${table_prefix}J_GRP">
<column name="SCHED_NAME"/>
Expand All @@ -171,13 +165,13 @@

<createTable tableName="${table_prefix}TRIGGERS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="JOB_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
Expand All @@ -203,7 +197,6 @@
<column name="MISFIRE_INSTR" type="smallint"/>
<column name="JOB_DATA" type="${blob_type}"/>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP" tableName="${table_prefix}TRIGGERS"/>

<createIndex tableName="${table_prefix}TRIGGERS" indexName="IDX_${table_prefix}T_C">
<column name="SCHED_NAME"/>
Expand Down Expand Up @@ -272,27 +265,26 @@

<createTable tableName="${table_prefix}BLOB_TRIGGERS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="BLOB_DATA" type="${blob_type}"/>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP" tableName="${table_prefix}BLOB_TRIGGERS"/>

<createTable tableName="${table_prefix}SIMPROP_TRIGGERS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="STR_PROP_1" type="VARCHAR(512)"/>
<column name="STR_PROP_2" type="VARCHAR(512)"/>
Expand All @@ -306,34 +298,32 @@
<column name="BOOL_PROP_1" type="BOOLEAN"/>
<column name="BOOL_PROP_2" type="BOOLEAN"/>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP" tableName="${table_prefix}SIMPROP_TRIGGERS"/>

<createTable tableName="${table_prefix}CRON_TRIGGERS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="CRON_EXPRESSION" type="VARCHAR(120)">
<constraints nullable="false"/>
</column>
<column name="TIME_ZONE_ID" type="VARCHAR(80)"/>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP" tableName="${table_prefix}CRON_TRIGGERS"/>

<createTable tableName="${table_prefix}SIMPLE_TRIGGERS">
<column name="SCHED_NAME" type="VARCHAR(120)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_NAME" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="TRIGGER_GROUP" type="VARCHAR(200)">
<constraints nullable="false"/>
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="REPEAT_COUNT" type="BIGINT">
<constraints nullable="false"/>
Expand All @@ -345,7 +335,6 @@
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey columnNames="SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP" tableName="${table_prefix}SIMPLE_TRIGGERS"/>

<addForeignKeyConstraint baseTableName="${table_prefix}TRIGGERS" constraintName="${table_prefix}TRIGGERS_SCHED_NAME_FKEY" baseColumnNames="SCHED_NAME, JOB_NAME, JOB_GROUP" referencedTableName="${table_prefix}JOB_DETAILS" referencedColumnNames="SCHED_NAME, JOB_NAME, JOB_GROUP"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
* Copyright IBM Corp. 2024, 2025
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.quartz.impl.jdbcjobstore;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
* Guards the structure of {@code liquibase.quartz.init.xml} against the
* {@code sql_generate_invisible_primary_key} regression (issue #1489).
*
* <p>When MySQL 8.0.30+ runs with GIPK enabled (the default on Azure MySQL
* Flexible Server and not disableable via SQL), it auto-creates an invisible
* primary key on any table created without an explicit primary key. Declaring
* the composite primary keys inline in {@code <createTable>} makes MySQL see
* the explicit key at creation time, so no generated key collides with a later
* {@code <addPrimaryKey>} (error 1068 "Multiple primary key defined").
*/
class LiquibaseQuartzInitXmlTest {

private static final String CHANGELOG =
"/org/quartz/impl/jdbcjobstore/liquibase.quartz.init.xml";

private static final String ANY_NS = "*";

@Test
void testPrimaryKeysAreInlinedInCreateTable() throws Exception {
Document changeLog = loadChangeLog();

// No standalone <addPrimaryKey>: it would collide with a GIPK-generated
// invisible key on a table created without an inline primary key.
assertEquals(
0,
changeLog.getElementsByTagNameNS(ANY_NS, "addPrimaryKey").getLength(),
"primary keys must be declared inline in createTable, not via addPrimaryKey");

// Every created table must carry an inline primary key so MySQL never
// auto-generates one under sql_generate_invisible_primary_key=ON.
NodeList tables = changeLog.getElementsByTagNameNS(ANY_NS, "createTable");
assertFalse(tables.getLength() == 0, "expected at least one createTable change");
for (int i = 0; i < tables.getLength(); i++) {
Element table = (Element) tables.item(i);
assertTrue(
hasInlinePrimaryKey(table),
"createTable " + table.getAttribute("tableName")
+ " has no inline primary key column");
}
}

private static Document loadChangeLog() throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
try (InputStream in = LiquibaseQuartzInitXmlTest.class.getResourceAsStream(CHANGELOG)) {
assertNotNull(in, "changelog resource not found on classpath: " + CHANGELOG);
return builder.parse(in);
}
}

private static boolean hasInlinePrimaryKey(Element createTable) {
NodeList columns = createTable.getElementsByTagNameNS(ANY_NS, "column");
for (int i = 0; i < columns.getLength(); i++) {
Element column = (Element) columns.item(i);
NodeList constraints = column.getElementsByTagNameNS(ANY_NS, "constraints");
for (int j = 0; j < constraints.getLength(); j++) {
if ("true".equalsIgnoreCase(((Element) constraints.item(j)).getAttribute("primaryKey"))) {
return true;
}
}
}
return false;
}
}