chore: drop duckdb usage and migrations (#3730)
* chore: drop duckdb usage and migrations * [autofix.ci] apply automated fixes * Add DefaultModel and MessageResponse classes with custom JSON serialization and validation - Introduced `DefaultModel` class with custom JSON encoders and serialization methods. - Added `MessageResponse` class inheriting from `DefaultModel` with fields for message details and custom validators/serializers. - Enhanced file handling and timestamp formatting in `MessageResponse`. * Refactor: Replace `MessageModelResponse` with `MessageResponse` in monitor API - Updated import statements to use `MessageResponse` from `langflow.schema.message`. - Modified `/messages` endpoint to return `list[MessageResponse]` instead of `list[MessageModelResponse]`. - Adjusted response model validation to use `MessageResponse`. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
17cc9bafcd
commit
616c01813e
17 changed files with 77 additions and 751 deletions
|
|
@ -13,15 +13,8 @@ from langflow.graph.utils import log_transaction, log_vertex_build
|
|||
from langflow.initial_setup.setup import load_flows_from_directory, load_starter_projects
|
||||
from langflow.services.database.models.base import orjson_dumps
|
||||
from langflow.services.database.models.flow import Flow, FlowCreate, FlowUpdate
|
||||
from langflow.services.database.models.transactions.crud import get_transactions_by_flow_id
|
||||
from langflow.services.database.utils import migrate_transactions_from_monitor_service_to_database, session_getter
|
||||
from langflow.services.deps import get_db_service, get_monitor_service, session_scope
|
||||
from langflow.services.monitor.schema import TransactionModel
|
||||
from langflow.services.monitor.utils import (
|
||||
add_row_to_table,
|
||||
drop_and_create_table_if_schema_mismatch,
|
||||
new_duckdb_locked_connection,
|
||||
)
|
||||
from langflow.services.database.utils import session_getter
|
||||
from langflow.services.deps import get_db_service
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
|
@ -429,58 +422,6 @@ def test_load_flows(client: TestClient, load_flows_dir):
|
|||
assert response.json()["name"] == "BasicExample"
|
||||
|
||||
|
||||
@pytest.mark.load_flows
|
||||
def test_migrate_transactions(client: TestClient):
|
||||
monitor_service = get_monitor_service()
|
||||
drop_and_create_table_if_schema_mismatch(str(monitor_service.db_path), "transactions", TransactionModel)
|
||||
flow_id = "c54f9130-f2fa-4a3e-b22a-3856d946351b"
|
||||
data = {
|
||||
"vertex_id": "vid",
|
||||
"target_id": "tid",
|
||||
"inputs": {"input_value": True},
|
||||
"outputs": {"output_value": True},
|
||||
"timestamp": "2021-10-10T10:10:10",
|
||||
"status": "success",
|
||||
"error": None,
|
||||
"flow_id": flow_id,
|
||||
}
|
||||
with new_duckdb_locked_connection(str(monitor_service.db_path), read_only=False) as conn:
|
||||
add_row_to_table(conn, "transactions", TransactionModel, data)
|
||||
assert 1 == len(monitor_service.get_transactions())
|
||||
|
||||
with session_scope() as session:
|
||||
migrate_transactions_from_monitor_service_to_database(session)
|
||||
new_trans = get_transactions_by_flow_id(session, UUID(flow_id))
|
||||
assert 1 == len(new_trans)
|
||||
t = new_trans[0]
|
||||
assert t.error is None
|
||||
assert t.inputs == data["inputs"]
|
||||
assert t.outputs == data["outputs"]
|
||||
assert t.status == data["status"]
|
||||
assert str(t.timestamp) == "2021-10-10 10:10:10"
|
||||
assert t.vertex_id == data["vertex_id"]
|
||||
assert t.target_id == data["target_id"]
|
||||
assert t.flow_id == UUID(flow_id)
|
||||
|
||||
assert 0 == len(monitor_service.get_transactions())
|
||||
|
||||
client.request("DELETE", f"api/v1/flows/{flow_id}")
|
||||
with session_scope() as session:
|
||||
new_trans = get_transactions_by_flow_id(session, UUID(flow_id))
|
||||
assert 0 == len(new_trans)
|
||||
|
||||
|
||||
@pytest.mark.load_flows
|
||||
def test_migrate_transactions_no_duckdb(client: TestClient):
|
||||
flow_id = "c54f9130-f2fa-4a3e-b22a-3856d946351b"
|
||||
get_monitor_service()
|
||||
|
||||
with session_scope() as session:
|
||||
migrate_transactions_from_monitor_service_to_database(session)
|
||||
new_trans = get_transactions_by_flow_id(session, UUID(flow_id))
|
||||
assert 0 == len(new_trans)
|
||||
|
||||
|
||||
def test_sqlite_pragmas():
|
||||
db_service = get_db_service()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue