-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BROKEN: Add initial first-class-files attempt
# Conflicts: # db/project.xml
- Loading branch information
1 parent
3c902cd
commit 86fc7ad
Showing
4 changed files
with
131 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from db.python.connect import DbBase | ||
from models.models.file import File | ||
|
||
|
||
class FileTable(DbBase): | ||
""" | ||
Capture File table operations and queries | ||
""" | ||
|
||
table_name = 'file' | ||
|
||
async def get_file_by_id(self, file_id: int) -> File: | ||
pass | ||
|
||
async def get_files_by_ids(self, file_ids: list[int]) -> list[File]: | ||
pass | ||
|
||
async def get_file_by_path(self, path: str) -> File: | ||
pass | ||
|
||
async def get_files_by_paths(self, paths: list[str]) -> list[File]: | ||
pass | ||
|
||
# region CREATE | ||
|
||
async def create_files(self, files: list[File]): | ||
""" | ||
Can insert and get by paths, will need to consider what | ||
should happen if files exist, eg should it: | ||
- Archive all old analysis / sequences at this location | ||
+ notify user of this | ||
- Fail, and make this a precondition | ||
""" | ||
pass | ||
|
||
# endregion CREATE |
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,19 @@ | ||
from enum import Enum | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
class FileType(Enum): | ||
FILE = 'file' | ||
DIRECTORY = 'directory' | ||
|
||
|
||
class File(BaseModel): | ||
"""Model to represent File""" | ||
|
||
id: int | ||
type: FileType | ||
path: str | ||
# in bytes | ||
size: int | ||
checksum: str | None |
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,36 @@ | ||
""" | ||
We need to apply this migration in three steps: | ||
- Add schema for files | ||
- migrate all the data to new schema | ||
- Remove old columns | ||
+ MariaDB will probably complain about deleting columns in archived data | ||
This is also the time we should consider archiving analysis with duplicate output | ||
paths, and also | ||
""" | ||
from collections import defaultdict | ||
|
||
from models.models.file import File | ||
|
||
connection = None | ||
|
||
|
||
def main(): | ||
pass | ||
|
||
|
||
async def migrate_analysis(): | ||
# collect all analysis-entries that are gs:// files | ||
get_query = 'SELECT * FROM analysis WHERE output LIKE "gs://%"' | ||
rows = await connection.fetch_all(get_query) | ||
mapped_files = defaultdict(list) | ||
for r in rows: | ||
\mapped_files[r['output']].append(r['id']) | ||
|
||
inserted_files = insert_files(list(mapped_files.keys())) | ||
|
||
for f in inserted_files: | ||
File(path=) | ||
|
||
|