Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added alembic script to resize url and slug columns to 191 #1192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nmveeresh wants to merge 6 commits into main
base: main
Choose a base branch
Loading
from migration/resize-url-slug-columns

Conversation

Copy link
Collaborator

@nmveeresh nmveeresh commented Oct 9, 2025

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

Background

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

  • slug β†’ VARCHAR(255)
  • url β†’ VARCHAR(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 <veeruveeresh1522@gmail.com>
Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com>
Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com>
- 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

Reviewers

@crivetimihai crivetimihai Awaiting requested review from crivetimihai crivetimihai is a code owner

@kevalmahajan kevalmahajan Awaiting requested review from kevalmahajan kevalmahajan is a code owner

@madhav165 madhav165 Awaiting requested review from madhav165 madhav165 is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /