-
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.
Merge pull request #155 from DocShow-AI/dev
Dev
- Loading branch information
Showing
106 changed files
with
2,624 additions
and
1,083 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.8-slim-buster | ||
|
||
# Set the working directory in the container to /app | ||
WORKDIR /app | ||
|
||
# Add the current directory contents into the container at /app | ||
ADD . /app | ||
|
||
# Install Python packages | ||
RUN apt-get update && \ | ||
apt-get install -y gcc libffi-dev && \ | ||
pip install --trusted-host pypi.python.org -r requirements.txt | ||
|
||
# Cleanup | ||
RUN apt-get remove -y gcc libffi-dev && \ | ||
apt-get autoremove -y && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Run alembic migrations when the container launches | ||
CMD ["alembic", "upgrade", "head"] |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[alembic] | ||
# ... other settings ... | ||
sqlalchemy.url = driver://user:pass@localhost/dummy | ||
script_location = alembic |
File renamed without changes.
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,24 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = ${repr(up_revision)} | ||
down_revision = ${repr(down_revision)} | ||
branch_labels = ${repr(branch_labels)} | ||
depends_on = ${repr(depends_on)} | ||
|
||
|
||
def upgrade(): | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade(): | ||
${downgrades if downgrades else "pass"} |
24 changes: 24 additions & 0 deletions
24
backend/alembic/versions/a7364adb18ea_initial_migration.py
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,24 @@ | ||
"""Initial migration | ||
Revision ID: a7364adb18ea | ||
Revises: | ||
Create Date: 2024-01-03 00:00:34.547254 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a7364adb18ea" | ||
down_revision = None | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
pass | ||
|
||
|
||
def downgrade(): | ||
pass |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 34 additions & 34 deletions
68
backend/databases/data_profile_manager.py → backend/database/data_profile_manager.py
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
from models.data_profile import DataProfile, DataProfileCreateRequest | ||
|
||
|
||
class DataProfileManager: | ||
def __init__(self, session): | ||
self.session = session | ||
|
||
def get_dataprofile_by_name(self, name): | ||
"""Retrieve a DataProfile by its name.""" | ||
return self.session.query(DataProfile).filter(DataProfile.name == name).first() | ||
|
||
def get_all_data_profiles(self): | ||
"""Retrieve all DataProfiles.""" | ||
return self.session.query(DataProfile).all() | ||
|
||
def create_dataprofile(self, data_profile_data: DataProfileCreateRequest): | ||
"""Create a new DataProfile.""" | ||
new_data_profile = DataProfile( | ||
name=data_profile_data.name, | ||
file_type=data_profile_data.file_type, # Assuming it's included in the request | ||
organization_id=data_profile_data.organization_id, # Assuming it's included in the request | ||
description=data_profile_data.description, | ||
) | ||
self.session.add(new_data_profile) | ||
self.session.commit() | ||
return new_data_profile.to_dict() | ||
|
||
def get_dataprofile_by_id(self, data_profile_id: int): | ||
"""Retrieve a DataProfile by its ID.""" | ||
return ( | ||
self.session.query(DataProfile) | ||
.filter(DataProfile.id == data_profile_id) | ||
.first() | ||
) | ||
from models.data_profile import DataProfile, DataProfileCreateRequest | ||
|
||
|
||
class DataProfileManager: | ||
def __init__(self, session): | ||
self.session = session | ||
|
||
def get_dataprofile_by_name(self, name): | ||
"""Retrieve a DataProfile by its name.""" | ||
return self.session.query(DataProfile).filter(DataProfile.name == name).first() | ||
|
||
def get_all_data_profiles(self): | ||
"""Retrieve all DataProfiles.""" | ||
return self.session.query(DataProfile).all() | ||
|
||
def create_dataprofile(self, data_profile_data: DataProfileCreateRequest): | ||
"""Create a new DataProfile.""" | ||
new_data_profile = DataProfile( | ||
name=data_profile_data.name, | ||
file_type=data_profile_data.file_type, | ||
organization_id=data_profile_data.organization_id, | ||
description=data_profile_data.description, | ||
) | ||
self.session.add(new_data_profile) | ||
self.session.commit() | ||
return new_data_profile | ||
|
||
def get_dataprofile_by_id(self, data_profile_id: int): | ||
"""Retrieve a DataProfile by its ID.""" | ||
return ( | ||
self.session.query(DataProfile) | ||
.filter(DataProfile.id == data_profile_id) | ||
.first() | ||
) |
4 changes: 2 additions & 2 deletions
4
backend/databases/database_manager.py → backend/database/database_manager.py
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
File renamed without changes.
File renamed without changes.
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,61 @@ | ||
from fastapi import HTTPException | ||
from sqlalchemy.orm import Session | ||
from typing import List | ||
|
||
from models.table_map import TableMap | ||
|
||
|
||
class TableMapManager: | ||
""" | ||
A class to manage CRUD operations related to the TableMap model. | ||
Attributes: | ||
db_session (Session): An active database session for performing operations. | ||
""" | ||
|
||
def __init__(self, session: Session): | ||
""" | ||
Initializes the TableMap with the given database session. | ||
Args: | ||
db_session (Session): The database session to be used for operations. | ||
""" | ||
self.db_session = session | ||
|
||
def create_table_map(self, table_map: TableMap): | ||
""" | ||
Add a new table map to the database. | ||
Args: | ||
table_map (TableMap): The TableMap object to be added. | ||
Returns: | ||
TableMap: The created TableMap object. | ||
""" | ||
try: | ||
if self.db_session: | ||
self.db_session.add(table_map) | ||
self.db_session.commit() | ||
return table_map | ||
except Exception as e: | ||
self.db_session.rollback() if self.db_session else None | ||
print(f"An error occurred: {e}") | ||
raise HTTPException(status_code=400, detail=str(e)) | ||
|
||
def get_org_tables(self, org_id: int) -> List: | ||
"""Returns a list of names of all of the tables associated with an organization.""" | ||
try: | ||
if self.db_session: | ||
table_names = ( | ||
self.db_session.query(TableMap.table_name) | ||
.filter(TableMap.organization_id == org_id) | ||
.all() | ||
) | ||
return [ | ||
name[0] for name in table_names | ||
] # Extracting table_name from each tuple | ||
return [] | ||
except Exception as e: | ||
self.db_session.rollback() if self.db_session else None | ||
print(f"An error occurred: {e}") | ||
raise HTTPException(status_code=400, detail=str(e)) |
File renamed without changes.
Oops, something went wrong.