22
33[ ![ Build Status] ( https://travis-ci.org/okumin/akka-persistence-sql-async.svg?branch=master )] ( https://travis-ci.org/okumin/akka-persistence-sql-async )
44
5- A journal and snapshot store plugin for [ akka-persistence] ( http://doc.akka.io/docs/akka/2.3.11 /scala/persistence.html ) using RDBMS.
5+ A journal and snapshot store plugin for [ akka-persistence] ( http://doc.akka.io/docs/akka/2.4.0 /scala/persistence.html ) using RDBMS.
66Akka-persistence-sql-async executes queries by [ ScalikeJDBC-Async] ( https://github.com/scalikejdbc/scalikejdbc-async ) that provides non-blocking APIs to talk to databases.
77
88
99Akka-persistence-sql-async supports following databases.
1010- MySQL
1111- PostgreSQL
1212
13- This library is tested against [ akka-persistence-tck] ( http://doc.akka.io/docs/akka/2.3.11 /scala/persistence.html#plugin-tck ) .
13+ This library is tested against [ akka-persistence-tck] ( http://doc.akka.io/docs/akka/2.4.0 /scala/persistence.html#plugin-tck ) .
1414
1515## Usage
1616
@@ -19,7 +19,7 @@ This library is tested against [akka-persistence-tck](http://doc.akka.io/docs/ak
1919You should add the following dependency.
2020
2121```
22- libraryDependencies += "com.okumin" %% "akka-persistence-sql-async" % "0.2.1 "
22+ libraryDependencies += "com.okumin" %% "akka-persistence-sql-async" % "0.3.0 "
2323```
2424
2525And then, please include the mysql-async if you use MySQL.
@@ -49,18 +49,20 @@ akka {
4949akka-persistence-sql-async {
5050 journal.class = "akka.persistence.journal.sqlasync.MySQLAsyncWriteJournal"
5151 snapshot-store.class = "akka.persistence.snapshot.sqlasync.MySQLSnapshotStore"
52-
52+
5353 # For PostgreSQL
5454 # journal.class = "akka.persistence.journal.sqlasync.PostgreSQLAsyncWriteJournal"
5555 # snapshot-store.class = "akka.persistence.snapshot.sqlasync.PostgreSQLSnapshotStore"
5656
5757 user = "root"
5858 password = ""
5959 url = "jdbc:mysql://localhost/akka_persistence_sql_async"
60- max-pool-size = 4 # total connection count
61- wait-queue-capacity = 10000 # If query cannot be executed soon, it wait in the queue and will be executed later.
62- journal-table-name = "journal"
63- snapshot-table-name = "snapshot"
60+ max-pool-size = 4
61+ wait-queue-capacity = 10000
62+
63+ metadata-table-name = "persistence_metadata"
64+ journal-table-name = "persistence_journal"
65+ snapshot-table-name = "persistence_snapshot"
6466}
6567```
6668
@@ -71,48 +73,64 @@ Create the database and tables for journal and snapshot store.
7173### MySQL
7274
7375```
74- CREATE TABLE IF NOT EXISTS {your_journal_table_name} (
76+ CREATE TABLE IF NOT EXISTS {your_metadata_table_name} (
77+ persistence_key BIGINT NOT NULL AUTO_INCREMENT,
7578 persistence_id VARCHAR(255) NOT NULL,
7679 sequence_nr BIGINT NOT NULL,
77- marker VARCHAR(255) NOT NULL,
80+ PRIMARY KEY (persistence_key),
81+ UNIQUE (persistence_id)
82+ ) ENGINE = InnoDB;
83+
84+ CREATE TABLE IF NOT EXISTS {your_journal_table_name} (
85+ persistence_key BIGINT NOT NULL,
86+ sequence_nr BIGINT NOT NULL,
7887 message BLOB NOT NULL,
79- created_at TIMESTAMP NOT NULL ,
80- PRIMARY KEY (persistence_id, sequence_nr )
81- );
88+ PRIMARY KEY (persistence_key, sequence_nr) ,
89+ FOREIGN KEY (persistence_key) REFERENCES {your_metadata_table_name} (persistence_key )
90+ ) ENGINE = InnoDB ;
8291
8392CREATE TABLE IF NOT EXISTS {your_snapshot_table_name} (
84- persistence_id VARCHAR(255) NOT NULL,
93+ persistence_key BIGINT NOT NULL,
8594 sequence_nr BIGINT NOT NULL,
8695 created_at BIGINT NOT NULL,
8796 snapshot BLOB NOT NULL,
88- PRIMARY KEY (persistence_id, sequence_nr)
89- );
97+ PRIMARY KEY (persistence_key, sequence_nr),
98+ FOREIGN KEY (persistence_key) REFERENCES {your_metadata_table_name} (persistence_key)
99+ ) ENGINE = InnoDB;
90100```
91101
92102### PostgreSQL
93103
94104```
95- CREATE TABLE IF NOT EXISTS {your_journal_table_name} (
105+ CREATE TABLE IF NOT EXISTS {your_metadata_table_name} (
106+ persistence_key BIGSERIAL NOT NULL,
96107 persistence_id VARCHAR(255) NOT NULL,
97108 sequence_nr BIGINT NOT NULL,
98- marker VARCHAR(255) NOT NULL,
99- message BYTEA NOT NULL,
100- created_at TIMESTAMP NOT NULL,
101- PRIMARY KEY (persistence_id, sequence_nr)
109+ PRIMARY KEY (persistence_key),
110+ UNIQUE (persistence_id)
102111);
103112
113+ CREATE TABLE IF NOT EXISTS {your_journal_table_name} (
114+ persistence_key BIGINT NOT NULL REFERENCES {your_metadata_table_name}(persistence_key),
115+ sequence_nr BIGINT NOT NULL,
116+ message BYTEA NOT NULL,
117+ PRIMARY KEY (persistence_key, sequence_nr)
118+ );
104119
105120CREATE TABLE IF NOT EXISTS {your_snapshot_table_name} (
106- persistence_id VARCHAR(255) NOT NULL,
121+ persistence_key BIGINT NOT NULL REFERENCES {your_metadata_table_name}(persistence_key) ,
107122 sequence_nr BIGINT NOT NULL,
108123 created_at BIGINT NOT NULL,
109124 snapshot BYTEA NOT NULL,
110- PRIMARY KEY (persistence_id , sequence_nr)
125+ PRIMARY KEY (persistence_key , sequence_nr)
111126);
112127```
113128
114129## Release Notes
115130
131+ ### 0.2.1 - Sep 25, 2015
132+ - [ Keep the highest sequence number] ( https://github.com/okumin/akka-persistence-sql-async/issues/6 )
133+
116134### 0.2 - Apr 5, 2015
117135- [ Change pass to password in configuration] ( https://github.com/okumin/akka-persistence-sql-async/issues/3 )
118136
0 commit comments