- Trying to solve database initialisation problem (no tables in tenant schema).

This commit is contained in:
Josako
2025-09-05 11:11:08 +02:00
parent 6115cc7e13
commit a6edd5c663
7 changed files with 32 additions and 13 deletions

View File

@@ -46,7 +46,10 @@ class Database:
def create_tables(self):
"""create tables in for schema"""
db.metadata.create_all(self.get_engine())
try:
db.metadata.create_all(self.get_engine())
except SQLAlchemyError as e:
current_app.logger.error(f"💔 Error creating tables for schema {self.schema}: {e.args}")
def switch_schema(self):
"""switch between tenant/public database schema"""

View File

@@ -608,6 +608,15 @@ Let op: apply alleen triggert niet altijd een rollout als er geen inhoudelijke s
kubectl -n eveai-staging logs deploy/eveai-api --tail=200
```
### Phase 10: Cockpit Setup
#### Standard Cockpit Setup
- Create a grafana user (Cockpit > Grafana Users > Add user)
- Open Grafana Dashboard (Cockpit > Open Dashboards)
- Er zijn heel wat dashboards beschikbaar.
- Kubernetes cluster overview (metrics)
- Kubernetes cluster logs (controlplane logs)
## Verification and Testing

View File

@@ -7,7 +7,10 @@ import logging.config
from common.extensions import db, migrate
from config.logging_config import configure_logging
from config.config import get_config
import common.models.user
import common.models.interaction
import common.models.entitlements
import common.models.document
def create_app(config_file=None):
app = Flask(__name__, static_url_path='/static')

View File

@@ -25,7 +25,7 @@ fi
# Set FLASK_APP environment variable
PROJECT_DIR="/app"
export FLASK_APP=${PROJECT_DIR}/scripts/run_eveai_app.py # Adjust the path to your Flask app entry point
export FLASK_APP=${PROJECT_DIR}/scripts/run.py # Adjust the path to your Flask app entry point
export PYTHONPATH="$PYTHONPATH:$PROJECT_DIR" # Include the app directory in the Python path
# Run the Flask migration command

View File

@@ -15,7 +15,7 @@ cd "$project_dir" || exit 1
source .env
# Set Flask app and Python path
export FLASK_APP=scripts/run_eveai_app.py
export FLASK_APP=scripts/run.py
export PYTHONPATH="$PYTHONPATH:$project_dir"
while getopts m:d: flag

View File

@@ -15,7 +15,7 @@ cd "$project_dir" || exit 1
source .env
# Set Flask app and Python path
export FLASK_APP=scripts/run_eveai_app.py
export FLASK_APP=scripts/run.py
export PYTHONPATH="$PYTHONPATH:$project_dir"
while getopts m: flag

View File

@@ -21,7 +21,7 @@ def initialize_data():
- Default tenant (ID 1)
- Admin user (ID 1)
"""
print("Starting data initialization...")
print("💜 Starting data initialization...")
app = create_app()
@@ -36,12 +36,12 @@ def initialize_data():
# Step 3: Initialize admin user
admin_user = initialize_admin_user(default_tenant)
print("Data initialization completed successfully")
print("💜 Data initialization completed successfully")
def initialize_roles():
"""Initialize system roles with IDs below 1000"""
print("Initializing system roles...")
print("🧡 Initializing system roles...")
# Define system roles - matching the exact IDs and names you specified
roles_data = [
@@ -69,12 +69,14 @@ def initialize_roles():
db.session.execute(text("ALTER SEQUENCE public.role_id_seq RESTART WITH 1000"))
db.session.commit()
print("🧡 Finished initializing system roles.")
return roles
def initialize_default_tenant():
"""Initialize the default system tenant with ID 1"""
print("Initializing default tenant...")
print("🧡 Initializing default tenant...")
tenant_data = {
'id': 1,
@@ -90,20 +92,22 @@ def initialize_default_tenant():
tenant = db.session.get(Tenant, tenant_data['id'])
if not tenant:
print(f"Creating default tenant: {tenant_data['name']} (ID: {tenant_data['id']})")
print(f"💛 Creating default tenant: {tenant_data['name']} (ID: {tenant_data['id']})")
tenant = Tenant(**tenant_data)
db.session.add(tenant)
db.session.commit()
# Create tenant schema
print(f"Creating schema for tenant {tenant.id}")
print(f"💛 Creating schema for tenant {tenant.id}")
Database(tenant.id).create_tenant_schema()
# Create MinIO bucket
print(f"Creating MinIO bucket for tenant {tenant.id}")
print(f"💛 Creating MinIO bucket for tenant {tenant.id}")
minio_client.create_tenant_bucket(tenant.id)
else:
print(f"Default tenant already exists: {tenant.name} (ID: {tenant.id})")
print(f"🧡 Default tenant already exists: {tenant.name} (ID: {tenant.id})")
print(f"🧡 Finished initializing default tenant.")
return tenant