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: Add support for creating sequence in MariaDB #2324

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

devgor88
Copy link
Contributor

@devgor88 devgor88 commented Dec 5, 2024

Description

Summary of the change: Add support for creating sequence in MariaDB.

Detailed description:

  • What: Variable supportsCreateSequence overrided from MysqlDialect(). Now it checks db version and return true for version upper or equal than 10.3 11.5 (sequences is supported from 10.3 but we can get list of them only starting with 11.5).

  • Why: It was necessary because existing isVersionCovers compares version as BigDecimal. Due to it 10.11 < 10.3.

  • How: There were added majorVersion and minorVersion in ExposedDatabaseMetadata. They were implemented in JdbcDatabaseMetadataImpl. isVersionCovers function implemented with two parameters major and minor versions.


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

@devgor88 devgor88 marked this pull request as draft December 5, 2024 10:08
@devgor88 devgor88 closed this Dec 5, 2024
@devgor88 devgor88 reopened this Dec 5, 2024
@devgor88 devgor88 marked this pull request as ready for review December 5, 2024 19:34
@devgor88 devgor88 closed this Dec 6, 2024
@devgor88 devgor88 reopened this Dec 6, 2024
@joc-a joc-a self-assigned this Dec 6, 2024
@devgor88
Copy link
Contributor Author

devgor88 commented Dec 6, 2024

I'll fix some tests

@devgor88 devgor88 marked this pull request as draft December 6, 2024 17:34
@devgor88 devgor88 marked this pull request as ready for review December 8, 2024 12:45
TransactionManager.current().db.isVersionCovers(SEQUENCE_MIN_MAJOR_VERSION, SEQUENCE_MIN_MINOR_VERSION)
}

// actually MariaDb supports it but jdbc driver prepares statement without RETURNING clause
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we implement this by ourselves? I looked how Oracle do this. As I understand Exposed sends sql without returning clause and jdbc driver add it after.

Copy link
Collaborator

@joc-a joc-a left a comment

Choose a reason for hiding this comment

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

Hi @devgor88. Thank you for your contribution! I left some comments.

Comment on lines 79 to 87
override fun sequences(): List<String> {
val sequences = mutableListOf<String>()
TransactionManager.current().exec("SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES") { rs ->
while (rs.next()) {
sequences.add(rs.getString("SEQUENCE_NAME"))
}
}
return sequences
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is overriding this function necessary? I tested your changes with MariaDB 10.3, and this was not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested it again with MariaDB 10.3 and

const val SEQUENCE_MIN_MAJOR_VERSION = 10
const val SEQUENCE_MIN_MINOR_VERSION = 3

At least several tests are fail. Especially important is org.jetbrains.exposed.sql.tests.shared.ddl.SequencesTests#testManuallyCreatedSequenceExists

Overriding can be omitted for versions between 10.3 and 11.5 because it and its super functions return empty list. For versions more or equal 11.5 it can be omitted too because super function is working correctly but I'd left it because super version run this query

SELECT TABLE_SCHEMA TABLE_CAT, NULL  TABLE_SCHEM,  TABLE_NAME, IF(TABLE_TYPE='BASE TABLE' or TABLE_TYPE='SYSTEM VERSIONED', 'TABLE', IF(TABLE_TYPE='TEMPORARY', 'LOCAL TEMPORARY', TABLE_TYPE)) as TABLE_TYPE, TABLE_COMMENT REMARKS, NULL TYPE_CAT, NULL TYPE_SCHEM, NULL TYPE_NAME, NULL SELF_REFERENCING_COL_NAME,  NULL REF_GENERATION FROM INFORMATION_SCHEMA.TABLES WHERE  TABLE_TYPE IN ('SEQUENCE') ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME

Copy link
Collaborator

Choose a reason for hiding this comment

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

What tests are failing for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rerun them again and none of sequence related tests are failing.

Comment on lines 90 to 91
const val SEQUENCE_MIN_MAJOR_VERSION = 11
const val SEQUENCE_MIN_MINOR_VERSION = 5
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's possible to get a list of sequences from version 10.3 and without overriding the sequences() function above, then this can be changed from 11.5 to 10.3.

@devgor88
Copy link
Contributor Author

devgor88 commented Dec 13, 2024

Hi @joc-a. Thank you for reviewing my contribution. I answered your comments.

@devgor88 devgor88 requested a review from joc-a December 21, 2024 17:54
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.

2 participants