Skip to content

Commit ae78517

Browse files
committed
Misc updates
- Remove old templates - Remove print statement - Add repo - Update project template - Use router from test runs - Fix `dm repo diff -a`
1 parent c84492e commit ae78517

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+57
-1773
lines changed

django_mongodb_cli/project.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def migrate_project(
228228
None,
229229
help="Optional MongoDB connection URI. Falls back to $MONGODB_URI if not provided.",
230230
),
231+
database: str = typer.Option(
232+
None,
233+
help="Specify the database to migrate.",
234+
),
231235
):
232236
"""
233237
Run Django migrations using django-admin instead of manage.py.
@@ -238,7 +242,8 @@ def migrate_project(
238242
cmd.append(app_label)
239243
if migration_name:
240244
cmd.append(migration_name)
241-
245+
if database:
246+
cmd.append(f"--database={database}")
242247
typer.echo(f"📦 Applying migrations for project '{name}'")
243248
_django_manage_command(
244249
name, directory, *cmd, extra_env=_build_mongodb_env(mongodb_uri)
@@ -277,6 +282,10 @@ def manage_command(
277282
mongodb_uri: str = typer.Option(
278283
None, "--mongodb-uri", help="MongoDB connection URI"
279284
),
285+
database: str = typer.Option(
286+
None,
287+
help="Specify the database to use.",
288+
),
280289
):
281290
"""
282291
Run any django-admin command for a project.
@@ -297,6 +306,9 @@ def manage_command(
297306

298307
os.environ["MONGODB_URI"] = mongodb_uri
299308

309+
if database:
310+
args.append(f"--database={database}")
311+
300312
if command:
301313
typer.echo(f"⚙️ Running django-admin {command} {' '.join(args)} for '{name}'")
302314
_django_manage_command(name, directory, command, *args)

django_mongodb_cli/repo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def do_delete(name):
263263

264264
@repo.command()
265265
def diff(
266+
ctx: typer.Context,
266267
repo_name: str = typer.Argument(None),
267268
all_repos: bool = typer.Option(
268269
False, "--all-repos", "-a", help="Show diffs of all repositories"
@@ -272,13 +273,15 @@ def diff(
272273
Show the git diff for the specified repository.
273274
If --all-repos is used, show diffs for all repositories.
274275
"""
276+
repo = Repo()
277+
repo.ctx = ctx
275278
repo_command(
276279
all_repos,
277280
repo_name,
278281
all_msg="Showing diffs for all repositories...",
279282
missing_msg="Please specify a repository name or use -a,--all-repos to show diffs of all repositories.",
280-
single_func=lambda repo_name: Repo().get_repo_diff(repo_name),
281-
all_func=lambda repo_name: Repo().get_repo_diff(repo_name),
283+
single_func=lambda repo_name: repo.get_repo_diff(repo_name),
284+
all_func=lambda repo_name: repo.get_repo_diff(repo_name),
282285
)
283286

284287

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
from django_mongodb_backend.utils import model_has_encrypted_fields
2+
3+
14
class EncryptedRouter:
2-
def db_for_read(self, model, **hints):
3-
if model._meta.app_label == "django_mongodb_demo":
4-
return "encrypted"
5+
def allow_migrate(self, db, app_label, model_name=None, **hints):
6+
if hints.get("model"):
7+
if model_has_encrypted_fields(hints["model"]):
8+
return db == "encrypted"
9+
else:
10+
return db == "default"
511
return None
612

7-
db_for_write = db_for_read
13+
def db_for_read(self, model, **hints):
14+
if model_has_encrypted_fields(model):
15+
return "encrypted"
16+
return "default"
817

9-
def allow_migrate(self, db, app_label, model_name=None, **hints):
10-
if app_label == "django_mongodb_demo":
11-
print("allow_migrate for django_mongodb_demo:", db)
12-
return db == "encrypted"
13-
# Don't create other app's models in the encrypted database.
14-
if db == "encrypted":
15-
return False
18+
def kms_provider(self, model):
19+
if model_has_encrypted_fields(model):
20+
return "local"
1621
return None
1722

18-
def kms_provider(self, model, **hints):
19-
return "local"
23+
db_for_write = db_for_read

django_mongodb_cli/templates/project_template/project_name/settings/project_name.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
"NAME": "{{ project_name }}_encrypted",
1717
"OPTIONS": {
1818
"auto_encryption_opts": AutoEncryptionOpts(
19-
kms_providers={"local": {"key": os.urandom(96)}}, # noqa
20-
key_vault_namespace="keyvault.__keyVault",
19+
kms_providers={
20+
"local": {
21+
"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"
22+
}
23+
},
24+
key_vault_namespace="{{ project_name }}_encrypted.__keyVault",
2125
),
2226
},
2327
}

django_mongodb_cli/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,11 @@ def get_repo_diff(self, repo_name: str) -> None:
418418
Get the diff of a repository.
419419
"""
420420

421-
self.get_repo_status(repo_name)
422-
423421
path, repo = self.ensure_repo(repo_name)
424422
if not repo or not path:
425423
return
426424

425+
self.title(f"{repo_name}:")
427426
unstaged = repo.index.diff(None)
428427
if unstaged:
429428
self.warn("\nChanges not staged for commit:")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ repos = [
8686
"mongo @ git+ssh://[email protected]/mongodb/mongo@master",
8787
"drivers-evergreen-tools @ git+ssh://[email protected]/mongodb-labs/drivers-evergreen-tools@master",
8888
"docs @ git+ssh://[email protected]/mongodb/docs@main",
89+
"docs-sample-apps @ git+ssh://[email protected]/mongodb/docs-sample-apps@main",
8990
"flask-pymongo @ git+ssh://[email protected]/mongodb-labs/flask-pymongo",
9091
"mongo-arrow @ git+ssh://[email protected]/mongodb-labs/mongo-arrow@main",
9192
"mongo-orchestration @ git+ssh://[email protected]/mongodb-labs/mongo-orchestration@master",

templates/app_template/.github/workflows/django.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

templates/app_template/__init__.py-tpl

Whitespace-only changes.

templates/app_template/admin.py-tpl

Lines changed: 0 additions & 3 deletions
This file was deleted.

templates/app_template/apps.py-tpl

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)