Commit Graph
36 Commits
Author SHA1 Message Date
LeoVasanko ab5b7584c9 Updated docs 2026-09-02 17:34:20 +00:00
LeoVasanko d33f3f9c2f Add @kanta.validate integrity-validation callbacks
Validators receive the live data object (and optionally the Kanta
instance) and raise on inconsistency. They run after replay/migrations
during open() and after each transaction before the change is queued;
a failure rolls back the transaction or aborts the open. Multiple
validators run in registration order until the first failure. Sync-only,
since transactions are synchronous.
2026-09-02 17:02:14 +00:00
LeoVasanko aee6c13996 Implement database rotation with n days retention (#2)
- Automatically erase history, keep as separate timestamped files.
- Full history may be recovered by concatenation of the files.
- Only applied at database opening time.
- Enable by Kanta(retention=...), use with care (experimental feature).
2026-09-02 16:46:19 +00:00
LeoVasanko 94c5ddeaba Inject state dicts by name (prev/state), rename MigrationResult to MigrationReport.
State dict injection now works by parameter name (prev/state, annotation
not checked) with DictPrev/DictState tags taking precedence; DictPre/DictPost
remain as aliases. MigrationResult is renamed to MigrationReport with fields
original/version/applied; the old type alias and a deprecated .migrations
property remain. Old symbols stay covered by the original tests; new-style
tests import from the kanta root. Includes some unrelated ruff formatting.
2026-08-27 14:50:34 +00:00
LeoVasanko 4ef74e027f Re-export from kanta configure_logging. 2026-08-27 13:41:31 +00:00
LeoVasanko 6839b48f6d Support filesystem paths in --data, --migrations, and --kanta arguments. 2026-08-13 21:31:21 +00:00
LeoVasanko 955fdd8e1c Locate only the current Python version's site-packages in nearby .venv dirs. 2026-08-13 21:27:14 +00:00
LeoVasanko 20694576c7 Scope sys.path additions around dynamic imports and include nearby .venv site-packages. 2026-08-13 21:23:28 +00:00
LeoVasanko 8be44bd490 Add CWD to sys.path so CLI can import target modules. 2026-08-13 21:12:59 +00:00
LeoVasanko f8a0a85158 Pretty-print snapshot lines and drop microseconds from CLI timestamps. 2026-08-13 21:12:33 +00:00
LeoVasanko 8e436295aa Add experimental kanta CLI for inspecting databases. 2026-08-13 18:44:46 +00:00
LeoVasanko 0b8c1d2da9 Ruff 2026-08-11 01:34:39 +00:00
LeoVasanko 33a8c07043 Make tests follow the earlier change of merging version and msgspec migration records into one. 2026-08-11 01:34:06 +00:00
LeoVasanko be3acaed3e Smarter change record formatting to 80ch wide, shortened with ellipsis character rather than three dots. 2026-08-11 01:21:34 +00:00
LeoVasanko f489216c2a All remaining events through logformat, cleaner migration message, prettier demo. 2026-08-07 17:12:29 +00:00
LeoVasanko 08f3c44f1f Group all migration events into one row migrate:vN (if version changed) OR migrate:msgspec
- Log as a single event
- Logging config has debug parameter to lower level to DEBUG, showing migration diffs
2026-08-07 16:20:56 +00:00
LeoVasanko e0046ae9d9 Cleanup 2026-08-07 16:10:46 +00:00
LeoVasanko c101f187d8 Implement richer, fully customizable logging; customizable timestamps (#1)
- `@kanta.logemit` handler for completely customizable logging output, with `LogEvent` structure and `kanta.tty.Line` helper to create colorized text and fixed width fields
- `configure_logging(diff=False)` to disable diff display globally (supplementing per-transaction `logdiff=False`)
- `transaction(extra: Any = ...)` for passing extra strings or custom metadata to logs
- `@kanta.clock` to provide user controlled clock for deterministic database outputs
- Added a demo script that shows basic functions, migrations, logfmt etc.
2026-08-07 15:08:28 +00:00
LeoVasanko 3a56bfbb10 Add kanta.bootstrap logger and configurable logging setup
- Bootstrap records are now logged via kanta.bootstrap at INFO level.
- Existing databases log 'Using <path>' at DEBUG on kanta.bootstrap.
- New databases log 'Created <path>' at INFO on kanta.bootstrap.
- Renamed loggers: kanta.changes -> kanta.transaction, kanta.migrations -> kanta.migration.
- configure_logging() gains bootstrap/migration/transaction/skiproot kwargs.
- Default configure_logging() attaches a no-prefix stderr handler to kanta and stops propagation.
- With skiproot=False, child logger propagation flags are still applied but kanta itself is left untouched.
- Updated tests and docstrings.
2026-06-20 19:10:58 +00:00
LeoVasanko 55fa475a13 Log new database creation, bootstrap like a transaction. 2026-06-20 18:15:08 +00:00
LeoVasanko 753b7eba86 Add separate migration logging, logmigr callback, and log= override
- Split transaction logger (kanta.changes) and migration logger (kanta.migrations).
- Migrations.apply() now returns MigrationResult instead of logging.
- Kanta.open() emits one info summary per DB and debug transaction per migration.
- Add open(log=...) to suppress/redirect default migration logging.
- Add @kanta.logmigr callback for custom migration logging/summaries.
- Add transaction(log=...) to suppress/redirect transaction logging.
- Update tests for the new MigrationResult API and logging behaviour.
2026-06-15 23:13:03 +00:00
LeoVasanko 42789e6619 Revised migration context: don't store changerecord unless something was changed, and always snapshot if and after changes done. 2026-06-15 22:14:03 +00:00
LeoVasanko c4726e6728 Stricter versioning: always store migrate version record, file must be within versions included in migrations. Log only for migrations that made changes. Allow deleting older migration functions when no longer required. 2026-06-15 03:09:45 +00:00
LeoVasanko 66e92739ab Refactor Migrations internals, add caching to avoid reloading per each Kanta instance. Naming changed from MigrationRegistry to Migration, module from migrate to kanta.migrations. 2026-06-15 01:12:42 +00:00
LeoVasanko 4dc2f0648e Fix creation of new database, ensuring that a bootstrap record of the initial state is always written. 2026-06-15 00:27:49 +00:00
LeoVasanko bec4635460 Add kanta.ctx SimpleNamespace for user variables. This is passed to migration functions if they take a second argument. Remove the old MigrationCtx system. 2026-06-14 19:54:23 +00:00
LeoVasanko c04a245366 Add read only mode that doesn't use locking. Useful for inspection while the database is in use or when no changes are intended (except in RAM). 2026-06-14 19:35:06 +00:00
LeoVasanko b501fcca86 Only Kanta exported at root, others available from submodules. 2026-06-13 21:26:35 +00:00
LeoVasanko 7e553bd868 Improved log formatting support by @kanta.logfmt, which replaces old resolver and user_display arguments (breaking change). 2026-06-13 21:22:05 +00:00
LeoVasanko 4db046d627 Implement proper bootstrap and fatal error handling via decorators. Breaks compatibility. 2026-06-13 02:53:09 +00:00
LeoVasanko acabc049e7 Fixed typing. 2026-06-13 00:59:18 +00:00
LeoVasanko 43f2cdbd53 Removed useless lock. 2026-06-13 00:55:05 +00:00
LeoVasanko ebfed10f24 Proper ts/mtime setting and tracking. Added Kanta.mtime property for reading current change time. 2026-06-13 00:49:35 +00:00
LeoVasanko e8d123a748 Don't make package root a module (debug). 2026-06-13 00:31:07 +00:00
LeoVasanko 56b955cfdf Fix imports 2026-06-12 19:23:23 +00:00
LeoVasanko c254970ae5 Initial commit 2026-06-12 19:15:46 +00:00