Skip to content

Replace raw SQL schema with SQLAlchemy Table definitions#237

Merged
michaelchu merged 1 commit intomainfrom
claude/review-sql-setup-wUGiF
Feb 28, 2026
Merged

Replace raw SQL schema with SQLAlchemy Table definitions#237
michaelchu merged 1 commit intomainfrom
claude/review-sql-setup-wUGiF

Conversation

@michaelchu
Copy link
Copy Markdown
Member

Move the Chainlit persistence DDL from hand-written SQL strings into
proper SQLAlchemy Table/Column definitions (optopsy/ui/models.py).
metadata.create_all() now emits dialect-appropriate DDL automatically:

  • PostgreSQL: UUID, JSONB, TEXT[], BOOLEAN, ON DELETE CASCADE
  • SQLite: TEXT, TEXT, TEXT, BOOLEAN (INTEGER affinity), ON DELETE CASCADE

Also aligns with the Chainlit docs schema:

  • Add missing columns: steps.command, steps.indent, feedbacks.threadId
  • Fix types: feedbacks.value INT (was REAL), elements.page INT (was TEXT)
  • Fix nullability: steps.name/type NOT NULL, elements.name NOT NULL
  • Add ON DELETE CASCADE to all foreign keys
  • Remove stale columns: elements.autoPlay, elements.playerConfig

https://claude.ai/code/session_01M8Tb8gCPXhR6VsExM2KNCm

Move the Chainlit persistence DDL from hand-written SQL strings into
proper SQLAlchemy Table/Column definitions (optopsy/ui/models.py).
metadata.create_all() now emits dialect-appropriate DDL automatically:

- PostgreSQL: UUID, JSONB, TEXT[], BOOLEAN, ON DELETE CASCADE
- SQLite: TEXT, TEXT, TEXT, BOOLEAN (INTEGER affinity), ON DELETE CASCADE

Also aligns with the Chainlit docs schema:
- Add missing columns: steps.command, steps.indent, feedbacks.threadId
- Fix types: feedbacks.value INT (was REAL), elements.page INT (was TEXT)
- Fix nullability: steps.name/type NOT NULL, elements.name NOT NULL
- Add ON DELETE CASCADE to all foreign keys
- Remove stale columns: elements.autoPlay, elements.playerConfig

https://claude.ai/code/session_01M8Tb8gCPXhR6VsExM2KNCm
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the Chainlit persistence schema from hand-written SQL strings to SQLAlchemy Table/Column definitions so metadata.create_all(engine) can emit dialect-appropriate DDL for SQLite and PostgreSQL.

Changes:

  • Add SQLAlchemy Core table definitions for the Chainlit persistence tables (users, threads, steps, elements, feedbacks).
  • Replace the raw DDL execution loop in app.py with metadata.create_all(engine) using the new models metadata.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
optopsy/ui/models.py Introduces SQLAlchemy MetaData + table definitions with dialect variants (UUID/JSONB/ARRAY on Postgres, TEXT fallback on SQLite).
optopsy/ui/app.py Removes raw SQL schema statements and initializes the DB schema via _db_metadata.create_all(engine).

Comment thread optopsy/ui/models.py
Comment thread optopsy/ui/models.py
Comment thread optopsy/ui/models.py
Comment thread optopsy/ui/app.py
Comment thread optopsy/ui/app.py
Comment thread optopsy/ui/app.py
@michaelchu michaelchu merged commit 23656b5 into main Feb 28, 2026
12 checks passed
@michaelchu michaelchu deleted the claude/review-sql-setup-wUGiF branch February 28, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants