Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-706 Handle MariaDB sequence max value for versions earlier than 11.5 #2375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joc-a
Copy link
Collaborator

@joc-a joc-a commented Jan 27, 2025

Description

Detailed description:

  • What: Handle MariaDB sequence max value for versions earlier than 11.5.
  • Why: According to the documentation here, MariaDB versions less than 11.5 have a max value for sequences that is lower than the one Exposed currently allows and that causes errors. Exposed allows a max of 9223372036854775807, while MariaDB allows a max of 9223372036854775806.
  • How: I added a new property, sequenceMaxValue, to DatabaseDialect, and that is overridden in MariaDBDialect and used to set the maxValue of Sequence wherever a sequence is created.

How to test:

  1. Go to docker-compose-mariadb.yml
  2. Modify it to use this image: image: mariadb:10.3.0
  3. Run SequencesTests and DatabaseMigrationTests for MariaDB v2 and v3 and they should pass

Type of Change

Please mark the relevant options with an "X":

  • Bug fix
  • New feature
  • Documentation update

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • MariaDB
  • Mysql5
  • Mysql8
  • Oracle
  • Postgres
  • SqlServer
  • H2
  • SQLite

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

@joc-a joc-a changed the title fix: Handle MariaDB sequence max value fix: Handle MariaDB sequence max value for versions earlier than 11.5 Jan 27, 2025
@joc-a joc-a force-pushed the joc/handle-mariadb-sequence-max-value branch from 78640af to 0cf78d8 Compare January 27, 2025 18:12
@joc-a joc-a changed the title fix: Handle MariaDB sequence max value for versions earlier than 11.5 fix: EXPOSED-706 Handle MariaDB sequence max value for versions earlier than 11.5 Jan 27, 2025
…er than 11.5

According to the documentation [here](https://mariadb.com/kb/en/create-sequence/#maxvalue), MariaDB versions less than 11.5 have a max value for sequences that is lower than the one Exposed currently allows and that causes errors.
@joc-a joc-a force-pushed the joc/handle-mariadb-sequence-max-value branch from 0cf78d8 to 0f15119 Compare January 28, 2025 10:24
@joc-a joc-a marked this pull request as ready for review January 28, 2025 11:07
Comment on lines -778 to +809
name = "my_sequence",
startWith = 1,
minValue = 1,
maxValue = 9223372036854775807
)
private val sequenceName by lazy { "custom_sequence" }

private val sequenceName = "custom_sequence"

private val tableWithoutAutoIncrement = object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").entityId()
private val tableWithoutAutoIncrement by lazy {
object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").entityId()
}
}

private val tableWithAutoIncrement = object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").autoIncrement().entityId()
private val tableWithAutoIncrement by lazy {
object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").autoIncrement().entityId()
}
}

private val tableWithAutoIncrementCustomSequence = object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").autoIncrement(sequence).entityId()
private val tableWithAutoIncrementCustomSequence by lazy {
object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").autoIncrement(sequence).entityId()
}
}

private val tableWithAutoIncrementSequenceName = object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").autoIncrement(sequenceName).entityId()
private val tableWithAutoIncrementSequenceName by lazy {
object : IdTable<Long>("test_table") {
override val id: Column<EntityID<Long>> = long("id").autoIncrement(sequenceName).entityId()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed these to lazy properties to be able to make the sequence variable in the test a late-initialized property without running into an error that it is not initalized yet.

@joc-a joc-a requested a review from obabichevjb January 28, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant