Skip to content

Commit

Permalink
feat: migration for SQL Server
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-alfers committed Feb 3, 2024
1 parent e28e821 commit a86caba
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 127 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ lazy val docs = project
"scaladoc.akka.base_url" -> s"https://doc.akka.io/api/akka/${Dependencies.AkkaVersionInDocs}/",
"javadoc.akka.base_url" -> s"https://doc.akka.io/japi/akka/${Dependencies.AkkaVersionInDocs}/",
"scaladoc.com.typesafe.config.base_url" -> s"https://lightbend.github.io/config/latest/api/",
"sqlserver.version" -> Dependencies.SqlServerVersion),
"sqlserver.version" -> Dependencies.SqlServerR2dbcVersion),
ApidocPlugin.autoImport.apidocRootPackage := "akka",
apidocRootPackage := "akka",
resolvers += Resolver.jcenterRepo,
Expand Down
30 changes: 26 additions & 4 deletions docs/src/main/paradox/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ re-run the full migration.
It's recommended that you create the `migration_progress` table before running the migration tool, but
if it doesn't exist the tool will try to create the table.

```sql
Postgres:
: ```sql
CREATE TABLE IF NOT EXISTS migration_progress(
persistence_id VARCHAR(255) NOT NULL,
event_seq_nr BIGINT,
Expand All @@ -47,6 +48,23 @@ CREATE TABLE IF NOT EXISTS migration_progress(
PRIMARY KEY(persistence_id)
```
SQLServer:
: ```sql
IF object_id('migration_progress') is null
CREATE TABLE migration_progress(
persistence_id NVARCHAR(255) NOT NULL,
event_seq_nr BIGINT,
snapshot_seq_nr BIGINT,
state_revision BIGINT,
PRIMARY KEY(persistence_id)
```

@@@ warning { .group-sqlserver }

The SQL Server dialect is marked `experimental` and not yet production ready until various [issues](https://github.com/akka/akka-persistence-r2dbc/issues?q=is%3Aopen+label%3Asqlserver+label%3Abug) with the integration of the `r2dbc-mssql` plugin have been resolved.

@@@

## Running

The migration tool can be run as main class `akka.persistence.r2dbc.migration.MigrationTool` provided by the above
Expand All @@ -56,13 +74,17 @@ The migration tool can be run as main class `akka.persistence.r2dbc.migration.Mi

Durable State is not migrated by `MigrationTool.migrateAll`, instead you need to use `MigrationTool.migrateDurableStates` for a given list of persistence ids.

@@@ note
@@@

## Configuration

You need to provide configuration for the source persistence plugin and the target Rd2BC plugin in your `application.conf`. An example of such configuration for migration from Akka Persistence JDBC:
You need to provide configuration for the source persistence plugin and the target Rd2BC plugin in your `application.conf`. An example of such configuration for migration from Akka Persistence JDBC:

Postgres:
: @@snip [application-postgres.conf](/migration-tests/src/test/resources/application-postgres-example.conf)

@@snip [application-postgres.conf](/migration-tests/src/test/resources/application-postgres.conf)
SQLServer:
: @@snip [application-sqlserver.conf](/migration-tests/src/test/resources/application-sqlserver-example.conf)

@@@ note

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
akka.persistence.r2dbc.migration {
source {
query-plugin-id = "jdbc-read-journal"
snapshot-plugin-id = "jdbc-snapshot-store"
}
}

akka.persistence.r2dbc.connection-factory = ${akka.persistence.r2dbc.sqlserver}
akka.persistence.r2dbc.connection-factory {
host = "localhost"
port = 1433
database = "your_db"
user = "your_user"
password = "your_password"
}

akka-persistence-jdbc {
shared-databases {
default {
profile = "slick.jdbc.SQLServerProfile$"
db {
url = "jdbc:sqlserver://"127.0.0.1":1433;databaseName=master;integratedSecurity=false;"
user = "user"
password = "password"
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
numThreads = 5
maxConnections = 5
minConnections = 1
}
}
}
}

jdbc-journal {
use-shared-db = "default"
}
jdbc-snapshot-store {
use-shared-db = "default"
}
jdbc-read-journal {
use-shared-db = "default"
}

# application specific serializers for events and snapshots
# must also be configured and included in classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
akka.persistence.r2dbc.connection-factory = ${akka.persistence.r2dbc.sqlserver}
2 changes: 1 addition & 1 deletion migration-tests/src/test/resources/logback-main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<appender-ref ref="STDOUT"/>
</root>

</configuration>
</configuration>
24 changes: 24 additions & 0 deletions migration-tests/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%date{ISO8601}] [%level] [%logger] [%X{akkaAddress}] [%marker] [%thread] - %msg%n</pattern>
</encoder>
</appender>


<appender name="CapturingAppender" class="akka.actor.testkit.typed.internal.CapturingAppender"/>
<!-- <logger name="akka.persistence.r2dbc.migration.MigrationTool" level="DEBUG" />-->

<logger name="akka.persistence.r2dbc" level="DEBUG" />
<!-- <logger name="io.r2dbc.postgresql.QUERY" level="DEBUG" />-->
<!-- <logger name="io.r2dbc.mssql.QUERY" level="DEBUG" />-->
<!-- <logger name="io.r2dbc.pool" level="DEBUG" />-->

<root level="INFO">
<appender-ref ref="CapturingAppender"/>
<!-- <appender-ref ref="STDOUT"/>-->
</root>

</configuration>
Loading

0 comments on commit a86caba

Please sign in to comment.