Skip to content

Conversation

nmveeresh
Copy link
Collaborator

🧾 PR Summary: Resize slug and url Columns to 191 Characters

Background

In the existing schema, the following columns had larger lengths:

  • slugVARCHAR(255)
  • urlVARCHAR(767)

These lengths exceeded typical index length limits on some databases (especially MySQL with UTF8MB4 encoding), potentially causing compatibility or index creation issues.


Change Summary

This migration adjusts both columns to a consistent and safer maximum length of 191 characters.

Migration Details

Upgrade (2f67b12600b4 → 878e287d2366):

  • slug: VARCHAR(255)VARCHAR(191)
  • url: VARCHAR(767)VARCHAR(191)

Downgrade (878e287d2366 → 2f67b12600b4):

  • slug: VARCHAR(191)VARCHAR(255)
  • url: VARCHAR(191)VARCHAR(767)

Rationale

  • Ensures compatibility with MySQL’s indexed column limits under UTF8MB4.
  • Aligns column sizes for uniformity across database backends.

Verification

  • ✅ Migration logs confirm successful schema updates:
    • Upgrade and downgrade executed without errors.
  • ✅ Schema inspection shows expected column types and lengths:
    slug → VARCHAR(191)
    url  → VARCHAR(191)
    

@nmveeresh nmveeresh marked this pull request as ready for review October 10, 2025 04:47
nmveeresh and others added 6 commits October 11, 2025 02:33
Signed-off-by: Veeresh K <[email protected]>
Signed-off-by: Veeresh K <[email protected]>
- Update db.py SQLAlchemy model to match migration (String(191))
- Add dialect-specific SQL handling in migration (SQLite, PostgreSQL, MySQL)
- Use CHAR_LENGTH for character-based truncation (not byte-based LENGTH in MySQL)
- Ensure truncation works correctly across all supported database backends
- SQLite doesn't support ALTER COLUMN TYPE directly
- Use batch_alter_table for SQLite (creates temp table, copies data, renames)
- Keep direct ALTER COLUMN for PostgreSQL and MySQL
- Applies to both upgrade and downgrade operations
- Fixes: sqlalchemy.exc.OperationalError with SQLite
@crivetimihai crivetimihai force-pushed the migration/resize-url-slug-columns branch from 05b2a53 to 97bb774 Compare October 11, 2025 01:45
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.

2 participants