Skip to content
Merged
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
Empty file.

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
working-directory: example/config-app
run: uv sync

- name: Copy .env.example to .env (config-app)
working-directory: example/config-app
run: cp .env.example .env

- name: Run tests (config-app)
working-directory: example/config-app
run: uv run pytest tests/ -v
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ fastapi_startkit/dist
fastapi_startkit.github.io.git
laravel-repo
application
.agents
.uv_cache
4 changes: 2 additions & 2 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ echo ""
echo "============================================================"
echo " Running: fastapi_startkit package tests"
echo "============================================================"
(cd "$ROOT/fastapi_startkit" && uv run pytest)
(cd "$ROOT/fastapi_startkit" && uv run pytest tests)

echo ""
echo "============================================================"
Expand All @@ -33,4 +33,4 @@ echo ""
echo "============================================================"
echo " Running: example/database-app tests"
echo "============================================================"
(cd "$ROOT/example/database-app" && uv run pytest)
(cd "$ROOT/example/database-app" && uv run pytest)
5 changes: 5 additions & 0 deletions example/config-app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
APP_ENV=development

REDIS_HOST=host.default
REDIS_PORT=0000
REDIS_DB=0
1 change: 1 addition & 0 deletions example/config-app/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/database-app/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions fastapi_startkit/src/fastapi_startkit/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def set_environment(self, env: str):
self.env = env
return self

def load_environment(self):
"""Reload environment variables for the current self.env."""
Environment.load_base(base_path=self.base_path)
Environment.load(self.env, base_path=self.base_path)
return self

def configure_exception_handler(self):
self.exception_manager: ExceptionHandler = self._exception_handler_class(
application=self
Expand Down Expand Up @@ -176,6 +182,7 @@ def __call__(self, *args, **kwargs):

def resolve_environment(self):
self.env = Environment.resolve_environment(base_path=self.base_path, env=self.env)
Environment.load_base(base_path=self.base_path)
Environment.load(self.env, base_path=self.base_path)

def is_debug(self) -> bool:
Expand Down
16 changes: 12 additions & 4 deletions fastapi_startkit/src/fastapi_startkit/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@ def resolve_environment(base_path=None, env: str | None = None):
if "PYTEST_CURRENT_TEST" in os.environ:
return "testing"

if os.environ.get("APP_ENV"):
return os.environ["APP_ENV"]

# Explicit env parameter takes priority over os.environ APP_ENV
if env:
return env

if os.environ.get("APP_ENV"):
return os.environ["APP_ENV"]

path = base_path / ".env"
if not path.exists():
raise ValueError("Unable to determine environment.")

load_dotenv(path)
load_dotenv(path, override=True)

env = os.environ.get("APP_ENV")
if not env:
raise ValueError("APP_ENV not set after loading .env")

return env

@staticmethod
def load_base(base_path=None):
"""Load the base .env file, resetting vars to their default values."""
path = base_path / ".env"
if path.exists():
load_dotenv(path, override=True)

@staticmethod
def load(env: str, override=True, only=None, base_path=None):
path = base_path / f".env.{env}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dumpdie import dd
from fastapi_startkit.masoniteorm.models import registry
from .BaseRelationship import BaseRelationship
from ..collection import Collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,21 @@ def compile_alter_sql(self, diff):
or diff.changed_columns
or diff.added_foreign_keys
):
original_columns = diff.from_table.added_columns
original_columns = dict(diff.from_table.added_columns)
# pop off the dropped columns. No need for them here
for column in diff.dropped_columns:
original_columns.pop(column)
original_columns.pop(column, None)

sql.append(
"CREATE TEMPORARY TABLE __temp__{table} AS SELECT {original_column_names} FROM {table}".format(
table=diff.name,
original_column_names=", ".join(
diff.from_table.added_columns.keys()
),
original_column_names=", ".join(original_columns.keys()),
)
)

sql.append("DROP TABLE {table}".format(table=self.wrap_table(diff.name)))

columns = diff.from_table.added_columns
columns = dict(original_columns)

columns.update(diff.renamed_columns)
columns.update(diff.changed_columns)
Expand Down Expand Up @@ -264,9 +262,7 @@ def compile_alter_sql(self, diff):
quoted_table=self.wrap_table(diff.name),
table=diff.name,
new_columns=", ".join(self.columnize_names(columns)),
original_column_names=", ".join(
diff.from_table.added_columns.keys()
),
original_column_names=", ".join(columns.keys()),
)
)
sql.append("DROP TABLE __temp__{table}".format(table=diff.name))
Expand Down
Loading