mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
feat(db): improve database initialization and migration handling
- Add smarter database state detection during initialization to handle new databases, existing databases with new features, and old databases needing migration - Make migration for llm_model_configs table idempotent to prevent conflicts when table already exists from code - Add detailed logging for different database initialization scenarios - Import sqlalchemy module for database inspection capabilities
This commit is contained in:
1 parent
bbd34f1f67
commit
8fad27d904
2 files changed
+54
-2
No files matched your search
@@ -8,6 +8,7 @@ Create Date: 2026-03-03
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy import inspect
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '20260303_create_llm_model_configs'
|
||||
@@ -17,6 +18,17 @@ depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Get the current connection
|
||||
conn = op.get_bind()
|
||||
inspector = inspect(conn)
|
||||
|
||||
# Check if table already exists (idempotent for databases created from code)
|
||||
tables = inspector.get_table_names()
|
||||
|
||||
if 'llm_model_configs' in tables:
|
||||
# Table already exists from Base.metadata.create_all, skip creation
|
||||
return
|
||||
|
||||
# Create llm_model_configs table
|
||||
op.create_table(
|
||||
'llm_model_configs',
|
||||
|
||||
Reference in new issue
Block a user