AdditionalMygrationsAutoImport

Extend this class in any module that ships SQL database migrations.

  1. Overview
  2. base_dir
  3. sql_dir

Overview

The Di container will auto-discover subclasses during add_modules() and register the sql paths returned by sql_paths(). The Mygrations endpoint will automatically prepend those paths (deduplicated, with the endpoint’s explicit sql list taking dedup priority) before executing migrations.

By default, sql points to a folder named sql next to the module file that defines the subclass. Override sql to point elsewhere — relative paths are resolved relative to the defining module’s file, absolute paths are passed through unchanged. Non-existent paths are silently skipped.

The subclass must not require constructor arguments.

Example (zero boilerplate — default sql folder named sql):

# my_module/migrations.py
from clearskies.di import AdditionalMygrationsAutoImport


class MyModuleMigrations(AdditionalMygrationsAutoImport):
    pass


# my_module/__init__.py
from .migrations import MyModuleMigrations  # just needs to be imported

Example (custom folder names):

class MyModuleMigrations(AdditionalMygrationsAutoImport):
    sql = ["database", "schema"]  # both resolved relative to this module's file

base_dir

Optional

Return resolved, existing SQL paths this module contributes as strings.

Relative entries in sql are resolved relative to the module file that
defines the concrete subclass before the existence check runs.  Non-existent
paths are silently omitted.

sql_dir

Optional

The list of SQL file paths or directories this module contributes, as strings. Relative paths are resolved relative to the module file that defines the concrete subclass. Non-existent paths are silently skipped.