DependencyTrack / DependencyTrack/dependency-track
Invalid default value's causing MySQL to not start
- Dominant language
- Java
- Stars
- 4.2k
- Forks
- 811
- Avg merge
- 8h 39m
- Merged PRs (30d)
- 237
Description
### Current Behavior
When testing MySQL for another change, creating the DB from scratch throws errors.
From Policy.java:
```
@Persistent
@Column(name = "ONLY_LATEST_PROJECT_VERSION", defaultValue = "false")
private boolean onlyLatestProjectVersion = false;
```
While most DBs handle `false` just fine, MySQL chokes on it. Changing to:
```
@Persistent
@Column(name = "ONLY_LATEST_PROJECT_VERSION", defaultValue = "0")
private boolean onlyLatestProjectVersion = false;
```
_Should_ correctly build the database for all 5 DB types (this hasn't been tested yet....).
`APIKEY` `IS_LEGACY`
```
2025-05-07 17:51:12,179 ERROR [Datastore] Error thrown executing CREATE TABLE "APIKEY"
2025-05-07T17:51:12.181410000Z (
2025-05-07T17:51:12.181475000Z "ID" BIGINT NOT NULL AUTO_INCREMENT,
2025-05-07T17:51:12.181881000Z "COMMENT" VARCHAR(255) BINARY NULL,
2025-05-07T17:51:12.182054000Z "CREATED" TIMESTAMP NULL,
2025-05-07T17:51:12.182261000Z "IS_LEGACY" BIT NOT NULL DEFAULT 'false',
2025-05-07T17:51:12.182344000Z "LAST_USED" TIMESTAMP NULL,
2025-05-07T17:51:12.182436000Z "PUBLIC_ID" VARCHAR(8) BINARY NULL,
2025-05-07T17:51:12.182514000Z "SECRET_HASH" VARCHAR(64) BINARY NULL,
2025-05-07T17:51:12.182541000Z CONSTRAINT "APIKEY_PK" PRIMARY KEY ("ID")
2025-05-07T17:51:12.182595000Z ) ENGINE=INNODB : Invalid default value for 'IS_LEGACY'
2025-05-07T17:51:12.182629000Z java.sql.SQLSyntaxErrorException: Invalid default value for 'IS_LEGACY'
```
This one is odd because the only reference I see to this is in the upgrade script `v4130_1Updater.java`.
This one is a bit more complicated, removing the upgrade script (and references to it) allows MySQL to finish building the database and start succesfully.
### Steps to Reproduce
Start up DT with MySQL.
Using MySQL 5.7.
Env Vars:
```
ALPINE_DATABASE_DRIVER=com.mysql.cj.jdbc.Driver;
ALPINE_DATABASE_MODE=external;
ALPINE_DATABASE_PASSWORD=admin;
ALPINE_DATABASE_URL=jdbc:mysql://host.docker.internal:3306/dtrack?autoReconnect\=true&useSSL\=false&sessionVariables\=sql_mode\='ANSI_QUOTES,STRICT_TRANS_TABLES,ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
ALPINE_DATABASE_USERNAME=user;
LOGGING_LEVEL=DEBUG
```
### Expected Behavior
MySQL based DB starts without issue.
### Dependency-Track Version
4.13.x
### Dependency-Track Distribution
Container Image
### Database Server
MySQL
### Database Server Version
5.7
### Browser
N/A
### Checklist
- [x] I have read and understand the [contributing guidelines](https://github.com/DependencyTrack/dependency-track/blob/master/CONTRIBUTING.md#filing-issues)
- [x] I have checked the [existing issues](https://github.com/DependencyTrack/dependency-track/issues) for whether this defect was already reported
Contributor guide
Assessment
This issue has not been assessed yet.