🐛 migration to fix duplicate files
This commit is contained in:
parent
62fd17eeb0
commit
41c009ab04
2 changed files with 37 additions and 0 deletions
|
|
@ -2,6 +2,8 @@ import asyncio
|
|||
import time
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Awaitable, Callable, List, Optional
|
||||
|
||||
from ..libs.util.paths import migration
|
||||
from ..server.protocols.ide_protocol import AbstractIdeProtocolServer
|
||||
|
||||
from meilisearch_python_async import Client
|
||||
|
|
@ -337,6 +339,12 @@ class ContextManager:
|
|||
async with Client(get_meilisearch_url()) as search_client:
|
||||
# First, create the index if it doesn't exist
|
||||
# The index is currently shared by all workspaces
|
||||
|
||||
# Check if need to migrate to new id format
|
||||
# If so, delete the index before recreating
|
||||
async with migration("meilisearch_context_items_001"):
|
||||
await search_client.delete_index_if_exists(SEARCH_INDEX_NAME)
|
||||
|
||||
await search_client.create_index(SEARCH_INDEX_NAME)
|
||||
globalSearchIndex = await search_client.get_index(SEARCH_INDEX_NAME)
|
||||
await globalSearchIndex.update_ranking_rules(
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from ..constants.main import (
|
|||
CONTINUE_SERVER_FOLDER,
|
||||
CONTINUE_SESSIONS_FOLDER,
|
||||
)
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
|
||||
def find_data_file(filename):
|
||||
|
|
@ -21,6 +22,34 @@ def getGlobalFolderPath():
|
|||
return path
|
||||
|
||||
|
||||
def getMigrationsPath():
|
||||
path = os.path.join(getGlobalFolderPath(), ".migrations")
|
||||
os.makedirs(path, exist_ok=True)
|
||||
return path
|
||||
|
||||
|
||||
def hasMigrated(migration_id: str) -> bool:
|
||||
path = os.path.join(getMigrationsPath(), migration_id)
|
||||
return os.path.exists(path)
|
||||
|
||||
|
||||
def markMigrated(migration_id: str):
|
||||
path = os.path.join(getMigrationsPath(), migration_id)
|
||||
with open(path, "w") as f:
|
||||
f.write("")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def migration(migration_id: str):
|
||||
has_migrated = hasMigrated(migration_id)
|
||||
if has_migrated:
|
||||
return
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
markMigrated(migration_id)
|
||||
|
||||
|
||||
def getSessionsFolderPath():
|
||||
path = os.path.join(getGlobalFolderPath(), CONTINUE_SESSIONS_FOLDER)
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue