Compare commits
2
Commits
0fe7d247f8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36151f4dda | ||
|
|
f8f88be492 |
@@ -1,88 +0,0 @@
|
|||||||
name: Build, Test & Deploy LotusGen
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
# 1. Automated Testing (Backend Pytest + Frontend Typecheck)
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
test:
|
|
||||||
name: Run Pytest & Frontend Build Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# --- PYTHON SETUP ---
|
|
||||||
- name: Set up Python 3.11
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.11'
|
|
||||||
|
|
||||||
- name: Install Dependencies & Run Tests
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r backend/requirements.txt pytest
|
|
||||||
python -m pytest backend/tests/ -v
|
|
||||||
|
|
||||||
# --- NODE SETUP ---
|
|
||||||
- name: Set up Node.js 20
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Verify Frontend Compilation
|
|
||||||
run: |
|
|
||||||
cd frontend
|
|
||||||
npm ci
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
# 2. Continuous Deployment (Build & Recreate Container)
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
deploy:
|
|
||||||
name: Build & Deploy Container
|
|
||||||
needs: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# Security: Deploy ONLY on pushes to main by the repository owner
|
|
||||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && github.repository == 'Sylphian/lotusgen'
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build and Start Production Container
|
|
||||||
env:
|
|
||||||
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
|
|
||||||
HOST_PORT: ${{ secrets.HOST_PORT }}
|
|
||||||
DATA_DIR: ${{ secrets.DATA_DIR }}
|
|
||||||
ARTIFACTS_DIR: ${{ secrets.ARTIFACTS_DIR }}
|
|
||||||
run: |
|
|
||||||
# Create host storage directories if they don't exist
|
|
||||||
mkdir -p "$DATA_DIR" "$ARTIFACTS_DIR"
|
|
||||||
|
|
||||||
# Build the production image from repo checkout
|
|
||||||
docker build -t lotusgen-app:latest .
|
|
||||||
|
|
||||||
# Gracefully recreate container
|
|
||||||
docker stop "$CONTAINER_NAME" 2>/dev/null || true
|
|
||||||
docker rm "$CONTAINER_NAME" 2>/dev/null || true
|
|
||||||
|
|
||||||
docker run -d \
|
|
||||||
--name "$CONTAINER_NAME" \
|
|
||||||
--restart unless-stopped \
|
|
||||||
-p 127.0.0.1:${HOST_PORT}:8000 \
|
|
||||||
-v "${DATA_DIR}:/app/data" \
|
|
||||||
-v "${ARTIFACTS_DIR}:/app/artifacts" \
|
|
||||||
-e LOTUSGEN_DB_PATH=/app/data/lotusgen.db \
|
|
||||||
-e LOTUSGEN_ARTIFACTS_DIR=/app/artifacts \
|
|
||||||
lotusgen-app:latest
|
|
||||||
|
|
||||||
echo "LotusGen successfully deployed to 127.0.0.1:${HOST_PORT}"
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import secrets
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
@@ -43,6 +44,7 @@ def format_table_response(table, project_tables) -> TableResponse:
|
|||||||
archetype=table.archetype, # type: ignore
|
archetype=table.archetype, # type: ignore
|
||||||
status=table.status, # type: ignore
|
status=table.status, # type: ignore
|
||||||
format=table.format, # type: ignore
|
format=table.format, # type: ignore
|
||||||
|
use_project_seed=getattr(table, "use_project_seed", True),
|
||||||
row_limit=table.row_limit,
|
row_limit=table.row_limit,
|
||||||
exclude_if=table.exclude_if,
|
exclude_if=table.exclude_if,
|
||||||
fields=table.fields_data or [],
|
fields=table.fields_data or [],
|
||||||
@@ -232,6 +234,7 @@ async def preview_table(table_id: str, count: int = Query(10, le=50), db: AsyncS
|
|||||||
proj = await ProjectService.get_project(db, table.project_id)
|
proj = await ProjectService.get_project(db, table.project_id)
|
||||||
proj_name = proj.name if proj else ""
|
proj_name = proj.name if proj else ""
|
||||||
proj_seed = proj.seed if proj else 42
|
proj_seed = proj.seed if proj else 42
|
||||||
|
effective_seed = proj_seed if getattr(table, "use_project_seed", True) else secrets.randbelow(10**9)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
samples = generate_dry_run_sample(
|
samples = generate_dry_run_sample(
|
||||||
@@ -239,7 +242,7 @@ async def preview_table(table_id: str, count: int = Query(10, le=50), db: AsyncS
|
|||||||
ref_tables,
|
ref_tables,
|
||||||
sample_size=count,
|
sample_size=count,
|
||||||
project_name=proj_name,
|
project_name=proj_name,
|
||||||
seed=proj_seed,
|
seed=effective_seed,
|
||||||
)
|
)
|
||||||
return DryRunResponse(success=True, sample_rows=samples)
|
return DryRunResponse(success=True, sample_rows=samples)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ async def init_db() -> None:
|
|||||||
tab_cols = [r[1] for r in connection.exec_driver_sql("PRAGMA table_info(tables)").fetchall()]
|
tab_cols = [r[1] for r in connection.exec_driver_sql("PRAGMA table_info(tables)").fetchall()]
|
||||||
if "slug" not in tab_cols:
|
if "slug" not in tab_cols:
|
||||||
connection.exec_driver_sql("ALTER TABLE tables ADD COLUMN slug VARCHAR(255) DEFAULT ''")
|
connection.exec_driver_sql("ALTER TABLE tables ADD COLUMN slug VARCHAR(255) DEFAULT ''")
|
||||||
|
if "use_project_seed" not in tab_cols:
|
||||||
|
connection.exec_driver_sql("ALTER TABLE tables ADD COLUMN use_project_seed BOOLEAN DEFAULT 1")
|
||||||
|
|
||||||
await conn.run_sync(migrate_slugs)
|
await conn.run_sync(migrate_slugs)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
|
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text
|
||||||
from sqlalchemy.dialects.sqlite import JSON
|
from sqlalchemy.dialects.sqlite import JSON
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
from backend.db.database import Base
|
from backend.db.database import Base
|
||||||
@@ -38,6 +38,7 @@ class TableModel(Base):
|
|||||||
archetype: Mapped[str] = mapped_column(String(50), nullable=False) # record, aggregate, reference
|
archetype: Mapped[str] = mapped_column(String(50), nullable=False) # record, aggregate, reference
|
||||||
status: Mapped[str] = mapped_column(String(50), default="draft") # draft, valid
|
status: Mapped[str] = mapped_column(String(50), default="draft") # draft, valid
|
||||||
format: Mapped[str] = mapped_column(String(20), default="csv") # csv, parquet
|
format: Mapped[str] = mapped_column(String(20), default="csv") # csv, parquet
|
||||||
|
use_project_seed: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||||
row_limit: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
row_limit: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
||||||
exclude_if: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
exclude_if: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class TableCreate(BaseModel):
|
|||||||
slug: Optional[str] = None
|
slug: Optional[str] = None
|
||||||
archetype: Literal["record", "aggregate", "reference", "collection"]
|
archetype: Literal["record", "aggregate", "reference", "collection"]
|
||||||
format: Optional[Literal["csv", "parquet"]] = "csv"
|
format: Optional[Literal["csv", "parquet"]] = "csv"
|
||||||
|
use_project_seed: Optional[bool] = True
|
||||||
row_limit: Optional[int] = 100000
|
row_limit: Optional[int] = 100000
|
||||||
exclude_if: Optional[str] = None
|
exclude_if: Optional[str] = None
|
||||||
fields: Optional[List[FieldSchema]] = Field(default_factory=list)
|
fields: Optional[List[FieldSchema]] = Field(default_factory=list)
|
||||||
@@ -44,6 +45,7 @@ class TableUpdate(BaseModel):
|
|||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
slug: Optional[str] = None
|
slug: Optional[str] = None
|
||||||
format: Optional[Literal["csv", "parquet"]] = None
|
format: Optional[Literal["csv", "parquet"]] = None
|
||||||
|
use_project_seed: Optional[bool] = None
|
||||||
row_limit: Optional[int] = None
|
row_limit: Optional[int] = None
|
||||||
exclude_if: Optional[str] = None
|
exclude_if: Optional[str] = None
|
||||||
fields: Optional[List[FieldSchema]] = None
|
fields: Optional[List[FieldSchema]] = None
|
||||||
@@ -66,6 +68,7 @@ class TableResponse(BaseModel):
|
|||||||
archetype: Literal["record", "aggregate", "reference", "collection"]
|
archetype: Literal["record", "aggregate", "reference", "collection"]
|
||||||
status: Literal["draft", "valid"]
|
status: Literal["draft", "valid"]
|
||||||
format: Literal["csv", "parquet"]
|
format: Literal["csv", "parquet"]
|
||||||
|
use_project_seed: bool = True
|
||||||
row_limit: Optional[int] = None
|
row_limit: Optional[int] = None
|
||||||
exclude_if: Optional[str] = None
|
exclude_if: Optional[str] = None
|
||||||
fields: List[FieldSchema] = Field(default_factory=list)
|
fields: List[FieldSchema] = Field(default_factory=list)
|
||||||
@@ -135,6 +138,7 @@ class ExportTableSchema(BaseModel):
|
|||||||
archetype: Literal["record", "aggregate", "reference", "collection"]
|
archetype: Literal["record", "aggregate", "reference", "collection"]
|
||||||
status: Literal["draft", "valid"]
|
status: Literal["draft", "valid"]
|
||||||
format: Optional[Literal["csv", "parquet"]] = "csv"
|
format: Optional[Literal["csv", "parquet"]] = "csv"
|
||||||
|
use_project_seed: Optional[bool] = True
|
||||||
row_limit: Optional[int] = None
|
row_limit: Optional[int] = None
|
||||||
exclude_if: Optional[str] = None
|
exclude_if: Optional[str] = None
|
||||||
fields: Optional[List[FieldSchema]] = None
|
fields: Optional[List[FieldSchema]] = None
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import secrets
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Any, AsyncGenerator, Dict, List, Optional
|
from typing import Any, AsyncGenerator, Dict, List, Optional
|
||||||
@@ -114,6 +115,7 @@ class GenerationService:
|
|||||||
project = await ProjectService.get_project(session, project_id)
|
project = await ProjectService.get_project(session, project_id)
|
||||||
project_name = project.name if project else ""
|
project_name = project.name if project else ""
|
||||||
project_seed = project.seed if project else 42
|
project_seed = project.seed if project else 42
|
||||||
|
effective_seed = project_seed if table_dict.get("use_project_seed", True) else secrets.randbelow(10**9)
|
||||||
|
|
||||||
GenerationService._broadcast(
|
GenerationService._broadcast(
|
||||||
job_id,
|
job_id,
|
||||||
@@ -145,7 +147,7 @@ class GenerationService:
|
|||||||
gen = TableGenerator(
|
gen = TableGenerator(
|
||||||
table_dict,
|
table_dict,
|
||||||
ref_tables,
|
ref_tables,
|
||||||
seed=project_seed,
|
seed=effective_seed,
|
||||||
chunk_size=50000,
|
chunk_size=50000,
|
||||||
project_name=project_name,
|
project_name=project_name,
|
||||||
total_count=target_rows,
|
total_count=target_rows,
|
||||||
@@ -174,7 +176,7 @@ class GenerationService:
|
|||||||
gen = TableGenerator(
|
gen = TableGenerator(
|
||||||
table_dict,
|
table_dict,
|
||||||
ref_tables,
|
ref_tables,
|
||||||
seed=project_seed,
|
seed=effective_seed,
|
||||||
chunk_size=50000,
|
chunk_size=50000,
|
||||||
project_name=project_name,
|
project_name=project_name,
|
||||||
total_count=target_rows,
|
total_count=target_rows,
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ class ProjectService:
|
|||||||
"archetype": t.archetype,
|
"archetype": t.archetype,
|
||||||
"status": t.status,
|
"status": t.status,
|
||||||
"format": t.format,
|
"format": t.format,
|
||||||
|
"use_project_seed": getattr(t, "use_project_seed", True),
|
||||||
"row_limit": t.row_limit,
|
"row_limit": t.row_limit,
|
||||||
"exclude_if": t.exclude_if,
|
"exclude_if": t.exclude_if,
|
||||||
"fields": t.fields_data or [],
|
"fields": t.fields_data or [],
|
||||||
@@ -178,6 +179,7 @@ class ProjectService:
|
|||||||
archetype=t.get("archetype", "record"),
|
archetype=t.get("archetype", "record"),
|
||||||
status=t.get("status", "draft"),
|
status=t.get("status", "draft"),
|
||||||
format=t.get("format", "csv"),
|
format=t.get("format", "csv"),
|
||||||
|
use_project_seed=t.get("use_project_seed", True),
|
||||||
row_limit=t.get("row_limit"),
|
row_limit=t.get("row_limit"),
|
||||||
exclude_if=t.get("exclude_if"),
|
exclude_if=t.get("exclude_if"),
|
||||||
fields_data=t.get("fields", []),
|
fields_data=t.get("fields", []),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import secrets
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@@ -88,6 +89,7 @@ def model_to_table_dict(t: TableModel) -> Dict[str, Any]:
|
|||||||
"archetype": t.archetype,
|
"archetype": t.archetype,
|
||||||
"status": t.status,
|
"status": t.status,
|
||||||
"format": t.format,
|
"format": t.format,
|
||||||
|
"use_project_seed": getattr(t, "use_project_seed", True),
|
||||||
"row_limit": t.row_limit,
|
"row_limit": t.row_limit,
|
||||||
"exclude_if": t.exclude_if,
|
"exclude_if": t.exclude_if,
|
||||||
"fields": t.fields_data or [],
|
"fields": t.fields_data or [],
|
||||||
@@ -130,6 +132,7 @@ class TableService:
|
|||||||
archetype=data.archetype,
|
archetype=data.archetype,
|
||||||
status="draft",
|
status="draft",
|
||||||
format=data.format or "csv",
|
format=data.format or "csv",
|
||||||
|
use_project_seed=data.use_project_seed if data.use_project_seed is not None else True,
|
||||||
row_limit=data.row_limit,
|
row_limit=data.row_limit,
|
||||||
exclude_if=clean_exclude,
|
exclude_if=clean_exclude,
|
||||||
fields_data=clean_fields,
|
fields_data=clean_fields,
|
||||||
@@ -194,6 +197,8 @@ class TableService:
|
|||||||
table.slug = data.slug.strip()
|
table.slug = data.slug.strip()
|
||||||
if data.format is not None:
|
if data.format is not None:
|
||||||
table.format = data.format
|
table.format = data.format
|
||||||
|
if data.use_project_seed is not None:
|
||||||
|
table.use_project_seed = data.use_project_seed
|
||||||
if data.row_limit is not None:
|
if data.row_limit is not None:
|
||||||
table.row_limit = data.row_limit
|
table.row_limit = data.row_limit
|
||||||
if data.exclude_if is not None:
|
if data.exclude_if is not None:
|
||||||
@@ -292,6 +297,7 @@ class TableService:
|
|||||||
project = proj_res.scalar_one_or_none()
|
project = proj_res.scalar_one_or_none()
|
||||||
project_name = project.name if project else ""
|
project_name = project.name if project else ""
|
||||||
project_seed = project.seed if project else 42
|
project_seed = project.seed if project else 42
|
||||||
|
effective_seed = project_seed if getattr(table, "use_project_seed", True) else secrets.randbelow(10**9)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sample_rows = generate_dry_run_sample(
|
sample_rows = generate_dry_run_sample(
|
||||||
@@ -299,7 +305,7 @@ class TableService:
|
|||||||
ref_tables,
|
ref_tables,
|
||||||
sample_size=10,
|
sample_size=10,
|
||||||
project_name=project_name,
|
project_name=project_name,
|
||||||
seed=project_seed,
|
seed=effective_seed,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise TableValidationError(f"Dry-run generation failed: {type(e).__name__} - {e}") from e
|
raise TableValidationError(f"Dry-run generation failed: {type(e).__name__} - {e}") from e
|
||||||
|
|||||||
@@ -604,3 +604,80 @@ async def test_metadata_variables_api_workflow():
|
|||||||
assert len(val_rows) == 10
|
assert len(val_rows) == 10
|
||||||
assert val_rows[0]["tag"] == "TelemetryHub:metrics:1:2500:777"
|
assert val_rows[0]["tag"] == "TelemetryHub:metrics:1:2500:777"
|
||||||
assert val_rows[9]["tag"] == "TelemetryHub:metrics:10:2500:777"
|
assert val_rows[9]["tag"] == "TelemetryHub:metrics:10:2500:777"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_table_use_project_seed_toggle():
|
||||||
|
await init_db()
|
||||||
|
transport = ASGITransport(app=app)
|
||||||
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||||
|
# 1. Create project with seed=42
|
||||||
|
proj_slug = f"seed-test-{uuid.uuid4().hex[:6]}"
|
||||||
|
res_p = await client.post(
|
||||||
|
"/api/projects",
|
||||||
|
json={"name": "SeedTest", "slug": proj_slug, "seed": 42},
|
||||||
|
)
|
||||||
|
assert res_p.status_code == 201
|
||||||
|
|
||||||
|
# 2. Create table with use_project_seed=True (default)
|
||||||
|
res_t1 = await client.post(
|
||||||
|
f"/api/projects/{proj_slug}/tables",
|
||||||
|
json={
|
||||||
|
"name": "deterministic_table",
|
||||||
|
"archetype": "record",
|
||||||
|
"use_project_seed": True,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "rand_val",
|
||||||
|
"role": "randomized",
|
||||||
|
"type": "integer",
|
||||||
|
"config": {"min": 1, "max": 1000000},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert res_t1.status_code == 201
|
||||||
|
t1_id = res_t1.json()["id"]
|
||||||
|
assert res_t1.json()["use_project_seed"] is True
|
||||||
|
|
||||||
|
# Previews on deterministic table must be identical
|
||||||
|
p1 = (await client.get(f"/api/tables/{t1_id}/preview?count=5")).json()["sample_rows"]
|
||||||
|
p2 = (await client.get(f"/api/tables/{t1_id}/preview?count=5")).json()["sample_rows"]
|
||||||
|
assert p1 == p2
|
||||||
|
|
||||||
|
# 3. Create table with use_project_seed=False (dynamic seed)
|
||||||
|
res_t2 = await client.post(
|
||||||
|
f"/api/projects/{proj_slug}/tables",
|
||||||
|
json={
|
||||||
|
"name": "dynamic_table",
|
||||||
|
"archetype": "record",
|
||||||
|
"use_project_seed": False,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "rand_val",
|
||||||
|
"role": "randomized",
|
||||||
|
"type": "integer",
|
||||||
|
"config": {"min": 1, "max": 1000000},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert res_t2.status_code == 201
|
||||||
|
t2_id = res_t2.json()["id"]
|
||||||
|
assert res_t2.json()["use_project_seed"] is False
|
||||||
|
|
||||||
|
# Previews on dynamic table will generate fresh seeds
|
||||||
|
dp1 = (await client.get(f"/api/tables/{t2_id}/preview?count=5")).json()["sample_rows"]
|
||||||
|
dp2 = (await client.get(f"/api/tables/{t2_id}/preview?count=5")).json()["sample_rows"]
|
||||||
|
assert dp1 != dp2
|
||||||
|
|
||||||
|
# 4. Update use_project_seed toggle via PUT /api/tables/{id}
|
||||||
|
res_up = await client.put(f"/api/tables/{t2_id}", json={"use_project_seed": True})
|
||||||
|
assert res_up.status_code == 200
|
||||||
|
assert res_up.json()["use_project_seed"] is True
|
||||||
|
|
||||||
|
# Now it is deterministic
|
||||||
|
up1 = (await client.get(f"/api/tables/{t2_id}/preview?count=5")).json()["sample_rows"]
|
||||||
|
up2 = (await client.get(f"/api/tables/{t2_id}/preview?count=5")).json()["sample_rows"]
|
||||||
|
assert up1 == up2
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [name, setName] = useState(table.name);
|
const [name, setName] = useState(table.name);
|
||||||
const [format, setFormat] = useState<'csv' | 'parquet'>(table.format || 'csv');
|
const [format, setFormat] = useState<'csv' | 'parquet'>(table.format || 'csv');
|
||||||
|
const [useProjectSeed, setUseProjectSeed] = useState<boolean>(table.use_project_seed !== false);
|
||||||
const [rowLimit, setRowLimit] = useState<number>(table.row_limit || 100000);
|
const [rowLimit, setRowLimit] = useState<number>(table.row_limit || 100000);
|
||||||
const [excludeIf, setExcludeIf] = useState<string>(table.exclude_if || '');
|
const [excludeIf, setExcludeIf] = useState<string>(table.exclude_if || '');
|
||||||
const [fields, setFields] = useState<Field[]>(table.fields || []);
|
const [fields, setFields] = useState<Field[]>(table.fields || []);
|
||||||
@@ -109,6 +110,7 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
const exportPayload = {
|
const exportPayload = {
|
||||||
archetype: table.archetype,
|
archetype: table.archetype,
|
||||||
format,
|
format,
|
||||||
|
use_project_seed: useProjectSeed,
|
||||||
row_limit: rowLimit,
|
row_limit: rowLimit,
|
||||||
exclude_if: excludeIf || null,
|
exclude_if: excludeIf || null,
|
||||||
fields,
|
fields,
|
||||||
@@ -171,6 +173,9 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
if (parsed.format && (parsed.format === 'csv' || parsed.format === 'parquet')) {
|
if (parsed.format && (parsed.format === 'csv' || parsed.format === 'parquet')) {
|
||||||
setFormat(parsed.format);
|
setFormat(parsed.format);
|
||||||
}
|
}
|
||||||
|
if (typeof parsed.use_project_seed === 'boolean') {
|
||||||
|
setUseProjectSeed(parsed.use_project_seed);
|
||||||
|
}
|
||||||
if (typeof parsed.row_limit === 'number') {
|
if (typeof parsed.row_limit === 'number') {
|
||||||
setRowLimit(parsed.row_limit);
|
setRowLimit(parsed.row_limit);
|
||||||
}
|
}
|
||||||
@@ -355,6 +360,7 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
const updated = await updateTable(table.id, {
|
const updated = await updateTable(table.id, {
|
||||||
name: cleanName,
|
name: cleanName,
|
||||||
format,
|
format,
|
||||||
|
use_project_seed: useProjectSeed,
|
||||||
row_limit: rowLimit,
|
row_limit: rowLimit,
|
||||||
exclude_if: cleanExclude,
|
exclude_if: cleanExclude,
|
||||||
fields: cleanFields,
|
fields: cleanFields,
|
||||||
@@ -382,6 +388,7 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
await updateTable(table.id, {
|
await updateTable(table.id, {
|
||||||
name: cleanName,
|
name: cleanName,
|
||||||
format,
|
format,
|
||||||
|
use_project_seed: useProjectSeed,
|
||||||
row_limit: rowLimit,
|
row_limit: rowLimit,
|
||||||
exclude_if: cleanExclude,
|
exclude_if: cleanExclude,
|
||||||
fields: cleanFields,
|
fields: cleanFields,
|
||||||
@@ -410,6 +417,7 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
await updateTable(table.id, {
|
await updateTable(table.id, {
|
||||||
name,
|
name,
|
||||||
format,
|
format,
|
||||||
|
use_project_seed: useProjectSeed,
|
||||||
row_limit: rowLimit,
|
row_limit: rowLimit,
|
||||||
exclude_if: excludeIf || null,
|
exclude_if: excludeIf || null,
|
||||||
fields,
|
fields,
|
||||||
@@ -567,6 +575,32 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-medium text-[#4F6170] dark:text-[#ADBFCE] mb-1">
|
||||||
|
RNG Seed
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={isLocked}
|
||||||
|
onClick={() => setUseProjectSeed(!useProjectSeed)}
|
||||||
|
className={`w-full flex items-center justify-between px-3 py-1.5 text-xs font-mono rounded-[6px] border-[1.5px] transition-colors disabled:opacity-50 cursor-pointer ${
|
||||||
|
useProjectSeed
|
||||||
|
? 'border-[#346538] bg-[#EDF3EC] dark:bg-[#1b2b1e] text-[#346538] dark:text-[#88d48e]'
|
||||||
|
: 'border-[#DEE3E8] dark:border-[#4F6170] bg-[#FFFFFF] dark:bg-[#161C22] text-[#4F6170] dark:text-[#ADBFCE]'
|
||||||
|
}`}
|
||||||
|
title={
|
||||||
|
useProjectSeed
|
||||||
|
? 'Follows project seed (deterministic and reproducible)'
|
||||||
|
: 'Uses dynamic random seed per generation/preview run'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span>{useProjectSeed ? 'Project Seed' : 'Dynamic Seed'}</span>
|
||||||
|
<span className="text-[10px] font-bold uppercase px-1.5 py-0.5 rounded border border-current">
|
||||||
|
{useProjectSeed ? 'Fixed' : 'Random'}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{isAggregate && (
|
{isAggregate && (
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-medium text-[#4F6170] dark:text-[#ADBFCE] mb-1">
|
<label className="block text-xs font-medium text-[#4F6170] dark:text-[#ADBFCE] mb-1">
|
||||||
@@ -757,7 +791,7 @@ export const TableSchemaEditor: React.FC<TableSchemaEditorProps> = ({
|
|||||||
title="Insert built-in variable or upstream column into expression"
|
title="Insert built-in variable or upstream column into expression"
|
||||||
>
|
>
|
||||||
<BracketsCurly size={13} weight="bold" />
|
<BracketsCurly size={13} weight="bold" />
|
||||||
<span>{'{ }'} Insert Variable</span>
|
<span>Insert Variable</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{activeVarPickerIdx === idx && (
|
{activeVarPickerIdx === idx && (
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export interface Table {
|
|||||||
archetype: TableArchetype;
|
archetype: TableArchetype;
|
||||||
status: TableStatus;
|
status: TableStatus;
|
||||||
format: OutputFormat;
|
format: OutputFormat;
|
||||||
|
use_project_seed?: boolean;
|
||||||
row_limit?: number | null;
|
row_limit?: number | null;
|
||||||
exclude_if?: string | null;
|
exclude_if?: string | null;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
|
|||||||
Reference in New Issue
Block a user