Skip to content

Commit

Permalink
wipe database on program upgrade
Browse files Browse the repository at this point in the history
slatinsky committed Jun 1, 2023
1 parent 2449c57 commit 246f590
Showing 5 changed files with 32 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
@@ -105,7 +105,6 @@ jobs:
cp backend\http-server\http-server.exe build\dcef\backend\http-server\http-server.exe
cp backend\windows-runner\dist\dcef.exe build\dcef.exe
Copy-Item -Path release\exports\* -Destination build\exports -Recurse
cp release\clear_database.bat build\clear_database.bat
cp release\registry_tweaks\change_260_character_path_limit_to_32767.reg build\registry_tweaks\change_260_character_path_limit_to_32767.reg
cp release\registry_tweaks\restore_260_character_path_limit.reg build\registry_tweaks\restore_260_character_path_limit.reg
cp release\registry_tweaks\README.txt build\registry_tweaks\README.txt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ node_modules
.vercel
.output
__pycache__
.vscode


# releases (built files)
5 changes: 4 additions & 1 deletion backend/preprocess/MongoDatabase.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@ def __init__(self):
"emojis": self.database["emojis"],
"jsons": self.database["jsons"],
"assets": self.database["assets"],
"jsons": self.database["jsons"]
"jsons": self.database["jsons"],
"config": self.database["config"],
}

self.create_indexes()
@@ -41,6 +42,8 @@ def clear_database_except_assets(self):
for collection_name in self.col:
if collection_name == "assets": # assets are expensive to recompute
continue
if collection_name == "config":
continue
self.col[collection_name].delete_many({})

def clear_assets(self):
27 changes: 27 additions & 0 deletions backend/preprocess/main_mongo.py
Original file line number Diff line number Diff line change
@@ -18,11 +18,38 @@
print = functools.partial(print, flush=True)


def wipe_database(database):
"""
Deletes all collections on version bump (on program update)
Change EXPECTED_VERSION to force wipe on incompatible schema changes
"""
EXPECTED_VERSION = 1 # <---- change this to wipe database
config = database.get_collection("config")

version = config.find_one({"key": "version"})
if version is None:
version = {"key": "version", "value": 0}
config.insert_one(version)

if version["value"] == EXPECTED_VERSION:
print("Database schema up to date, no wipe needed")
return

print("Wiping database...")
database.clear_database_except_assets()
database.clear_assets()
print("Done wiping database")

version["value"] = EXPECTED_VERSION
config.update_one({"key": "version"}, {"$set": version})


def main(input_dir, output_dir):
print("main_mongo loaded")

database = MongoDatabase()
wipe_database(database)

# DEBUG clear database
# database.clear_database_except_assets()
# database.clear_assets()
2 changes: 0 additions & 2 deletions release/clear_database.bat

This file was deleted.

0 comments on commit 246f590

Please sign in to comment.