Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions piccolo/apps/migrations/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def create_migration_table(self) -> bool:
return False

def get_migration_modules(
self, folder_path: str
self, folder_path: Optional[str] = None
) -> dict[str, MigrationModule]:
"""
Imports the migration modules in the given folder path, and returns
Expand All @@ -40,7 +40,8 @@ def get_migration_modules(
"""
migration_modules = {}

sys.path.insert(0, folder_path)
if folder_path is not None:
sys.path.insert(0, folder_path)

folder_contents = os.listdir(folder_path)
excluded = ("__init__.py",)
Expand Down
12 changes: 8 additions & 4 deletions piccolo/apps/migrations/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ def _generate_migration_meta(app_config: AppConfig) -> NewMigrationMeta:

filename = f"{cleaned_app_name}_{cleaned_id}"

path = os.path.join(
app_config.resolved_migrations_folder_path, f"{filename}.py"
)
if app_config.resolved_migrations_folder_path is not None:
path = os.path.join(
app_config.resolved_migrations_folder_path, f"{filename}.py"
)

return NewMigrationMeta(
migration_id=_id, migration_filename=filename, migration_path=path
Expand Down Expand Up @@ -257,7 +258,10 @@ async def new(

app_config = Finder().get_app_config(app_name=app_name)

_create_migrations_folder(app_config.resolved_migrations_folder_path)
if app_config.resolved_migrations_folder_path:
_create_migrations_folder(
app_config.resolved_migrations_folder_path
)

try:
await _create_new_migration(
Expand Down
4 changes: 2 additions & 2 deletions piccolo/conf/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ class AppConfig:
"""

app_name: str
migrations_folder_path: Union[str, pathlib.Path]
migrations_folder_path: Union[str, pathlib.Path, None]
table_classes: list[type[Table]] = field(default_factory=list)
migration_dependencies: list[str] = field(default_factory=list)
commands: list[Union[Callable, Command]] = field(default_factory=list)

@property
def resolved_migrations_folder_path(self) -> str:
def resolved_migrations_folder_path(self) -> Union[str, None]:
return (
str(self.migrations_folder_path)
if isinstance(self.migrations_folder_path, pathlib.Path)
Expand Down
7 changes: 4 additions & 3 deletions tests/apps/migrations/auto/integration/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ def _test_migrations(

migrations_folder_path = app_config.resolved_migrations_folder_path

if os.path.exists(migrations_folder_path):
shutil.rmtree(migrations_folder_path)
if migrations_folder_path is not None:
if os.path.exists(migrations_folder_path):
shutil.rmtree(migrations_folder_path)

_create_migrations_folder(migrations_folder_path)
_create_migrations_folder(migrations_folder_path)

for table_snapshot in table_snapshots:
app_config.table_classes = table_snapshot
Expand Down
7 changes: 7 additions & 0 deletions tests/conf/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def test_get_table_with_name(self):


class TestAppConfig(TestCase):
def test_migrations_folder_path_is_none(self):
"""
Make sure that ``migrations_folder_path`` argument can be ``None``.
"""
config = AppConfig(app_name="music", migrations_folder_path=None)
self.assertEqual(config.resolved_migrations_folder_path, None)

def test_pathlib(self):
"""
Make sure a ``pathlib.Path`` instance can be passed in as a
Expand Down