rs_workflows/init_pi_db_flow.md¶
Create the database used in performance indicator
create_schema(db_url)
¶
Creates all database tables defined in the pi_db_models.
This task initializes the database schema for the Performance Indicator (PI) database using the provided SQLAlchemy engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
SQLAlchemy database engine connected to the target database. |
required |
Source code in docs/rs-client-libraries/rs_workflows/init_pi_db_flow.py
init_pi_database(env)
async
¶
Initializes the Performance Indicator (PI) database (named performance) schema and populates default categories.
This Prefect flow
- Creates all required tables for the PI database.
- Inserts default PI categories if none exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
FlowEnvArgs
|
Prefect flow environment configuration, including runtime context variables. |
required |
Environment Variables Required
POSTGRES_USER (str): PostgreSQL username. POSTGRES_PASSWORD (str): PostgreSQL password. POSTGRES_HOST (str): PostgreSQL host address. POSTGRES_PORT (str): PostgreSQL port. POSTGRES_PI_DB (str): Name of the Performance Indicator database.
Flow Steps
- Initialize flow environment and tracing span.
- Build database connection URL.
- Create database schema via
create_schematask. - Insert default PI categories via
insert_pi_categoriestask.
Source code in docs/rs-client-libraries/rs_workflows/init_pi_db_flow.py
insert_pi_categories(db_url)
¶
Inserts default Performance Indicator (PI) categories into the database if none exist.
This task checks whether the pi_category table is empty and, if so, inserts predefined
categories from PI_CATEGORY_DATA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
SQLAlchemy database engine connected to the target database. |
required |
Notes
- If categories already exist, no action is taken.
- Commits the transaction only if new data is inserted.