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
14 changes: 13 additions & 1 deletion django_mongodb_cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def migrate_project(
None,
help="Optional MongoDB connection URI. Falls back to $MONGODB_URI if not provided.",
),
database: str = typer.Option(
None,
help="Specify the database to migrate.",
),
):
"""
Run Django migrations using django-admin instead of manage.py.
Expand All @@ -238,7 +242,8 @@ def migrate_project(
cmd.append(app_label)
if migration_name:
cmd.append(migration_name)

if database:
cmd.append(f"--database={database}")
typer.echo(f"📦 Applying migrations for project '{name}'")
_django_manage_command(
name, directory, *cmd, extra_env=_build_mongodb_env(mongodb_uri)
Expand Down Expand Up @@ -277,6 +282,10 @@ def manage_command(
mongodb_uri: str = typer.Option(
None, "--mongodb-uri", help="MongoDB connection URI"
),
database: str = typer.Option(
None,
help="Specify the database to use.",
),
):
"""
Run any django-admin command for a project.
Expand All @@ -297,6 +306,9 @@ def manage_command(

os.environ["MONGODB_URI"] = mongodb_uri

if database:
args.append(f"--database={database}")

if command:
typer.echo(f"⚙️ Running django-admin {command} {' '.join(args)} for '{name}'")
_django_manage_command(name, directory, command, *args)
Expand Down
7 changes: 5 additions & 2 deletions django_mongodb_cli/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def do_delete(name):

@repo.command()
def diff(
ctx: typer.Context,
repo_name: str = typer.Argument(None),
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Show diffs of all repositories"
Expand All @@ -272,13 +273,15 @@ def diff(
Show the git diff for the specified repository.
If --all-repos is used, show diffs for all repositories.
"""
repo = Repo()
repo.ctx = ctx
repo_command(
all_repos,
repo_name,
all_msg="Showing diffs for all repositories...",
missing_msg="Please specify a repository name or use -a,--all-repos to show diffs of all repositories.",
single_func=lambda repo_name: Repo().get_repo_diff(repo_name),
all_func=lambda repo_name: Repo().get_repo_diff(repo_name),
single_func=lambda repo_name: repo.get_repo_diff(repo_name),
all_func=lambda repo_name: repo.get_repo_diff(repo_name),
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
from django_mongodb_backend.utils import model_has_encrypted_fields


class EncryptedRouter:
def db_for_read(self, model, **hints):
if model._meta.app_label == "django_mongodb_demo":
return "encrypted"
def allow_migrate(self, db, app_label, model_name=None, **hints):
if hints.get("model"):
if model_has_encrypted_fields(hints["model"]):
return db == "encrypted"
else:
return db == "default"
return None

db_for_write = db_for_read
def db_for_read(self, model, **hints):
if model_has_encrypted_fields(model):
return "encrypted"
return "default"

def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == "django_mongodb_demo":
print("allow_migrate for django_mongodb_demo:", db)
return db == "encrypted"
# Don't create other app's models in the encrypted database.
if db == "encrypted":
return False
def kms_provider(self, model):
if model_has_encrypted_fields(model):
return "local"
return None

def kms_provider(self, model, **hints):
return "local"
db_for_write = db_for_read
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"django_mongodb_extensions.debug_toolbar.panels.MQLPanel",
"debug_toolbar.panels.staticfiles.StaticFilesPanel",
"debug_toolbar.panels.templates.TemplatesPanel",
"debug_toolbar.panels.alerts.AlertsPanel",
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.redirects.RedirectsPanel",
"debug_toolbar.panels.profiling.ProfilingPanel",
"django_mongodb_extensions.debug_toolbar.panels.MQLPanel",
]

# Webpack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
"NAME": "{{ project_name }}_encrypted",
"OPTIONS": {
"auto_encryption_opts": AutoEncryptionOpts(
kms_providers={"local": {"key": os.urandom(96)}}, # noqa
key_vault_namespace="keyvault.__keyVault",
kms_providers={
"local": {
"key": b"tO\x7f\xf2L0\x9e\xab\xcd'\xd3\xd4'P\xf5;3\x94\xde8\xd7\xa4\xc5J\xe9\xb7\xc6\t\xbe\xa3<\xb3\xbe\xb3\xe5E\xb1\xdf[\xfb\x94\x8c`\x9e\xa20*\x82\x16\x98\xa32\x11\xa6\xeb\xfa\x05e\x08/\xe2\x01\xe8\xf1'#\xf9E\xde\xb0\x07Z\x93V\x84.\xf5\xb9\xdbR\xf6\xf6!\xd7;\xa9c\x087\xa1f\x9c\x1b\x86\xe8D"
}
},
key_vault_namespace="{{ project_name }}_encrypted.__keyVault",
),
},
}
Expand Down
16 changes: 9 additions & 7 deletions django_mongodb_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,11 @@ def get_repo_diff(self, repo_name: str) -> None:
Get the diff of a repository.
"""

self.get_repo_status(repo_name)

path, repo = self.ensure_repo(repo_name)
if not repo or not path:
return

self.title(f"{repo_name}:")
unstaged = repo.index.diff(None)
if unstaged:
self.warn("\nChanges not staged for commit:")
Expand Down Expand Up @@ -608,11 +607,14 @@ def set_default_repo(self, repo_name: str) -> None:
if repo_name not in self.map:
self.err(f"Repository '{repo_name}' not found in configuration.")
return
subprocess.run(
["gh", "repo", "set-default"],
cwd=self.get_repo_path(repo_name),
check=True,
)
try:
subprocess.run(
["gh", "repo", "set-default"],
cwd=self.get_repo_path(repo_name),
check=True,
)
except subprocess.CalledProcessError as e:
self.err(f"❌ Failed to set default repository: {e}")


class Package(Repo):
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ repos = [
"mongo @ git+ssh://[email protected]/mongodb/mongo@master",
"drivers-evergreen-tools @ git+ssh://[email protected]/mongodb-labs/drivers-evergreen-tools@master",
"docs @ git+ssh://[email protected]/mongodb/docs@main",
"docs-sample-apps @ git+ssh://[email protected]/mongodb/docs-sample-apps@main",
"flask-pymongo @ git+ssh://[email protected]/mongodb-labs/flask-pymongo",
"mongo-arrow @ git+ssh://[email protected]/mongodb-labs/mongo-arrow@main",
"mongo-orchestration @ git+ssh://[email protected]/mongodb-labs/mongo-orchestration@master",
Expand All @@ -101,6 +102,13 @@ path = "src"
[tool.django-mongodb-cli.install.libmongocrypt]
install_dir = "bindings/python"

[tool.django-mongodb-cli.install.langchain-mongodb]
install_dir = "libs/langchain-mongodb"

[tool.django-mongodb-cli.test.langchain-mongodb]
test_command = "pytest"
test_dir = "src/langchain-mongodb/libs/langchain-mongodb/tests"

[tool.django-mongodb-cli.test.mongo-python-driver]
test_command = "just"
test_dir = "src/mongo-python-driver/test"
Expand Down
30 changes: 0 additions & 30 deletions templates/app_template/.github/workflows/django.yml

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions templates/app_template/admin.py-tpl

This file was deleted.

6 changes: 0 additions & 6 deletions templates/app_template/apps.py-tpl

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions templates/app_template/models.py-tpl

This file was deleted.

Loading