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

feat: sqlserver / mssql support #505

Merged
merged 21 commits into from
Feb 2, 2024

Conversation

sebastian-alfers
Copy link
Contributor

@sebastian-alfers sebastian-alfers commented Jan 22, 2024

Next iteration based on discussion in #494.


Note that in the sqlserver specific overrides, named binding is still used. This is recommended by the plugin, and my have several advantages:

  • no need to bind a param multiple times if needed,
  • no need to use the getAndIncIndex approach for conditional binding,
  • no need to bind in order and
  • more readable.

However, I see this is not aligned with the rest of the project, so I have no problem with converting to positional binding for where it is not yet used.


More notes:

  • the test fails when changing the log level of the root logger and / or of the sqlserver QUERY class to DEBUG
  • perf spec sometimes fails

@sebastian-alfers sebastian-alfers marked this pull request as draft January 22, 2024 10:29
Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

looking good


override def encode(timestamp: Instant): LocalDateTime = LocalDateTime.ofInstant(timestamp, zone)

override def now[T](): T = LocalDateTime.ofInstant(instantNow(), zone).asInstanceOf[T]
Copy link
Member

Choose a reason for hiding this comment

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

that cast to T looks dangerous, for example this usage:

override def currentDbTimestamp(): Future[Instant] = Future.successful(timestampCodec.now())

wouldn't that cast a LocalDateTime to an Instant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, right. I am fixing this now. It seems I can get rid of def now[T](): T completely, and fix the places where I am not yet binding a timestamp with the codec specific .bindTimestamp.

The unsafe casts must not yet have been triggered I assume.

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

looking good, a few comments about the timestamps


override def decode(row: Row, name: String): Instant = toInstant(row.get(name, classOf[LocalDateTime]))

override def encode(timestamp: Instant): LocalDateTime = LocalDateTime.ofInstant(timestamp, zone)
Copy link
Member

Choose a reason for hiding this comment

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

this is good, it wouldn't surprise me if r2dbc-sqlserver would add support for binding Instant in a future version. seems like a missing thing to me. anyway, for us this is good now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They discussed it already here and here.

Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

Looking good, left some questions and nitpicks but I think the only big thing missing is documentation.

@@ -74,6 +74,7 @@ class MigrationToolSpec

private val migration = new MigrationTool(system)

// enable for sqlserver as well?
Copy link
Member

Choose a reason for hiding this comment

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

Seems fine if it passes, if not, not sure it is important to deal with right away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Table creation would need to be tailored for sqlserver, skipping it for now.

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 I create a ticket for this?

Copy link
Member

Choose a reason for hiding this comment

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

The migration tool is only using methods in the dao that we are using for other things already, if I'm not misremembering. Therefore it is not that important to test it with all dialects. I think the comment can be removed and nothing more.

Copy link
Member

Choose a reason for hiding this comment

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

@sebastian-alfers I think I misunderstood. The question wasn't only about the test. The MigrationTool has it's own MigrationDao, which would be different for sqlserver. Please create an issue and we handle it if it comes up as a request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

docker/docker-compose-sqlserver.yml Show resolved Hide resolved
ddl-scripts/create_tables_sqlserver.sql Show resolved Hide resolved
Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

LGTM with a few more nitpicks and CI green. Would be good with a second LGTM before merging though.

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

Looking good, only a few minor things.
Maybe it can be worth looking at the dialect in Akka Projections before we release to see that this fits in with that.


package akka.persistence.r2dbc.internal.codec

trait QueryAdapter {
Copy link
Member

Choose a reason for hiding this comment

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

private[akka] on all these internal classes, and the usual InternalApi markers

Copy link
Member

Choose a reason for hiding this comment

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

Maybe some of these will be needed for the sqlserver dialect in Akka Projections?

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 can look into projections regarding sqlserver.

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 was building the sqlserver dialect in projections based on a publishLocal snapshot from this branch, and did not see any problems in this regards.

ddl-scripts/create_tables_sqlserver.sql Outdated Show resolved Hide resolved
docs/src/main/paradox/getting-started.md Show resolved Hide resolved
docs/src/main/paradox/getting-started.md Outdated Show resolved Hide resolved
@sebastian-alfers
Copy link
Contributor Author

Maybe it can be worth looking at the dialect in Akka Projections before we release to see that this fits in with that.

I looked at projections and did not see anything missing, when it comes to integrating changes from this PR.

@patriknw patriknw marked this pull request as ready for review January 31, 2024 10:39
Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

LGTM

@patriknw patriknw merged commit e28e821 into akka:main Feb 2, 2024
8 checks passed
@patriknw patriknw added this to the 1.2.2 milestone Feb 2, 2024
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.

3 participants