fix(prestart): add owner_id to plugin tables after migrations
This commit is contained in:
+44
@@ -100,6 +100,50 @@ asyncio.run(set_password())
|
||||
"
|
||||
fi
|
||||
|
||||
echo "[prestart] Adding owner_id to plugin tables if missing..."
|
||||
python3 -c "
|
||||
import asyncio, os, re
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy import text
|
||||
|
||||
async def fix_owner_id():
|
||||
db_url = os.environ.get('MIGRATION_DATABASE_URL', os.environ.get('DATABASE_URL', ''))
|
||||
if not db_url:
|
||||
print('[prestart] WARNING: No DB URL for owner_id fix')
|
||||
return
|
||||
engine = create_async_engine(db_url)
|
||||
# Tables that should have owner_id (from core migration 0054)
|
||||
tables = ['files', 'folders', 'calendar_entries', 'calendars', 'tasks', 'subtasks']
|
||||
try:
|
||||
async with engine.begin() as conn:
|
||||
for table in tables:
|
||||
# Check if table exists
|
||||
exists = await conn.execute(text(
|
||||
\"SELECT 1 FROM information_schema.tables WHERE table_name = :t\"
|
||||
), {\"t\": table})
|
||||
if exists.fetchone() is None:
|
||||
continue
|
||||
# Check if owner_id column exists
|
||||
has_col = await conn.execute(text(
|
||||
\"SELECT 1 FROM information_schema.columns WHERE table_name = :t AND column_name = 'owner_id'\"
|
||||
), {\"t\": table})
|
||||
if has_col.fetchone() is None:
|
||||
await conn.execute(text(
|
||||
f\"ALTER TABLE {table} ADD COLUMN IF NOT EXISTS owner_id UUID REFERENCES users(id) ON DELETE SET NULL\"
|
||||
))
|
||||
await conn.execute(text(
|
||||
f\"CREATE INDEX IF NOT EXISTS ix_{table}_owner ON {table} (owner_id)\"
|
||||
))
|
||||
print(f'[prestart] Added owner_id to {table}')
|
||||
print('[prestart] owner_id fix completed.')
|
||||
except Exception as e:
|
||||
print(f'[prestart] WARNING: owner_id fix failed: {e}')
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
asyncio.run(fix_owner_id())
|
||||
"
|
||||
|
||||
echo "[prestart] Seeding admin user if not exists..."
|
||||
python3 /app/scripts/seed_admin.py || echo "[prestart] WARNING: Admin seed failed (may already exist)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user