question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Cassandra migrations for Lagom itself not possible

See original GitHub issue

We want to migrate the Lagom tables by ourself and not rely on these two settings but set them to false:

cassandra-snapshot-store {
  keyspace-autocreate = false
  tables-autocreate = false
}

This does work for tables-autocreate = false almost all components but not the KafkaTopicProducers which are eagerly started in LagomKafkaComponents via new ScaladslRegisterTopicProducers and that accesses the snapshot store. Also I could not manage to set keyspace-autocreate = false in general.

Expected behavior

I want to decouple C* migrations from the Lagom and run the migrations on my own. This is required for production system upgrades when some of the Lagom tables change.

My workaround is the following:

For Dev/Test I keep keyspace-autocreate = true and tables-autocreate = true and never run migrations for Lagom locally. I don’t like this because I can never test that my migrations are working before I deploy to a preprod environment. Ideally we can somehow hook into the “init” callback from akka-persistence where Lagom creates it’s own tables.

For production we set keyspace-autocreate = false and tables-autocreate = false and manage migrations by oureself by running them after the deployment. Of course this requires Lagom code to be compatible with new and old versions which is usually the case.

Lagom Version (1.2.x / 1.3.x / etc)

1.4.

API (Scala / Java / Neither / Both)

Scala

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fkoehlercommented, Apr 26, 2018

One possible workaround would be to make your service implementation’s constructor depend on the component that needs to run first. This will ensure the right ordering, though if the dependency executes asynchronously you would also need to block on it to prevent initialization from proceeding.

I followed your advice and this is how I was able to solve the problem (in dev mode, using the right init order for the traits and making the migrations blocking)

1reaction
TimMoorecommented, Feb 27, 2018

@fkoehler I would not recommend performing migrations from the ApplicationLoader, because in a multi-node cluster it will run on each node. Cassandra schema modifications are not concurrency safe, so you should run migrations in production using a separate process decoupled from your services.

It’s a fair point about having more control over the initialization process, however.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lagom cassandra readside table not created - Stack Overflow
I have created a user repository Lagom readside in my user-impl service, but for some reason the Cassandra users table doesn't get created...
Read more >
lagom/lagom - Gitter
Cassandra runs in the JVM, making it easy to integrate into a Java or Scala development environment without having to worry about OS-specific...
Read more >
Cassandra Setup - Lagom Framework
This page describes how to configure Cassandra for use with Persistent Entity API or Akka Typed Persistence in a Lagom service .
Read more >
Cassandra Java Create Schema
Interacting with Cassandra using the Datastax Java driver. 116 ... This schema migration is created by no limitations to create schemas for running, ......
Read more >
Migration • Akka Persistence Cassandra - Documentation
Versions 0.101+ make it possible to drop the static column used . This saves space for persistence ids that have been deleted. Also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found