Skip to content

Commit 4ac2238

Browse files
committed
env_variables
1 parent 00a99d5 commit 4ac2238

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

fastapi/.env.example

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
# Local Lakebase Configuration (legacy - replaced by Lakebase config below)
2-
# DATABRICKS_DATABASE_INSTANCE=<INSTANCE_NAME>
3-
# DATABRICKS_DATABASE_NAME=<DATABASE_NAME>
4-
DATABRICKS_DATABASE_PORT=5432
5-
6-
# Table Configuration
7-
DEFAULT_POSTGRES_SCHEMA=<SCHEMA_NAME>
8-
DEFAULT_POSTGRES_TABLE=<TABLE_NAME>
9-
101
# Lakebase Configuration
112
LAKEBASE_INSTANCE_NAME=<LAKEBASE_INSTANCE_NAME> # Name of the Lakebase instance
123
LAKEBASE_DATABASE_NAME=<LAKEBASE_DATABASE_NAME> # Name of the Lakebase database
134
LAKEBASE_CATALOG_NAME=<LAKEBASE_CATALOG_NAME> # Name of the Lakebase catalog
145
SYNCHED_TABLE_STORAGE_CATALOG=<SYNCED_TABLE_CATALOG> # Catalog where you have permissions to create tables. Used to store metadata from the lakebase synced table pipeline.
156
SYNCHED_TABLE_STORAGE_SCHEMA=<SYNCED_TABLE_SCHEMA> # Schema where you have permissions to create tables. Used to store metadata from the lakebase synced table pipeline.
16-
7+
DATABRICKS_DATABASE_PORT=5432
178
DATABRICKS_HOST=<DATABRICKS_HOST> # e.g., https://adb-1234567890123456.7.azuredatabricks.net
189
DATABRICKS_TOKEN=<PAT_TOKEN> # e.g., dapi
1910
DATABRICKS_USER_NAME=<YOUR_USER_NAME> # e.g., [email protected]

fastapi/app.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ env:
1212
- name: 'DATABRICKS_DATABASE_PORT'
1313
value: '5432'
1414

15-
- name: 'DEFAULT_POSTGRES_SCHEMA'
16-
value: 'public'
17-
- name: 'DEFAULT_POSTGRES_TABLE'
18-
value: 'orders_synced'
19-
2015
- name: 'DB_POOL_SIZE'
2116
value: '5'
2217
- name: 'DB_MAX_OVERFLOW'

fastapi/models/orders.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from datetime import date
32
from decimal import Decimal
43
from typing import Optional
@@ -18,8 +17,8 @@ class OrderBase(SQLModel):
1817

1918

2019
class Order(OrderBase, table=True):
21-
__tablename__ = os.getenv("DEFAULT_POSTGRES_TABLE", "orders_synced")
22-
__table_args__ = {"schema": os.getenv("DEFAULT_POSTGRES_SCHEMA", "public")}
20+
__tablename__ = "orders_synced"
21+
__table_args__ = "public"
2322
o_orderkey: Optional[int] = Field(default=None, primary_key=True)
2423

2524

fastapi/routes/v1/lakebase.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ async def create_lakebase_resources(
4545
),
4646
):
4747
if create_resources:
48-
instance_name = os.getenv("LAKEBASE_INSTANCE_NAME", f"{current_user_id}-lakebase-demo")
49-
48+
instance_name = os.getenv(
49+
"LAKEBASE_INSTANCE_NAME", f"{current_user_id}-lakebase-demo"
50+
)
51+
5052
# Check if instance already exists
5153
try:
5254
instance_exists = w.database.get_database_instance(name=instance_name)
@@ -59,12 +61,14 @@ async def create_lakebase_resources(
5961
)
6062
except Exception as e:
6163
if "not found" in str(e).lower() or "resource not found" in str(e).lower():
62-
logger.info(f"Instance {instance_name} does not exist. Proceeding with creation.")
64+
logger.info(
65+
f"Instance {instance_name} does not exist. Proceeding with creation."
66+
)
6367
else:
6468
logger.error(f"Error checking instance existence: {e}")
6569
raise HTTPException(
66-
status_code=500,
67-
detail=f"Error checking instance existence: {str(e)}"
70+
status_code=500,
71+
detail=f"Error checking instance existence: {str(e)}",
6872
)
6973

7074
lakebase_database_name = os.getenv("LAKEBASE_DATABASE_NAME", "demo_database")
@@ -101,12 +105,15 @@ async def create_lakebase_resources(
101105
logger.info(f"Creating superuser role for: {superuser_role.name}")
102106
try:
103107
created_role = w.database.create_database_instance_role(
104-
instance_name=instance_create.name, database_instance_role=superuser_role
108+
instance_name=instance_create.name,
109+
database_instance_role=superuser_role,
105110
)
106111
logger.info(f"Successfully created superuser role: {created_role.name}")
107112
except Exception as e:
108113
logger.error(f"Failed to create superuser role (continuing anyway): {e}")
109-
logger.info("Database instance is still functional - role can be created manually if needed")
114+
logger.info(
115+
"Database instance is still functional - role can be created manually if needed"
116+
)
110117

111118
catalog = DatabaseCatalog(
112119
name=catalog_name,
@@ -145,17 +152,18 @@ async def create_lakebase_resources(
145152
logger.info(f"Initiated sync pipeline creation: {synced_table_create.id}")
146153
pipeline_id = synced_table_create.id
147154
except Exception as e:
148-
logger.error(f"API error during synced table creation (pipeline likely created anyway): {e}")
155+
logger.error(
156+
f"API error during synced table creation (pipeline likely created anyway): {e}"
157+
)
149158
pipeline_id = "check-workspace-ui"
150-
151-
# Get workspace URL from current workspace client
159+
152160
workspace_url = w.config.host
153161
if pipeline_id != "check-workspace-ui":
154162
pipeline_url = f"{workspace_url}/pipelines/{pipeline_id}"
155163
message = f"Resources created successfully. Synced table pipeline {pipeline_id} is provisioning asynchronously. Monitor progress at: {pipeline_url}"
156164
else:
157165
message = f"Resources created successfully. Synced table pipeline initiated (API response error). Check pipelines in workspace: {workspace_url}/pipelines"
158-
166+
159167
return LakebaseResourcesResponse(
160168
instance=instance_create.name,
161169
catalog=database_create.name,
@@ -192,7 +200,9 @@ async def delete_lakebase_resources(
192200
message="No resources were deleted (confirm_deletion=False)",
193201
)
194202

195-
instance_name = os.getenv("LAKEBASE_INSTANCE_NAME", f"{current_user_id}-lakebase-demo")
203+
instance_name = os.getenv(
204+
"LAKEBASE_INSTANCE_NAME", f"{current_user_id}-lakebase-demo"
205+
)
196206
catalog_name = os.getenv("LAKEBASE_CATALOG_NAME", f"{current_user_id}-pg-catalog")
197207
synced_table_name = f"{catalog_name}.public.orders_synced"
198208

0 commit comments

Comments
 (0)