Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ config.ini
mergin
.coverage
htmlcov
.vscode
.env
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ To run automatic tests:
export TEST_MERGIN_URL=<url> # testing server
export TEST_API_USERNAME=<username>
export TEST_API_PASSWORD=<pwd>
export TEST_API_WORKSPACE=<workspace>
pytest-3 test/


Expand Down
10 changes: 10 additions & 0 deletions dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import tempfile
import random
import uuid
import re

import psycopg2
from itertools import chain
Expand All @@ -34,6 +35,14 @@ class DbSyncError(Exception):
pass


def _add_quotes_to_schema_name(schema: str) -> str:
matches = re.findall(r"[^a-z0-9_]", schema)
if len(matches) != 0:
schema = schema.replace("\"", "\"\"")
schema = f'"{schema}"'
return schema


def _tables_list_to_string(tables):
return ";".join(tables)

Expand Down Expand Up @@ -230,6 +239,7 @@ def _set_db_project_comment(conn, schema, project_name, version, project_id=None
def _get_db_project_comment(conn, schema):
""" Get Mergin Maps project name and its current version in db schema"""
cur = conn.cursor()
schema = _add_quotes_to_schema_name(schema)
cur.execute("SELECT obj_description(%s::regnamespace, 'pg_namespace')", (schema, ))
res = cur.fetchone()[0]
try:
Expand Down
Loading