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

Download files

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

Source Distribution

clandestino-0.1.3.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

clandestino-0.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file clandestino-0.1.3.tar.gz.

File metadata

  • Download URL: clandestino-0.1.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.1.0-17-amd64

File hashes

Hashes for clandestino-0.1.3.tar.gz
Algorithm Hash digest
SHA256 eeda41beeada237d7cc874b4bf9bd5ba4f89a38bd9f6de25fa315311da041115
MD5 ae91d4b7499f6f6d20826350c67f83b3
BLAKE2b-256 1f2e1db436276ce60c3797e26cdb8a05817f391c4b287789aaef7c13ca3c6d87

See more details on using hashes here.

File details

Details for the file clandestino-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: clandestino-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.1.0-17-amd64

File hashes

Hashes for clandestino-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6c2f388bc151660149ba6b02432da3cac25b3ef801a9b0681bc950ddc83dccf1
MD5 c940ede69149b70e14bdcde6027b2621
BLAKE2b-256 11e129a40542dd349401e4740bc0023d9f6717c3d3c5d2af2919737d1e5ca894

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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