Skip to content

Commit

Permalink
Load migrations from custom directory (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bp72 authored Feb 4, 2024
1 parent 65a9f51 commit 9b4d9e6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions simple_migrations/migrate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from datetime import datetime, timezone
from importlib import import_module
from importlib import util as importlib_util

import psycopg

Expand Down Expand Up @@ -77,7 +77,9 @@ def migrate(until: int | None, fake: bool) -> int:
for m_id, migration in migrations_to_apply:
sys.stdout.write(f"{log_action} {migration}... ")
if not fake:
migration_obj = import_module(f"{config.migrations_dir}.{migration[:-3]}")
spec = importlib_util.spec_from_file_location(migration[:-3], f"{config.migrations_dir}/{migration}")
migration_obj = importlib_util.module_from_spec(spec)
spec.loader.exec_module(migration_obj)
method = getattr(migration_obj, command)
method()
if command == "forwards":
Expand Down

0 comments on commit 9b4d9e6

Please sign in to comment.