Skip to content

Commit 0d5d70f

Browse files
committed
UPDATED management command
1 parent 74bc1bb commit 0d5d70f

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
32
from django.core.management.base import BaseCommand
43
from src.DatabaseConnections.models import ConnectionInfo
54

@@ -11,25 +10,30 @@ class Command(BaseCommand):
1110
help = "Create connection for erp-service."
1211

1312
def handle(self, *args, **options):
14-
connection, created = ConnectionInfo.objects.get_or_create(
15-
erp_system="5s_control",
16-
defaults={
17-
"type": "api",
18-
"dbms": "postgres",
19-
"is_active": True,
20-
"host": "http://erp-service",
21-
"server": None,
22-
"database": None,
23-
"username": "admin",
24-
"password": "admin",
25-
"port": 3005,
26-
"used_in_orders_view": True,
27-
},
28-
)
13+
try:
14+
connection, created = ConnectionInfo.objects.get_or_create(
15+
erp_system="5s_control",
16+
defaults={
17+
"type": "api",
18+
"dbms": "postgres",
19+
"is_active": True,
20+
"host": "http://erp-service",
21+
"server": None,
22+
"database": None,
23+
"username": "admin",
24+
"password": "admin",
25+
"port": 3005,
26+
"used_in_orders_view": True,
27+
},
28+
)
29+
30+
if created:
31+
logger.info("Connection created successfully.")
32+
self.stdout.write(self.style.SUCCESS("✅ Connection created successfully."))
33+
else:
34+
logger.info("Connection already exists.")
35+
self.stdout.write(self.style.SUCCESS("ℹ️ Connection already exists."))
2936

30-
if created:
31-
logger.info("Connection created successfully.")
32-
self.stdout.write(self.style.SUCCESS("✅ Connection created successfully."))
33-
else:
34-
logger.info("Connection already exists.")
35-
self.stdout.write(self.style.SUCCESS("ℹ️ Connection already exists."))
37+
except Exception as e:
38+
logger.error(f"Error creating connection: {e}")
39+
self.stdout.write(self.style.ERROR(f"❌ Error creating connection: {e}"))

0 commit comments

Comments
 (0)