Skip to main content

Herramienta de replicación de esquemas que desacopla la estructura de la integridad para permitir cargas de datos de alto rendimiento.

Project description

Schema Replicator

Schema Replicator is a specialized module designed to handle the intelligent replication of database schemas. Unlike standard dump utilities, it is designed to split the DDL (Data Definition Language) generation into logical phases to support high-performance data loading pipelines.

This library will allow you to clone a DB structure to another DB. Then you may use another tool to migrate the data from one DB to another being able to run multiple parallel batches while not having to worry about the order of the data. Finally, with just one command, this library will apply the integrity restrictions on the target DB (Foreign Keys, Constraints) once you are done loading the data.

Core Philosophy

Relational databases have strict integrity rules (Foreign Keys, Constraints) that make simple data copying difficult (the "Chicken and Egg" problem).

Schema Replicator solves this by decoupling the Structure from the Integrity:

  1. Base DDL: Creates tables with columns and primary types only.
  2. Constraint DDL: Creates Foreign Keys, non-essential Indexes, and complex checks.

By applying "Base DDL" first and "Constraint DDL" last, we allow data pipelines (like db_orchestrator) to load data in parallel without worrying about insertion order or constraint violations.

Components

extractor.py (DDLExtractor)

Uses SQLAlchemy's inspection engine to reflect an existing database.

  • get_table_base_ddl(table_name): Returns the CREATE TABLE SQL statement stripped of Foreign Keys and complex constraints.
  • get_constraints_and_indexes_ddl(table_name): Returns a list of ALTER TABLE ADD CONSTRAINT and CREATE INDEX statements.

applier.py (DDLApplier)

A simple executor wrapper.

  • apply_ddl(ddl_statements): Executes a list of SQL statements against a target database connection transactionally.

Integration

With db_orchestrator

This module is the backbone of the Orchestrator's migration strategy.

  • Phase 1: Orchestrator calls get_table_base_ddl to prepare the destination.
  • Phase 2: Orchestrator loads data using anonimize.
  • Phase 3: Orchestrator calls get_constraints_and_indexes_ddl to seal the database integrity.

With anonimize

While schema_replicator does not directly import anonimize, they are symbiotic.

  • schema_replicator ensures the container (Table) exists and has the correct data types.
  • anonimize ensures the content (Rows) is transformed and secure before filling that container.

Usage Example

from sqlalchemy import create_engine
from schema_replicator.extractor import DDLExtractor
from schema_replicator.applier import DDLApplier

source_engine = create_engine("postgresql://user:pass@source/db")
dest_engine = create_engine("postgresql://user:pass@dest/db")

extractor = DDLExtractor(source_engine)
applier = DDLApplier(dest_engine)

# 1. Base Structure
base_sql = extractor.get_table_base_ddl("users")
applier.apply_ddl([base_sql])

# ... Load Data Here ...

# 2. Integrity
constraints_sql = extractor.get_constraints_and_indexes_ddl("users")
applier.apply_ddl(constraints_sql)

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

schema_replicator-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

schema_replicator-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file schema_replicator-0.1.0.tar.gz.

File metadata

  • Download URL: schema_replicator-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for schema_replicator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4aa0257ba3042709a80a4421277752a7fbc36699ac9b38b7030f09067f199a1
MD5 796e4e7af0c7358517056b38191ea964
BLAKE2b-256 2f6f93f77cc310ad4af869860bc7e004fed5efc0ed06b9eb170b5a5ad0d050af

See more details on using hashes here.

Provenance

The following attestation bundles were made for schema_replicator-0.1.0.tar.gz:

Publisher: python-publish.yml on AleLoredo/schema_replicator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file schema_replicator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for schema_replicator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 002f0090ed310bf3d5cf6cf3455634e7f919af3ee90735165cdfffbe53cb9901
MD5 9d3dee478382cfb692e5aba63c59ac91
BLAKE2b-256 c44e31e8f93afb8b26f0ba5cb69d6d0aa02474848eb87a8333d913eb1a4f72ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for schema_replicator-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on AleLoredo/schema_replicator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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