make4db
make like tool for databases.
Like the traditional make tool, make4db builds any modified database scripts, in most cases DDLs, and dependent database scripts in dependency order. For example, when a table DDL is modified, its DDL is evaluated, and then any views that reference the modified table are evaluated, and so on.
One key difference between the traditional make tool and db4make is, that db4make does not rely on file timestamps to detect changes; but instead uses cryptographic hashes.
Features
- build all changed and their dependent objects in the dependency order (
make) - build only specific objects and their references (if changed) in the dependency order (
make <target>) - touch mode -- mark objects as built, without running SQLs (
make -t) - preview mode -- only show objects that would be executed (
make -n) - rebuild unconditionally (
make -B) - when supported by the DBMS, help obtain object dependencies
- in case of a failure, keep building scripts that are not dependent on the failing scripts (
make -k)
Installation
Use pip (pipx recommended) for installation. In addition to make4db package, a database-provider package for m4db must be installed. Available database-provider packages:
make4db-duckdbmake4db-postgresmake4db-snowflake
Usage
m4db is the primary tool. It is used for building changed DDLs and their dependent objects in the correct order.
Use m4db --help to list all available options. Some of the important options are listed below:
--ddl-dir: root directory containing all DDLs. It is recommended to use VCS such as git to store DDLs--tracking-dir: a directory to store DDL execution status. Although execution status is considered persistent information, this directory is not typically version-controlled. There might be different tracking directories that represent different environments, such asdev,prodetc.--out-dir: directory to DDL execution logs
Companion tools
Besides the main tool (m4db), the following tools are also available:
m4db-refs: show or manage object dependency hierarchym4db-gc: garbage collect outdated, orphaned filesm4db-dbclean: allows cleaning up outdated database objects by generatingDROPstatements. Note: only available for some databasesm4db-cache: allows pre-computing cryptographic hash for large repositories
Storing DDLs
-
DDLs are stored as plain text in single-level deep folders.
-
Folder names are used to infer schema name, and file names are used to infer object names. File and folder names are always in lower-case, but converted to upper-case to derive schema and object names
-
File names consist of a base name and extension.
- Base name must match the object name (except filename must be all lower-case).
- File extension must be either
.sqlor.py - File names that start with
.(period) are ignored, and so are any.pyfiles that start with_.
-
Files that have
.sqlextension must contain one or more valid SQL statements. -
Files that have
.pyextension must be a top-level Python script and must contain a function namedsqlreturning one or more SQL statements as string. The following are the two valid function signatures.def sql(name: str, replace: bool) -> str | Iterable[str]: """Dynamically build and return SQL statement(s) Args: name: name of the object being created (or replaced). note: name is qualified with the schema name replace: true if m4db is running in replace mode, that is, --replace option was specified at run-time Returns: A single SQL statement as `str`; or multiple SQL statements as `Iterable[str]` """
def sql(session, name: str, replace: bool) -> str | Iterable[str]: """Dynamically build and return SQL statement(s) Args: session: an active database session (must not be closed) name: name of the object being created (or replaced). note: name is qualified with the schema name replace: true if m4db is running in replace mode, that is, --replace option was specified at run-time Returns: A single SQL statement as `str`; or multiple SQL statements as `Iterable[str]` """
Limitations
- only manages schema-level objects (does not manage databases, schemas, or permissions)
- does not manage cross-database objects (assumes databases are "environments")
- object dependency management, depending on the database support, is semi-automatic
- change detection is based on the file content
Technical details
- Unlike the traditional
makeutility, make4db relies on the cryptographic hash of files to detect changes. - make4db is database agnostic and requires separate database provider module to function
- make4db relies on object references (for example, references of a view being other tables/views) to determine what objects need to be (re)build
- object references are stored along with the database scripts in a hidden folder (
.m4dbin the project-level folder) m4db-refsis a helper tool that can, for selected databases, automatically generate object references
- object references are stored along with the database scripts in a hidden folder (
Metadata
Release files for make4db 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| make4db-0.1.3.tar.gz | 17.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| make4db-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.2 kB
Release files / make4db-0.1.3.tar.gz
| Download URL | make4db-0.1.3.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
000e5464dc0dc4cd51fab6a77efe83e3d1e0e54bd47290da77d2323727f28e28
|
|
BLAKE2b-256 checksum How to use checksums |
91b34f73c81b25f3bbd14c53e287fef0b57d1a96dabf170b2ef11933a904ccbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / make4db-0.1.3-py3-none-any.whl
| Download URL | make4db-0.1.3-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba4749c8a526d3c4f508341f33d70f5c46f21ada28398f0eba2c01fa4c916fbb
|
|
BLAKE2b-256 checksum How to use checksums |
0be772e99d7411f5afca92ee6b1b18b9d49039e74e57b35f83f5aa99ef405c8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for make4db 0.1.3
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.