Skip to content

iconik-io/cassandra-model-keys-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cassandra Model Keys Checker

A pre-commit hook that checks for redefined partition_key or primary_key fields in Cassandra model subclasses.

Usage

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/iconik-io/cassandra-model-keys-checker
    rev: v1.0.0  # Use the latest release tag
    hooks:
      - id: cassandra-model-keys-checker

What it checks

This hook ensures that base model classes don't have fields that are redefined in child classes with partition_key=True or primary_key=True.

Example of code that will fail

class UserBaseModel(Model):
    __abstract__ = True

    status = columns.Text()
    email = columns.Text()
    tenant_id = columns.TimeUUID()

class UserModel(UserBaseModel):
    tenant_id = columns.TimeUUID(partition_key=True, primary_key=True)  # ❌ Error!

class UserByEmailModel(UserBaseModel):
    email = columns.TimeUUID(partition_key=True, primary_key=True)  # ❌ Error!

Example of valid code

class UserBaseModel(Model):
    __abstract__ = True
    status = columns.Text()

class UserModel(UserBaseModel):
    email = columns.Text()  # ✅ OK
    tenant_id = columns.TimeUUID(partition_key=True, primary_key=True)  # ✅ OK

class UserByEmailModel(UserBaseModel):
    email = columns.Text(partition_key=True, primary_key=True)  # ✅ OK
    tenant_id = columns.TimeUUID()  # ✅ OK

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages