88using Akka . Actor ;
99using Akka . Hosting ;
1010using Akka . Persistence . Hosting ;
11+ using Akka . Persistence . Sql . Config ;
12+ using Akka . Persistence . Sql . Hosting ;
1113
1214namespace Akka . Persistence . Sql . Hosting
1315{
@@ -65,11 +67,70 @@ public static class HostingExtensions
6567 /// </para>
6668 /// <b>Default</b>: <c>true</c>
6769 /// </param>
70+ /// <param name="journalDatabaseMapping">
71+ /// <para>
72+ /// The database options to modify database table column mapping for this journal.
73+ /// </para>
74+ /// <b>NOTE</b>: This is used primarily for backward compatibility,
75+ /// you leave this empty for greenfield projects.
76+ /// </param>
77+ /// <param name="databaseMapping">
78+ /// <para>
79+ /// The database options to modify database table column mapping for this journal.
80+ /// </para>
81+ /// <b>NOTE</b>: This is used primarily for backward compatibility,
82+ /// you leave this empty for greenfield projects.
83+ /// </param>
84+ /// <param name="tagStorageMode">
85+ /// <para>
86+ /// Describe how tags are being stored inside the database. Setting this to
87+ /// <see cref="TagMode.Csv"/> will store the tags as a comma delimited value
88+ /// in a column named <c>tags</c> inside the event journal. Setting this to
89+ /// <see cref="TagMode.TagTable"/> will store the tags inside a separate
90+ /// tag table instead.
91+ /// </para>
92+ /// <b>NOTE</b>: This is used primarily for backward compatibility,
93+ /// you leave this empty for greenfield projects.
94+ /// </param>
95+ /// <param name="deleteCompatibilityMode">
96+ /// <para>
97+ /// If true, journal_metadata is created and used for deletes
98+ /// and max sequence number queries.
99+ /// </para>
100+ /// <b>NOTE</b>: This is used primarily for backward compatibility,
101+ /// you leave this empty for greenfield projects.
102+ /// </param>
103+ /// <param name="useWriterUuidColumn">
104+ /// <para>
105+ /// A flag to indicate if the writer_uuid column should be generated and be populated in run-time.
106+ /// </para>
107+ /// <b>Notes:</b>
108+ /// <list type="number">
109+ /// <item>
110+ /// The column will only be generated if auto-initialize is set to true.
111+ /// </item>
112+ /// <item>
113+ /// This feature is Akka.Persistence.Sql specific, setting this to true will break
114+ /// backward compatibility with databases generated by other Akka.Persistence plugins.
115+ /// </item>
116+ /// <item>
117+ /// <para>
118+ /// To make this feature work with legacy plugins, you will have to alter the old
119+ /// journal table:
120+ /// </para>
121+ /// <c>ALTER TABLE [journal_table_name] ADD [writer_uuid_column_name] VARCHAR(128);</c>
122+ /// </item>
123+ /// <item>
124+ /// If set to true, the code will not check for backward compatibility. It will expect
125+ /// that the `writer-uuid` column to be present inside the journal table.
126+ /// </item>
127+ /// </list>
128+ /// </param>
68129 /// <returns>
69130 /// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.
70131 /// </returns>
71132 /// <exception cref="ArgumentOutOfRangeException">
72- /// Thrown when <see cref ="journalBuilder"/> is set and <see cref ="mode"/> is set to
133+ /// Thrown when <paramref name ="journalBuilder"/> is set and <paramref name ="mode"/> is set to
73134 /// <see cref="PersistenceMode.SnapshotStore"/>
74135 /// </exception>
75136 public static AkkaConfigurationBuilder WithSqlPersistence (
@@ -81,7 +142,11 @@ public static AkkaConfigurationBuilder WithSqlPersistence(
81142 Action < AkkaPersistenceJournalBuilder > ? journalBuilder = null ,
82143 bool autoInitialize = true ,
83144 string pluginIdentifier = "sql" ,
84- bool isDefaultPlugin = true )
145+ bool isDefaultPlugin = true ,
146+ DatabaseMapping ? databaseMapping = null ,
147+ TagMode ? tagStorageMode = null ,
148+ bool ? deleteCompatibilityMode = null ,
149+ bool ? useWriterUuidColumn = null )
85150 {
86151 if ( mode == PersistenceMode . SnapshotStore && journalBuilder is { } )
87152 throw new Exception ( $ "{ nameof ( journalBuilder ) } can only be set when { nameof ( mode ) } is set to either { PersistenceMode . Both } or { PersistenceMode . Journal } ") ;
@@ -97,14 +162,24 @@ public static AkkaConfigurationBuilder WithSqlPersistence(
97162 ConnectionString = connectionString ,
98163 ProviderName = providerName ,
99164 AutoInitialize = autoInitialize ,
165+ TagStorageMode = tagStorageMode ,
166+ DeleteCompatibilityMode = deleteCompatibilityMode ,
100167 } ;
101168
169+ if ( databaseMapping is { } )
170+ journalOpt . DatabaseOptions = databaseMapping . Value . JournalOption ( ) ;
171+
102172 if ( schemaName is { } )
103173 {
104- journalOpt . DatabaseOptions = new JournalDatabaseOptions ( DatabaseMapping . Default )
105- {
106- SchemaName = schemaName
107- } ;
174+ journalOpt . DatabaseOptions ??= JournalDatabaseOptions . Default ;
175+ journalOpt . DatabaseOptions . SchemaName = schemaName ;
176+ }
177+
178+ if ( useWriterUuidColumn is { } )
179+ {
180+ journalOpt . DatabaseOptions ??= JournalDatabaseOptions . Default ;
181+ journalOpt . DatabaseOptions . JournalTable ??= JournalTableOptions . Default ;
182+ journalOpt . DatabaseOptions . JournalTable . UseWriterUuidColumn = useWriterUuidColumn ;
108183 }
109184
110185 var adapters = new AkkaPersistenceJournalBuilder ( journalOpt . Identifier , builder ) ;
@@ -118,12 +193,13 @@ public static AkkaConfigurationBuilder WithSqlPersistence(
118193 AutoInitialize = autoInitialize ,
119194 } ;
120195
196+ if ( databaseMapping is { } )
197+ snapshotOpt . DatabaseOptions = databaseMapping . Value . SnapshotOption ( ) ;
198+
121199 if ( schemaName is { } )
122200 {
123- snapshotOpt . DatabaseOptions = new SnapshotDatabaseOptions ( DatabaseMapping . Default )
124- {
125- SchemaName = schemaName
126- } ;
201+ snapshotOpt . DatabaseOptions ??= new SnapshotDatabaseOptions ( DatabaseMapping . Default ) ;
202+ snapshotOpt . DatabaseOptions . SchemaName = schemaName ;
127203 }
128204
129205 return mode switch
0 commit comments