Migration tools for cassandra

Hello, everyone!

I am currenlty working on a custom Webcrawler pet-service, written in Elixir and using Cassandra as a database.

I am using Xandra as a driver.

Can anyone suggest migration tools for this kind of database ?

I discovered some ecto-based packages on top of cqerl and Xandra, but with longly outdated dependencies.

So, does some kind of migrator exists for cassandra?

Thanks! :smiley:

We ran into the same issue as you (no packages looked good), so we basically just copied Ecto migrations ourselves, i.e. we have a schema_migrations table in each keyspace. It’s a bit more complicated cuz we’re multitenanted, and thus have a keyspace for each tenant.

In retrospect, and after several side projects, I’m not sure that was the easiest approach. You can simply just use Ecto migrations to manage your Cassandra schema. Ecto migrations are just a generic way to make sure some chunk of code gets run only one time; nothing stopping you from writing migrations that alter Cassandra schema.

Edit: I assumed you’re also using a relational database and thus Ecto.

1 Like

Thanks for the reply.

The idea of using some kind of Cassandra Ecto driver and Ecto just for migrations may be the way to go.

No no, I mean just use straight up Ecto migrations, no need for a “Cassandra Ecto” driver at all


defmodule Repo.Migrations.CreateFooKeyspace do
  use Ecto.Migration
  
  def up do
    {:ok, conn} = Xandra.start_link(...)
    
    Xandra.execute!(conn, """
      CREATE KEYSPACE foo ...
    """)
  end

  def down do
    {:ok, conn} = Xandra.start_link(...)
    
    Xandra.execute!(conn, """
      DROP KEYSPACE foo ...
    """)
  end
end

There is nothing stopping you from running arbitrary code in Ecto migrations.

I see.

Blockquote
Edit: I assumed you’re also using a relational database and thus Ecto.

Do you use another DB for the schema_migrations table ? Like postgres or ETS ?

Yes, we use Postgres for relation data.

But if you’re not using some relational database already, adding one to your infra just to use Ecto migrations to manage Cassandra schema doesn’t seem like a good idea.