Skip to content

Generator

pelican.generator.generate_migration

generate_migration(name, ops=None, migration_dir=_DEFAULT_MIGRATION_DIR)
Source code in pelican/generator.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def generate_migration(
    name: str,
    ops: Sequence[DiffOperation] | None = None,
    migration_dir: str | Path = _DEFAULT_MIGRATION_DIR,
) -> Path:
    migration = Migration(revision=_generate_revision(), name=name)
    migration_file = Path(migration_dir) / migration.file_name
    migration_file.parent.mkdir(parents=True, exist_ok=True)

    if ops is not None:
        content = _render_autogenerate_body(ops, migration)
    else:
        content = _get_template("migration").format(migration=migration)

    migration_file.write_text(content)
    return migration_file