Skip to main content

Exobrain database model and migration management

Project description

exobrain-database

PyPI - Version PyPI - Python Version CI/CD


exobrain-database is a Python library that provides the SQLAlchemy ORM models, Alembic migration management, and utility tools for the Exobrain platform database. It supports a multi-tenant architecture where each organization has its own isolated PostgreSQL schema.

The package is distributed as a namespace package under exobrain.database, making it composable with other exobrain.* packages.


Table of Contents


Installation

pip install exobrain-database

Or with uv:

uv add exobrain-database

Development

This project uses uv for dependency management and building.

Prerequisites: Python 3.12+ and uv

Setup:

git clone git@github.com:MyExobrain/exobrain-database.git
cd exobrain-database
uv sync --all-groups

Common tasks:

uv run pytest                                  # Run tests
uv run pytest --cov=exobrain.database          # Tests with coverage
uv run ruff check src tests                    # Lint
uv run ruff format src tests                   # Format
uv run mypy src                                # Type check
uv build                                       # Build wheel + sdist

Add dependencies:

uv add package-name                # Production
uv add --group dev package-name    # Development
uv sync --upgrade                  # Update all

Project Structure

The source code lives under src/exobrain/database/ as a namespace package:

src/exobrain/database/
├── migrations/               # Alembic migration engine
│   ├── alembic.ini           # Alembic configuration file
│   ├── env.py                # Migration environment setup
│   ├── migration_manager.py  # Public API: upgrade / downgrade per org schema
│   └── versions/             # Auto-generated migration scripts
├── model/                    # SQLAlchemy ORM models
│   ├── base.py               # Declarative base classes
│   ├── associations/         # Many-to-many association tables
│   ├── enums/                # Database enumeration types (config, currency, running states)
│   ├── general/              # Cross-organization models (copilots, permissions, roles,
│   │                         #   predefined actions/executions/risks, reasons)
│   └── org/                  # Per-organization models (config, connections, dashboards,
│                             #   running actions/executions/risks, scopes, users)
└── tools/                    # Reusable database utilities
    ├── jsonb_filter.py       # Helper for filtering on JSONB columns
    ├── record_count.py       # Efficient record counting queries
    └── sql_query_logger.py   # SQLAlchemy query logging utility

Key design decisions

  • Multi-tenant schemas: each organization's data is isolated in a dedicated PostgreSQL schema (e.g. org_<id>). Migrations are applied per-schema via migration_manager.upgrade(org_id).
  • Namespace package: exobrain.database has no __init__.py at the exobrain level, allowing other exobrain.* packages to coexist in the same Python environment.
  • py.typed marker: the package ships type information and is fully typed (compatible with mypy in strict mode).
  • Build system: Uses uv as the modern Python build & package manager.

Usage

Apply migrations for an organization

from uuid import UUID
from exobrain.database.migrations import migration_manager

org_id = UUID("12345678-1234-5678-1234-567812345678")
migration_manager.upgrade(org_id)

Use ORM models

from exobrain.database.model.general.role import Role
from exobrain.database.model.org.user import User

License

exobrain-database is distributed under a proprietary license. See LICENSE.md for details.

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

exobrain_database-0.1.1.tar.gz (59.9 kB view details)

Uploaded Source

Built Distribution

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

exobrain_database-0.1.1-py3-none-any.whl (141.7 kB view details)

Uploaded Python 3

File details

Details for the file exobrain_database-0.1.1.tar.gz.

File metadata

  • Download URL: exobrain_database-0.1.1.tar.gz
  • Upload date:
  • Size: 59.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for exobrain_database-0.1.1.tar.gz
Algorithm Hash digest
SHA256 01b85602246bbee0911ce593a18f0f30c2e01a3ee27e2a31ab597f3bb494f2d9
MD5 12dc078f3fbf152556d6a7d61610611d
BLAKE2b-256 19628e0dcca555e62203ac2f9e5caabe23f2ad965ca2d8b2749bcd991ff63c7c

See more details on using hashes here.

File details

Details for the file exobrain_database-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: exobrain_database-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 141.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for exobrain_database-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86776d98758f76a23dd673ddc19c4a9afa38462405dc102bed308f23151422ad
MD5 74c472e2ffcc8c6526f8d7035a641e13
BLAKE2b-256 db6cbfa2b88cc5b07f492b39a16ec2265c02d6a72fa5e8340421416835fc5db0

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