Skip to main content

Delete tenant-scoped MySQL data by walking foreign-key relationships

Project description

Titto

Titto deletes tenant-scoped rows from a MySQL schema by reading table metadata, following foreign-key paths back to a tenant table, nulling optional references, and deleting rows in dependency order.

Warnings

This is a destructive database tool. Run it against production only after testing the exact command against a restored copy or staging database.

--commit permanently commits the deletes. Without --commit, Titto still runs the UPDATE and DELETE statements inside a transaction, then rolls them back. That dry run can still take locks, fire triggers, and affect non-transactional tables.

Take a backup before any committed run. Prefer a database snapshot or logical dump that you have already tested restoring. Keep the backup until the tenant removal has been verified.

Usage

Show commands:

uv run titto --help

Dry-run a single-column tenant key and cache table metadata as JSON:

uv run titto delete "$DB_URL" tenant 42 --cache .tables.json

Commit the delete:

uv run titto delete "$DB_URL" tenant 42 --cache .tables.json --commit

Use a composite tenant key by passing each primary-key part as its own token:

uv run titto delete "$DB_URL" tenant 42 eu --cache .tables.json

Require selected tables to be empty for the tenant before deleting anything:

uv run titto delete "$DB_URL" tenant 42 --skip invoice --skip payment

Clean up unreferenced rows in tables that are not directly tenant-scoped:

uv run titto cleanup "$DB_URL" tenant --cache .tables.json

Clean up unreferenced rows in explicitly selected tables:

uv run titto cleanup-tables "$DB_URL" tag category --cache .tables.json

DB_URL is a MySQL URL such as:

mysql://user:password@localhost:3306/app_schema

Avoid putting real passwords directly in shell history. Use an environment variable, secret manager, or another shell-safe mechanism appropriate for your environment.

Cache Notes

--cache stores parsed table metadata as JSON. The recommended local cache path is .tables.json; it is ignored by Git.

The cache is tied to the host, port, schema name, and cache format version. Titto rejects mismatched cache metadata and reparses the database schema. If the schema changes on the same host and schema name, delete .tables.json so Titto can refresh it.

Development

Run the test suite:

uv run python -m unittest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

titto-0.2.tar.gz (8.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

titto-0.2.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

titto-0.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file titto-0.2.tar.gz.

File metadata

  • Download URL: titto-0.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for titto-0.2.tar.gz
Algorithm Hash digest
SHA256 4c4d023d33c01c5b63ea368e4ac27d1fb2b26a95c2eb6d8b0de26940a5203ad0
MD5 3c58f0045d1717085a2705a648fad9a2
BLAKE2b-256 ab7386cc8d12084f37e70e643d64d6f766a1953cec6f839efc619ecf0682a5c4

See more details on using hashes here.

File details

Details for the file titto-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: titto-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for titto-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4970b5b039a9de6d4f0bebf6f9d30ada1c2058fa1c8b06b177f28f52bef27c27
MD5 ae1b8ef1617da94c666fddb2fce4ad24
BLAKE2b-256 c8ae0c1ca85ba9fafc78e6e1211a3bc5639ec96712b89ea758e819fbca23753a

See more details on using hashes here.

File details

Details for the file titto-0.2-py3-none-any.whl.

File metadata

  • Download URL: titto-0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for titto-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a23bf912232b4a861ab5e990a277d2da782f4abb3a47670e9405013b1473b0fd
MD5 ff911a2b3143e3ad39b7ba7bae0ea82c
BLAKE2b-256 821128d456af356906f68ae20cb9db594c3785bca91c165d957cb23d0b876b38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page