-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ingest_gis configable, update db mock, refactor sql tool
Ingest GIS Configurable - This is just so I can disable GIS for instance 4 Update DB Mock & DbService Interface - Looks like I forgot to add copy & abort to the db instance type - I actually moved ConnectionLike::info out of the interface and added a method to DatabaseService to do that logic without exposing psycopgs API to the user of the service Refactor SQL Tool - I moved reading files logic to a new class called FileDiscovery - This stuff was moved out SchemaReader - Added a comment for the stuff unsafe stuff, I feel like maybe I should lift this out or something? idk. - I deleted a test, but the truth is I just moved it to a new name but I am not ready to commit the contents
- Loading branch information
Showing
11 changed files
with
131 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from dataclasses import dataclass | ||
from logging import getLogger | ||
import re | ||
from typing import cast, Self, Optional | ||
|
||
from lib.service.io import IoService | ||
|
||
from .config import schema_ns | ||
from .type import SchemaNamespace | ||
|
||
def create_file_regex(root_dir: str) -> re.Pattern: | ||
path_root = re.escape(root_dir) | ||
path_ns = r'(?P<ns>[_a-zA-Z][_a-zA-Z0-9]*)' | ||
path_file = r'(?P<step>\d{3})_APPLY(_(?P<name>[_a-zA-Z][_a-zA-Z0-9]*))?.sql' | ||
return re.compile(rf'^{path_root}/{path_ns}/schema/{path_file}$') | ||
|
||
@dataclass | ||
class FileDiscoveryMatch: | ||
ns: SchemaNamespace | ||
step: int | ||
name: str | ||
|
||
|
||
class FileDiscovery: | ||
logger = getLogger(__name__) | ||
|
||
def __init__(self: Self, io: IoService, file_regex: re.Pattern, root_dir: str): | ||
self._io = io | ||
self.file_regex = file_regex | ||
self.root_dir = root_dir | ||
|
||
async def ns_matches(self: Self, ns: SchemaNamespace) -> list[tuple[str, FileDiscoveryMatch]]: | ||
return [(f, self.match_file(f)) for f in await self.ns_sql_files(ns)] | ||
|
||
async def ns_sql_files(self: Self, ns: SchemaNamespace) -> list[str]: | ||
glob_s = '*_APPLY*.sql' | ||
root_d = f'{self.root_dir}/{ns}/schema' | ||
return [f async for f in self._io.grep_dir(root_d, glob_s)] | ||
|
||
def match_file(self: Self, file: str) -> FileDiscoveryMatch: | ||
match self.file_regex.match(file): | ||
case None: | ||
raise ValueError(f'invalid file {file}') | ||
case match: | ||
ns_str = match.group('ns') | ||
step = int(match.group('step')) | ||
name = match.group('name') | ||
if ns_str not in schema_ns: | ||
raise TypeError(f'unknown namespace {ns_str}') | ||
ns: SchemaNamespace = cast(SchemaNamespace, ns_str) | ||
return FileDiscoveryMatch(ns, step, name) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.