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:
- Base DDL: Creates tables with columns and primary types only.
- 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 theCREATE TABLESQL statement stripped of Foreign Keys and complex constraints.get_constraints_and_indexes_ddl(table_name): Returns a list ofALTER TABLE ADD CONSTRAINTandCREATE INDEXstatements.
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_ddlto prepare the destination. - Phase 2: Orchestrator loads data using
anonimize. - Phase 3: Orchestrator calls
get_constraints_and_indexes_ddlto seal the database integrity.
With anonimize
While schema_replicator does not directly import anonimize, they are symbiotic.
schema_replicatorensures the container (Table) exists and has the correct data types.anonimizeensures 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4aa0257ba3042709a80a4421277752a7fbc36699ac9b38b7030f09067f199a1
|
|
| MD5 |
796e4e7af0c7358517056b38191ea964
|
|
| BLAKE2b-256 |
2f6f93f77cc310ad4af869860bc7e004fed5efc0ed06b9eb170b5a5ad0d050af
|
Provenance
The following attestation bundles were made for schema_replicator-0.1.0.tar.gz:
Publisher:
python-publish.yml on AleLoredo/schema_replicator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
schema_replicator-0.1.0.tar.gz -
Subject digest:
a4aa0257ba3042709a80a4421277752a7fbc36699ac9b38b7030f09067f199a1 - Sigstore transparency entry: 858304609
- Sigstore integration time:
-
Permalink:
AleLoredo/schema_replicator@389c0668f6b4fea4ce198602491e88bc6f1c1c27 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/AleLoredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@389c0668f6b4fea4ce198602491e88bc6f1c1c27 -
Trigger Event:
release
-
Statement type:
File details
Details for the file schema_replicator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: schema_replicator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
002f0090ed310bf3d5cf6cf3455634e7f919af3ee90735165cdfffbe53cb9901
|
|
| MD5 |
9d3dee478382cfb692e5aba63c59ac91
|
|
| BLAKE2b-256 |
c44e31e8f93afb8b26f0ba5cb69d6d0aa02474848eb87a8333d913eb1a4f72ea
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
schema_replicator-0.1.0-py3-none-any.whl -
Subject digest:
002f0090ed310bf3d5cf6cf3455634e7f919af3ee90735165cdfffbe53cb9901 - Sigstore transparency entry: 858304679
- Sigstore integration time:
-
Permalink:
AleLoredo/schema_replicator@389c0668f6b4fea4ce198602491e88bc6f1c1c27 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/AleLoredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@389c0668f6b4fea4ce198602491e88bc6f1c1c27 -
Trigger Event:
release
-
Statement type: