npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prisma-reorder

v1.0.0

Published

A TypeScript NPM package that enhances Prisma ORM by enabling automatic column reordering in MySQL/MariaDB databases to match the column order defined in the Prisma schema.

Readme

Prisma Column Order Manager

A TypeScript-based NPM package that enhances the developer experience with Prisma ORM by enabling automatic column reordering in supported SQL databases (MySQL, MariaDB, and SQLite) to match the column order defined in the Prisma schema.

🎯 Features

  • Column Synchronization: Create migrations to sync database column order to match Prisma schema field order
  • Migration Fixing: Fix column order in migration files to respect schema field order
  • Database Support: Support for MySQL and MariaDB databases
  • CLI Interface: Easy-to-use command-line interface for all operations

🚀 Installation

npm install prisma-reorder
# or
yarn add prisma-reorder

📋 Supported Databases

✅ MySQL - Full support for column reordering
✅ MariaDB - Full support for column reordering
❌ SQLite - Not supported (limitations in column reordering without table recreation)
❌ PostgreSQL - Not supported (limitations in column reordering)
❌ SQL Server - Not supported (limitations in column reordering)

📋 Commands

1. sync - Reorder Database Columns

The main command that analyzes your Prisma schema and creates a migration to reorder database columns to match the field order.

npx prisma-reorder sync
npx prisma-reorder sync --schema custom/path/schema.prisma
npx prisma-reorder sync --model User Post  # Sync specific models
npx prisma-reorder sync --verbose          # Show detailed output

How it works:

  1. Connects to your database using Prisma
  2. Fetches actual column metadata and order from database tables
  3. Compares with the field order in your Prisma schema
  4. Creates a new migration file with ALTER TABLE statements
  5. Migration follows Prisma's naming convention: [timestamp]_sync_column_order

2. fix-migration - Fix Migration Files

Analyzes migration files and fixes column order issues in ADD COLUMN statements.

npx prisma-reorder fix-migration                              # Check latest migration for column order issues
npx prisma-reorder fix-migration --apply                      # Apply fixes directly to migration file
npx prisma-reorder fix-migration --migrations-dir ./migrations # Custom migrations directory
npx prisma-reorder fix-migration --verbose                    # Show detailed output

How it works:

Given this Prisma schema:

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  bio       String?  // Should be positioned after 'name'
  avatar    String?  // Should be positioned after 'bio'
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

When you have a migration file containing:

ALTER TABLE `User`
    ADD COLUMN `bio` TEXT;
ALTER TABLE `User`
    ADD COLUMN `avatar` VARCHAR(255);

Running npx prisma-reorder fix-migration will detect and fix the positioning:

ALTER TABLE `User`
    ADD COLUMN `bio` TEXT AFTER `name`;
ALTER TABLE `User`
    ADD COLUMN `avatar` VARCHAR(255) AFTER `bio`;

📚 Programmatic API

The Schema Reader module is currently implemented and provides the foundation for all schema analysis operations:

import { SchemaReader, SUPPORTED_PROVIDERS } from 'prisma-reorder';

// Create a schema reader (defaults to prisma/schema.prisma)
const reader = new SchemaReader();

// Validate database support
const validation = await reader.validateSupportedDatabase();
console.log(`Provider: ${validation.provider}`);
console.log(`Supported: ${validation.isSupported}`);

// Get model names
const models = await reader.getModelNames();
console.log('Models:', models); // ['User', 'Post', 'Profile']

// Get field order for a model (only database columns, not relations)
const userFields = await reader.getModelFieldOrder('User');
console.log('User fields:', userFields); // ['id', 'email', 'name', 'createdAt']

Advanced Analysis

// Get complete schema analysis
const analysis = await reader.getSchemaAnalysis();

console.log(`Database: ${analysis.provider}`);
console.log(`Supported: ${analysis.isSupported}`);
console.log(`Models found: ${analysis.models.length}`);

// Analyze each model
analysis.models.forEach((model) => {
  console.log(`\nModel: ${model.name}`);
  model.fields.forEach((field) => {
    const tags = [];
    if (field.isId) tags.push('ID');
    if (field.isUnique) tags.push('UNIQUE');
    if (field.isRelation) tags.push('RELATION');

    console.log(`  ${field.name}: ${field.type} ${tags.join(' ')}`);
  });
});

🛠️ Development

To contribute to this project:

# Clone the repository
git clone <repository-url>
cd prisma-reorder

# Install dependencies
npm install

# Build the project
npm run build

# Test the CLI locally
npx . sync --help

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.