Replace raw SQL schema with SQLAlchemy Table definitions#237
Merged
michaelchu merged 1 commit intomainfrom Feb 28, 2026
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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.pywithmetadata.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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Also aligns with the Chainlit docs schema:
https://claude.ai/code/session_01M8Tb8gCPXhR6VsExM2KNCm