akka / akka-persistence-jdbc

Asynchronously writes journal and snapshot entries to configured JDBC databases so that Akka Actors can recover state

Home Page:https://doc.akka.io/docs/akka-persistence-jdbc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SchemaUtils.createIfNotExists(.) doesn't work with H2 Version 2.1.210

alphaville76 opened this issue · comments

H2 Version 2 is a major release with breaking changes, therefore the schema used in
https://github.com/akka/akka-persistence-jdbc/blob/master/core/src/main/resources/schema/h2/h2-create-schema.sql
isn't valid anymore, because of the CONSTRAINT fk_event_journal FOREIGN KEY syntax.

As a temporary workaround instead of SchemaUtils.createIfNotExists(.) I'm using SchemaUtils.applyScript(.) with a script without the FOREIGN_KEY.

That's correct. You should indeed use SchemaUtils.applyScript().

Beware that the plugin is not tested with H2 Version 2, so I hope you won't run into any other issues.

Thanks for the reply, but you should update or drop the H2 v.1 support because of a Log4Shell-Like Vulnerability in the Version 1: https://www.securityweek.com/log4shell-vulnerability-found-popular-h2-database

See also:
CVE-2022-23221
CVE-2021-42392
CVE-2021-23463

I let you know, if I run into other issues.

For the moment, I'm using this script (very similar to the versioned one):

CREATE TABLE IF NOT EXISTS "event_journal"
(
"ordering" BIGINT NOT NULL AUTO_INCREMENT,
"deleted" BOOLEAN DEFAULT false NOT NULL,
"persistence_id" VARCHAR(255) NOT NULL,
"sequence_number" BIGINT NOT NULL,
"writer" VARCHAR NOT NULL,
"write_timestamp" BIGINT NOT NULL,
"adapter_manifest" VARCHAR NOT NULL,
"event_payload" BLOB NOT NULL,
"event_ser_id" INTEGER NOT NULL,
"event_ser_manifest" VARCHAR NOT NULL,
"meta_payload" BLOB,
"meta_ser_id" INTEGER,
"meta_ser_manifest" VARCHAR,
PRIMARY KEY ("persistence_id", "sequence_number")
);

CREATE UNIQUE INDEX IF NOT EXISTS "event_journal_ordering_idx" on "event_journal" ("ordering");

CREATE TABLE IF NOT EXISTS "event_tag"
(
"event_id" BIGINT NOT NULL,
"tag" VARCHAR NOT NULL,
PRIMARY KEY ("event_id", "tag")
);

CREATE TABLE IF NOT EXISTS "snapshot"
(
"persistence_id" VARCHAR(255) NOT NULL,
"sequence_number" BIGINT NOT NULL,
"created" BIGINT NOT NULL,
"snapshot_ser_id" INTEGER NOT NULL,
"snapshot_ser_manifest" VARCHAR NOT NULL,
"snapshot_payload" BLOB NOT NULL,
"meta_ser_id" INTEGER,
"meta_ser_manifest" VARCHAR,
"meta_payload" BLOB,
PRIMARY KEY ("persistence_id", "sequence_number")
);

CREATE TABLE IF NOT EXISTS "durable_state"
(
"global_offset" BIGINT NOT NULL AUTO_INCREMENT,
"persistence_id" VARCHAR(255) NOT NULL,
"revision" BIGINT NOT NULL,
"state_payload" BLOB NOT NULL,
"state_serial_id" INTEGER NOT NULL,
"state_serial_manifest" VARCHAR,
"tag" VARCHAR,
"state_timestamp" BIGINT NOT NULL,
PRIMARY KEY ("persistence_id")
);
CREATE INDEX IF NOT EXISTS "state_tag_idx" on "durable_state" ("tag");
CREATE INDEX IF NOT EXISTS "state_global_offset_idx" on "durable_state" ("global_offset");

CREATE TABLE IF NOT EXISTS "akka_projection_offset_store"
(
"projection_name" VARCHAR(255) NOT NULL,
"projection_key" VARCHAR(255) NOT NULL,
"current_offset" VARCHAR(255) NOT NULL,
"manifest" VARCHAR(4) NOT NULL,
"mergeable" BOOLEAN NOT NULL,
"last_updated" BIGINT NOT NULL,
PRIMARY KEY ("projection_name", "projection_key")
);

CREATE INDEX IF NOT EXISTS "projection_name_index" ON "akka_projection_offset_store" ("projection_name");

CREATE TABLE IF NOT EXISTS "akka_projection_management"
(
"projection_name" VARCHAR(255) NOT NULL,
"projection_key" VARCHAR(255) NOT NULL,
"paused" BOOLEAN NOT NULL,
"last_updated" BIGINT NOT NULL,
PRIMARY KEY ("projection_name", "projection_key")
);

Thanks for the reply, but you should update or drop the H2 v.1 support because of a Log4Shell-Like Vulnerability in the Version 1: securityweek.com/log4shell-vulnerability-found-popular-h2-database

We don't recommend using H2 DB in any production environment. We only recommend it for writing unit tests. Therefore vulnerabilities in the library or in any transitive dependencies is not considered an issue, or at least not a high priority issue.

Because we only recommend it for testing, upgrading should not be an issue. We don't need to care about any backwards compatibility and, since everything is in-memory anyway, I don't think we have any blocker to upgrade to v2.

Would you like to send a PR to update it?

Yes, I'm going to send a PR... give me a couples of days. :-)
My goal is to update the script, so that is compatible with both H2 versions.

and documented in #656