Skip to content

Commit

Permalink
Formatting pass
Browse files Browse the repository at this point in the history
# Conflicts:
#	models/models/analysis.py
  • Loading branch information
illusional committed Jun 26, 2023
1 parent 86fc7ad commit 8754c40
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
69 changes: 37 additions & 32 deletions db/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -697,40 +697,45 @@
</changeSet>
<changeSet author="michael.franklin" id="2022-10-18_first-class-files">
<sql>SET @@system_versioning_alter_history = 1;</sql>
<createTable tableName="file">
<createTable tableName="file">
<!-- Maybe should consider "in-progress" flag to shos that it's expecting an output to exist -->
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="type" type="ENUM('file', 'directory')" />
<column name="path" type="TEXT">
<constraints unique="true" nullable="false" />
</column>
<column name="size" type="INT" />
<column name="checksum" type="TEXT" />

</createTable>
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="type" type="ENUM('file', 'directory')" />
<column name="path" type="TEXT">
<constraints unique="true" nullable="false" />
</column>
<column name="size" type="INT" />
<column name="checksum" type="TEXT" />
<column name="exists" type="BIT" />

</createTable>

<!-- attach files to analysis-->
<createTable tableName="analysis_files">
<column name="analysis_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_analysis_files_analysis" references="analysis(id)" />
</column>
<column name="file_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_analysis_files_file" references="file(id)" />
</column>
<column name="pattern" type="TEXT"/>
</createTable>

<!-- attach files to analysis-->
<createTable tableName="sequence_files">
<column name="sequence_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_analysis_files_analysis" references="sample_sequencing(id)" />
</column>
<column name="file_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_analysis_files_file" references="file(id)" />
</column>
<column name="pattern" type="TEXT"/>
</createTable>
<createTable tableName="analysis_outputs">
<column name="analysis_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_analysis_outputs_analysis" references="analysis(id)" />
</column>
<column name="value" type="TEXT">
<constraints nullable="true" />
</column>
<column name="file_id" type="INT">
<constraints nullable="true" foreignKeyName="fk_analysis_outputs_file" references="file(id)" />
</column>
<column name="pattern" type="TEXT"/>

</createTable>

<!-- attach files to analysis-->
<createTable tableName="sequence_files">
<column name="sequence_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_sequence_files_sequence" references="sample_sequencing(id)" />
</column>
<column name="file_id" type="INT">
<constraints nullable="false" foreignKeyName="fk_sequence_files_file" references="file(id)" />
</column>
<column name="pattern" type="TEXT"/>
</createTable>
</changeSet>
</databaseChangeLog>
2 changes: 2 additions & 0 deletions db/python/tables/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AnalysisFilter(GenericFilterModel):
status: GenericFilter[AnalysisStatus] = None
meta: GenericMetaFilter = None
output: GenericFilter[str] = None
outputs: GenericMetaFilter = None
active: GenericFilter[bool] = None

def __hash__(self): # pylint: disable=useless-parent-delegation
Expand Down Expand Up @@ -58,6 +59,7 @@ async def create_analysis(
sequencing_group_ids: List[int],
meta: Optional[Dict[str, Any]] = None,
output: str = None,
outputs: dict[str, Any] = None,
active: bool = True,
author: str = None,
project: ProjectId = None,
Expand Down
2 changes: 1 addition & 1 deletion db/python/tables/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ async def create_files(self, files: list[File]):
"""
pass

# endregion CREATE
# endregion CREATE
1 change: 1 addition & 0 deletions models/models/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AnalysisInternal(SMBase):
type: str
status: AnalysisStatus
output: str = None
outputs: dict[str, Any] = None
sequencing_group_ids: list[int] = []
timestamp_completed: str | None = None
project: int | None = None
Expand Down
4 changes: 3 additions & 1 deletion models/models/file.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from enum import Enum
from typing import Optional

from pydantic import BaseModel


class FileType(Enum):
"""Type of File that we record"""
FILE = 'file'
DIRECTORY = 'directory'

Expand All @@ -17,3 +18,4 @@ class File(BaseModel):
# in bytes
size: int
checksum: str | None
exists: bool
12 changes: 5 additions & 7 deletions scripts/migrate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ async def migrate_analysis():
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=)

mapped_files[r['output']].append(r['id'])

# inserted_files = insert_files(list(mapped_files.keys()))
#
# for f in inserted_files:
# File(path=)

0 comments on commit 8754c40

Please sign in to comment.