* feat: Add support for running flows by endpoint name
This commit modifies the `simplified_run_flow` endpoint in `endpoints.py` to allow running flows using the endpoint name instead of the flow ID. It introduces a new route parameter `flow_id_or_name` which can accept either a UUID or a string representing the endpoint name. The code first attempts to parse the parameter as a UUID, and if that fails, it queries the database to find a flow with the matching endpoint name. This change improves the usability of the API by providing an alternative way to identify flows for execution.
* feat: Add endpoint_name field to FlowType
This commit adds the `endpoint_name` field to the `FlowType` interface in the `index.ts` file. The `endpoint_name` field is an optional string that represents the name of the endpoint associated with the flow. This change allows for more flexibility in identifying flows by endpoint name instead of just the flow ID. It improves the usability of the codebase by providing an alternative way to reference flows.
* 🐛 (endpoints.py): change type of flow_id_or_name parameter from Union[str, UUID] to str to simplify the API and improve readability
* feat: Add migration utility functions for table, column, foreign key, and constraint existence checks
This commit adds utility functions to the `migration.py` module in the `langflow.utils` package. These functions provide convenient ways to check the existence of tables, columns, foreign keys, and constraints in a database using SQLAlchemy. The functions `table_exists`, `column_exists`, `foreign_key_exists`, and `constraint_exists` take the table name, column name, foreign key name, and constraint name respectively, along with the SQLAlchemy engine or connection object. They use the `Inspector` class from `sqlalchemy.engine.reflection` to retrieve the necessary information and return a boolean value indicating whether the specified element exists in the database. These utility functions improve the readability and maintainability of the codebase by encapsulating the common existence checks in a reusable and modular way.
* feat: Add unique constraints for per-user folders and flows
This commit adds unique constraints for per-user folders and flows in the database. It introduces the `unique_folder_name` constraint for the `folder` table, ensuring that each user can have only one folder with a specific name. Similarly, it adds the `unique_flow_endpoint_name` and `unique_flow_name` constraints for the `flow` table, enforcing uniqueness of endpoint names and flow names per user. These constraints improve data integrity and prevent duplicate entries in the database, providing a more robust and reliable system.
* feat: Add poetry installation and caching steps to GitHub Actions workflow
This commit updates the GitHub Actions workflow file `action.yml` to include additional steps for installing poetry and caching its dependencies. The `run` step now installs poetry using the specified version and ensures that the poetry binary is available in the PATH. Additionally, the workflow now includes a step to restore pip and poetry cached dependencies using the `actions/cache` action. These changes improve the workflow by providing a more efficient and reliable way to manage poetry dependencies and caching.
* refactor: Improve error handling in update_flow function
This commit improves the error handling in the `update_flow` function in `flows.py`. It adds a new `elif` condition to check if the exception is an instance of `HTTPException` and re-raises it. This ensures that any `HTTPException` raised during the update process is properly handled and returned as a response. Additionally, it removes the unnecessary `else` block and simplifies the code logic. This refactor enhances the reliability and maintainability of the `update_flow` function.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
from sqlalchemy.engine.reflection import Inspector
|
|
|
|
|
|
def table_exists(name, conn):
|
|
"""
|
|
Check if a table exists.
|
|
|
|
Parameters:
|
|
name (str): The name of the table to check.
|
|
conn (sqlalchemy.engine.Engine or sqlalchemy.engine.Connection): The SQLAlchemy engine or connection to use.
|
|
|
|
Returns:
|
|
bool: True if the table exists, False otherwise.
|
|
"""
|
|
inspector = Inspector.from_engine(conn)
|
|
return name in inspector.get_table_names()
|
|
|
|
|
|
def column_exists(table_name, column_name, conn):
|
|
"""
|
|
Check if a column exists in a table.
|
|
|
|
Parameters:
|
|
table_name (str): The name of the table to check.
|
|
column_name (str): The name of the column to check.
|
|
conn (sqlalchemy.engine.Engine or sqlalchemy.engine.Connection): The SQLAlchemy engine or connection to use.
|
|
|
|
Returns:
|
|
bool: True if the column exists, False otherwise.
|
|
"""
|
|
inspector = Inspector.from_engine(conn)
|
|
return column_name in [column["name"] for column in inspector.get_columns(table_name)]
|
|
|
|
|
|
def foreign_key_exists(table_name, fk_name, conn):
|
|
"""
|
|
Check if a foreign key exists in a table.
|
|
|
|
Parameters:
|
|
table_name (str): The name of the table to check.
|
|
fk_name (str): The name of the foreign key to check.
|
|
conn (sqlalchemy.engine.Engine or sqlalchemy.engine.Connection): The SQLAlchemy engine or connection to use.
|
|
|
|
Returns:
|
|
bool: True if the foreign key exists, False otherwise.
|
|
"""
|
|
inspector = Inspector.from_engine(conn)
|
|
return fk_name in [fk["name"] for fk in inspector.get_foreign_keys(table_name)]
|
|
|
|
|
|
def constraint_exists(table_name, constraint_name, conn):
|
|
"""
|
|
Check if a constraint exists in a table.
|
|
|
|
Parameters:
|
|
table_name (str): The name of the table to check.
|
|
constraint_name (str): The name of the constraint to check.
|
|
conn (sqlalchemy.engine.Engine or sqlalchemy.engine.Connection): The SQLAlchemy engine or connection to use.
|
|
|
|
Returns:
|
|
bool: True if the constraint exists, False otherwise.
|
|
"""
|
|
inspector = Inspector.from_engine(conn)
|
|
constraints = inspector.get_unique_constraints(table_name)
|
|
return constraint_name in [constraint["name"] for constraint in constraints]
|