fix: remove trailing newlines from migrations to prevent SQLITE_MISUSE errors
Python's sqlite3.executescript() has a bug where trailing newlines after the final semicolon create empty statements. When APSW's log_sqlite() is enabled (via apswutils, imported by fastmigrate), these cause visible "API called with NULL prepared statement" errors during interpreter shutdown. - Strip trailing newlines from all 9 existing migration files - Update migration template to end with semicolon, no trailing newline - Document the requirement in CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,11 @@ When handling animal selections:
|
|||||||
- Store feed amounts in grams (INTEGER) for precision
|
- Store feed amounts in grams (INTEGER) for precision
|
||||||
- Display as kg with 3 decimals
|
- Display as kg with 3 decimals
|
||||||
|
|
||||||
|
### Migrations
|
||||||
|
- Migration files must end with `;` and NO trailing newline
|
||||||
|
- Python's sqlite3.executescript() has a bug: trailing newlines after the final `;` create empty statements that cause SQLITE_MISUSE errors when APSW logging is enabled
|
||||||
|
- Use `animaltrack create-migration "description"` to create new migrations (template handles this correctly)
|
||||||
|
|
||||||
## Refreshing Docs
|
## Refreshing Docs
|
||||||
```bash
|
```bash
|
||||||
# FastHTML
|
# FastHTML
|
||||||
|
|||||||
@@ -94,12 +94,13 @@ def create_migration(migrations_dir: str | Path, description: str) -> Path:
|
|||||||
filepath = migrations_path / filename
|
filepath = migrations_path / filename
|
||||||
|
|
||||||
# SQL template with ABOUTME header
|
# SQL template with ABOUTME header
|
||||||
|
# NOTE: Template must NOT end with trailing newline after final semicolon.
|
||||||
|
# Python's sqlite3.executescript() has a bug where trailing newlines create
|
||||||
|
# empty statements that cause SQLITE_MISUSE errors when APSW logging is enabled.
|
||||||
template = f"""-- ABOUTME: Migration {index:04d} - {description}
|
template = f"""-- ABOUTME: Migration {index:04d} - {description}
|
||||||
-- ABOUTME: Created for AnimalTrack database schema versioning.
|
-- ABOUTME: Created for AnimalTrack database schema versioning.
|
||||||
|
|
||||||
-- Write your migration SQL here
|
-- Write your migration SQL here;"""
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
filepath.write_text(template)
|
filepath.write_text(template)
|
||||||
return filepath
|
return filepath
|
||||||
|
|||||||
Reference in New Issue
Block a user