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
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 @@ -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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ repos = [
"mongo @ git+ssh://git@github.com/mongodb/mongo@master",
"drivers-evergreen-tools @ git+ssh://git@github.com/mongodb-labs/drivers-evergreen-tools@master",
"docs @ git+ssh://git@github.com/mongodb/docs@main",
"docs-sample-apps @ git+ssh://git@github.com/mongodb/docs-sample-apps@main",
"flask-pymongo @ git+ssh://git@github.com/mongodb-labs/flask-pymongo",
"mongo-arrow @ git+ssh://git@github.com/mongodb-labs/mongo-arrow@main",
"mongo-orchestration @ git+ssh://git@github.com/mongodb-labs/mongo-orchestration@master",
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.

552 changes: 0 additions & 552 deletions templates/app_template/templates/app_name.html

This file was deleted.

3 changes: 0 additions & 3 deletions templates/app_template/tests.py-tpl

This file was deleted.

7 changes: 0 additions & 7 deletions templates/app_template/urls.py

This file was deleted.

7 changes: 0 additions & 7 deletions templates/app_template/views.py-tpl

This file was deleted.

15 changes: 0 additions & 15 deletions templates/frontend_template/project_name/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions templates/frontend_template/project_name/README.md

This file was deleted.

Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
71 changes: 0 additions & 71 deletions templates/frontend_template/project_name/webpack/webpack.common.js

This file was deleted.

This file was deleted.

This file was deleted.

Loading