- Trying to solve database initialisation problem (no tables in tenant schema).
This commit is contained in:
@@ -46,7 +46,10 @@ class Database:
|
|||||||
|
|
||||||
def create_tables(self):
|
def create_tables(self):
|
||||||
"""create tables in for schema"""
|
"""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):
|
def switch_schema(self):
|
||||||
"""switch between tenant/public database schema"""
|
"""switch between tenant/public database schema"""
|
||||||
|
|||||||
@@ -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
|
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
|
## Verification and Testing
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import logging.config
|
|||||||
from common.extensions import db, migrate
|
from common.extensions import db, migrate
|
||||||
from config.logging_config import configure_logging
|
from config.logging_config import configure_logging
|
||||||
from config.config import get_config
|
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):
|
def create_app(config_file=None):
|
||||||
app = Flask(__name__, static_url_path='/static')
|
app = Flask(__name__, static_url_path='/static')
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ fi
|
|||||||
|
|
||||||
# Set FLASK_APP environment variable
|
# Set FLASK_APP environment variable
|
||||||
PROJECT_DIR="/app"
|
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
|
export PYTHONPATH="$PYTHONPATH:$PROJECT_DIR" # Include the app directory in the Python path
|
||||||
|
|
||||||
# Run the Flask migration command
|
# Run the Flask migration command
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ cd "$project_dir" || exit 1
|
|||||||
source .env
|
source .env
|
||||||
|
|
||||||
# Set Flask app and Python path
|
# 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"
|
export PYTHONPATH="$PYTHONPATH:$project_dir"
|
||||||
|
|
||||||
while getopts m:d: flag
|
while getopts m:d: flag
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ cd "$project_dir" || exit 1
|
|||||||
source .env
|
source .env
|
||||||
|
|
||||||
# Set Flask app and Python path
|
# 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"
|
export PYTHONPATH="$PYTHONPATH:$project_dir"
|
||||||
|
|
||||||
while getopts m: flag
|
while getopts m: flag
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def initialize_data():
|
|||||||
- Default tenant (ID 1)
|
- Default tenant (ID 1)
|
||||||
- Admin user (ID 1)
|
- Admin user (ID 1)
|
||||||
"""
|
"""
|
||||||
print("Starting data initialization...")
|
print("💜 Starting data initialization...")
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
@@ -36,12 +36,12 @@ def initialize_data():
|
|||||||
# Step 3: Initialize admin user
|
# Step 3: Initialize admin user
|
||||||
admin_user = initialize_admin_user(default_tenant)
|
admin_user = initialize_admin_user(default_tenant)
|
||||||
|
|
||||||
print("Data initialization completed successfully")
|
print("💜 Data initialization completed successfully")
|
||||||
|
|
||||||
|
|
||||||
def initialize_roles():
|
def initialize_roles():
|
||||||
"""Initialize system roles with IDs below 1000"""
|
"""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
|
# Define system roles - matching the exact IDs and names you specified
|
||||||
roles_data = [
|
roles_data = [
|
||||||
@@ -69,12 +69,14 @@ def initialize_roles():
|
|||||||
db.session.execute(text("ALTER SEQUENCE public.role_id_seq RESTART WITH 1000"))
|
db.session.execute(text("ALTER SEQUENCE public.role_id_seq RESTART WITH 1000"))
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
print("🧡 Finished initializing system roles.")
|
||||||
|
|
||||||
return roles
|
return roles
|
||||||
|
|
||||||
|
|
||||||
def initialize_default_tenant():
|
def initialize_default_tenant():
|
||||||
"""Initialize the default system tenant with ID 1"""
|
"""Initialize the default system tenant with ID 1"""
|
||||||
print("Initializing default tenant...")
|
print("🧡 Initializing default tenant...")
|
||||||
|
|
||||||
tenant_data = {
|
tenant_data = {
|
||||||
'id': 1,
|
'id': 1,
|
||||||
@@ -90,20 +92,22 @@ def initialize_default_tenant():
|
|||||||
tenant = db.session.get(Tenant, tenant_data['id'])
|
tenant = db.session.get(Tenant, tenant_data['id'])
|
||||||
|
|
||||||
if not tenant:
|
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)
|
tenant = Tenant(**tenant_data)
|
||||||
db.session.add(tenant)
|
db.session.add(tenant)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Create tenant schema
|
# 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()
|
Database(tenant.id).create_tenant_schema()
|
||||||
|
|
||||||
# Create MinIO bucket
|
# 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)
|
minio_client.create_tenant_bucket(tenant.id)
|
||||||
else:
|
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
|
return tenant
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user