1

I have this table in cassandra

CREATE TABLE daily_stats (
    day text,
    user text,
    clicks counter
    PRIMARY KEY ((day, user))
)

All I need to change is the partitioning key to

PRIMARY KEY (day, user)

Now cassandra does not allow me to alter table like this. It also does not support table renaming.

So the only way to update primary key in cassandra table is to create new table and migrate data to it from old table. That's easy.

But I would like to prepare the infrastructure for other such future changes.

What I can easily come up with is add version suffixes for every table

daily_stats_v1
daily_stats_v2

Or to every keyspace

app_stats_v1
app_stats_v2

Then it would be really easy to create the new fixed table, update apps to use this table and finally migrate data from old table.

Anyways, I'm more interested in good practices and "the proper ways to do it".

Community
  • 1
  • 1
PovilasB
  • 1,488
  • 1
  • 15
  • 25
  • Aside from your actual question, are you sure that's the schema you want to use? That means all the stats for a day will be stored in one partition. So all your writes will be handled by one machine. – Alec Collier Jan 06 '16 at 00:45
  • That was a simplified sample. To be closer to my real data model primary key would be `(user, day)` :) – PovilasB Jan 06 '16 at 06:21

0 Answers0