Skip to main content

Clandestino

banner

By: CenturyBoys

This package provides a migration tool. It includes a command-line interface (CLI) for easy execution and a single asynchronous function that can be imported and used in your code.

Install

The main package does not have any database implementation and uses only the interfaces and abstractions from the clandestino_interfaces package. In other words, you are free to create your own implementations. We will explain the details later.

Database Type Install using extra description Environment parameter
PostgreSQL postgres here CLANDESTINO_POSTGRES_CONNECTION_STRING
Elasticsearch elasticsearch here CLANDESTINO_ELASTICSEARCH_CONNECTION_STRING
MongoDB mongo here CLANDESTINO_MONGO_CONNECTION_STRING

How to install extra packages?

poetry add clandestino -E postgres
OR
pip install 'romeways[postgres]'

Config

Clandestino has some configurations that you can set as environment variables or in a .env file.

  • CLANDESTINO_MIGRATION_REPO If you are using any of the extra packages, you must set them with their respective values: POSTGRES, ELASTICSEARCH, MONGO

CLI

[-h] Help command

$cdt -h         
 Clandestino is a database migration tool
 Migration repository mode is: ELASTICSEARCH
  cldest [-h|-m|-lm|-rm|-cm] [params]

    -h: Display help
    -m: Migrate database
    -lm: List migrations
    -rm: Rollback last migration
    -cm: Create database migration - params [name type]

[-m] Migrate database

Migrate databases using the files within the ./migrations folder. Each migration checks if it's already run. If not, the migration is applied, the information is saved, and the async def up(self) -> None method is called. No migration will be executed twice.

The system will display the migration status:

  • OK = ✅
  • ERROR = ⚠️
  • SKIPPED = ⏭️

[-lm] List migrations

List all migration within the ./migrations folder

[-rm] Rollback migration

Rollback the last database migration using the latest file in the ./migrations folder. The async def down(self) -> None method within the file will be called.

The system will display the rollback status:

  • OK = ✅
  • ERROR = ⚠️
  • SKIPPED = ⏭️

[-cm] Create migration

Create a migration within the ./migrations folder, if the folder not exists create it to.

This command receive two parameters:

  • Migration name
  • Migration type, if not filled will use default migration template.

The migration file will be like this migration_{datetime_reference}_{migration_name}.py

Migration file

The migration file inherit the abstract class AbstractMigration and need declare two fundtions:

  • async def up(self) -> None. This method will be called on migration command
  • async def down(self) -> None. This method will be called on rollback command

See bellow an empty template file

from clandestino_interfaces import AbstractMigration

class Migration(AbstractMigration):

    infra = None

    async def up(self) -> None:
        """Do modifications in database"""
        pass

    async def down(self) -> None:
        """Undo modifications in database"""
        pass

Self Implementation

To create your own Clandestino implementation, simply create a file named repository.py inside the ./migrations folder. This file should contain a class named MigrateRepository that inherits from clandestino_interfaces.IMigrateRepository.

Observation: Your migrations need to handler the database connections by your self.

See bellow the interface:

from abc import ABC, abstractmethod

class IMigrateRepository(ABC):
    @classmethod
    @abstractmethod
    async def create_control_table(cls) -> None:
        pass

    @classmethod
    @abstractmethod
    async def control_table_exists(cls) -> bool:
        pass

    @classmethod
    @abstractmethod
    async def register_migration_execution(cls, migration_name: str) -> None:
        pass

    @classmethod
    @abstractmethod
    async def migration_already_executed(cls, migration_name: str) -> bool:
        pass

    @classmethod
    @abstractmethod
    async def remove_migration_execution(cls, migration_name: str) -> None:
        pass

Metadata

Release files for clandestino 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clandestino 0.1.0
File Size Uploaded Provenance Actions
clandestino-0.1.0.tar.gz 9.3 kB Without provenance Details for clandestino-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clandestino 0.1.0
File Interpreter ABI Platform Actions
clandestino-0.1.0-py3-none-any.whl Python 3 none any Details for clandestino-0.1.0-py3-none-any.whl

Total release size: 19.3 kB

Release files / clandestino-0.1.0.tar.gz

Download URL clandestino-0.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
55d92bedff2e18a00accc12b818f0190237bca4ca84c09b6afad5df7de7e18a5
BLAKE2b-256 checksum
How to use checksums
b37fe55504415ddac08065409054e9511091a97c1e3d44faced35a4f3359e2cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.2 Linux/6.1.0-17-amd64

Release files / clandestino-0.1.0-py3-none-any.whl

Download URL clandestino-0.1.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e293f0030661500008ea2cad0743812bcc73c3ff38a7eb12e25ace493bec25de
BLAKE2b-256 checksum
How to use checksums
1b94982f2341677b112c2fce55f026e4f2ac83831c9c1a8805d281e59f75f96c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.2 Linux/6.1.0-17-amd64

Security for clandestino 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page