ClaudeForge database schema and migration generator for PostgreSQL, MySQL, MongoDB with ORM integration.
/plugin marketplace add claudeforge/marketplace/plugin install schema-generator@claudeforge-marketplaceClaudeForge intelligent database schema design and migration system that creates optimized, scalable database architectures with automated migration generation and comprehensive ORM integration across multiple database platforms.
Transform database design from manual schema creation to intelligent automation that ensures data integrity, performance optimization, and seamless migration management across relational and NoSQL databases.
/schema-generator [database] [options]
Target: $ARGUMENTS (if specified, otherwise analyze current scope)
PostgreSQL Schema Design:
/schema-generator postgres --entity=User,Post,Comment --relations=true
Generates PostgreSQL schema with:
MySQL Schema Design:
/schema-generator mysql --entity=Product --storage-engine=InnoDB
Creates MySQL schema including:
MongoDB Schema Design:
/schema-generator mongodb --collection=Order --validation=strict
Designs MongoDB schema with:
Prisma Schema Generation:
/schema-generator prisma --datasource=postgresql --models=User,Profile
Generates Prisma schema with:
TypeORM Entity Generation:
/schema-generator typeorm --database=mysql --decorators=true
Creates TypeORM entities including:
Sequelize Model Generation:
/schema-generator sequelize --dialect=postgres --associations=true
Generates Sequelize models with:
Version-Based Migrations:
/schema-generator migrate --type=versioned --from=v1 --to=v2
Creates versioned migrations with:
Timestamp-Based Migrations:
/schema-generator migrate --type=timestamp --auto-generate=true
Generates timestamp migrations including:
Schema Synchronization:
/schema-generator sync --mode=safe --backup=true
Performs schema synchronization with:
-- Users table with advanced PostgreSQL features
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) NOT NULL UNIQUE,
username VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
profile JSONB DEFAULT '{}',
roles TEXT[] DEFAULT ARRAY['user'],
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE,
CONSTRAINT email_format CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'),
CONSTRAINT username_length CHECK (LENGTH(username) >= 3)
);
-- Composite index for common queries
CREATE INDEX idx_users_email_active ON users(email) WHERE deleted_at IS NULL;
-- GIN index for JSONB queries
CREATE INDEX idx_users_profile ON users USING GIN(profile);
-- Full-text search index
CREATE INDEX idx_users_search ON users USING GIN(to_tsvector('english', username || ' ' || email));
-- Trigger for automatic updated_at
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER update_users_updated_at
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "fullTextIndex"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
email String @unique @db.VarChar(255)
username String @unique @db.VarChar(50)
passwordHash String @map("password_hash") @db.VarChar(255)
profile Json @default("{}")
roles String[] @default(["user"])
posts Post[]
comments Comment[]
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
deletedAt DateTime? @map("deleted_at") @db.Timestamptz
@@index([email], where: { deletedAt: null })
@@map("users")
}
model Post {
id String @id @default(uuid())
title String @db.VarChar(255)
slug String @unique @db.VarChar(255)
content String @db.Text
published Boolean @default(false)
authorId String @map("author_id")
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
comments Comment[]
tags Tag[]
viewCount Int @default(0) @map("view_count")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
publishedAt DateTime? @map("published_at") @db.Timestamptz
@@index([authorId])
@@index([slug])
@@index([published, createdAt])
@@map("posts")
}
model Comment {
id String @id @default(uuid())
content String @db.Text
postId String @map("post_id")
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
authorId String @map("author_id")
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
parentId String? @map("parent_id")
parent Comment? @relation("CommentReplies", fields: [parentId], references: [id])
replies Comment[] @relation("CommentReplies")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
@@index([postId])
@@index([authorId])
@@index([parentId])
@@map("comments")
}
model Tag {
id String @id @default(uuid())
name String @unique @db.VarChar(50)
slug String @unique @db.VarChar(50)
posts Post[]
@@map("tags")
}
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, OneToMany, ManyToOne, JoinColumn, Index } from 'typeorm';
@Entity('users')
@Index('idx_users_email_active', ['email'], { where: '"deleted_at" IS NULL' })
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'varchar', length: 255, unique: true })
@Index()
email: string;
@Column({ type: 'varchar', length: 50, unique: true })
username: string;
@Column({ name: 'password_hash', type: 'varchar', length: 255 })
passwordHash: string;
@Column({ type: 'jsonb', default: {} })
profile: Record<string, any>;
@Column({ type: 'text', array: true, default: () => "ARRAY['user']" })
roles: string[];
@OneToMany(() => Post, post => post.author)
posts: Post[];
@OneToMany(() => Comment, comment => comment.author)
comments: Comment[];
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
updatedAt: Date;
@DeleteDateColumn({ name: 'deleted_at', type: 'timestamptz' })
deletedAt?: Date;
}
@Entity('posts')
@Index('idx_posts_author', ['authorId'])
@Index('idx_posts_published_created', ['published', 'createdAt'])
export class Post {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'varchar', length: 255 })
title: string;
@Column({ type: 'varchar', length: 255, unique: true })
@Index()
slug: string;
@Column({ type: 'text' })
content: string;
@Column({ type: 'boolean', default: false })
published: boolean;
@Column({ name: 'author_id', type: 'uuid' })
authorId: string;
@ManyToOne(() => User, user => user.posts, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'author_id' })
author: User;
@OneToMany(() => Comment, comment => comment.post)
comments: Comment[];
@Column({ name: 'view_count', type: 'int', default: 0 })
viewCount: number;
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
updatedAt: Date;
@Column({ name: 'published_at', type: 'timestamptz', nullable: true })
publishedAt?: Date;
}
-- CreateTable: Users
CREATE TABLE "users" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"email" VARCHAR(255) NOT NULL,
"username" VARCHAR(50) NOT NULL,
"password_hash" VARCHAR(255) NOT NULL,
"profile" JSONB NOT NULL DEFAULT '{}',
"roles" TEXT[] DEFAULT ARRAY['user']::TEXT[],
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ NOT NULL,
"deleted_at" TIMESTAMPTZ,
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");
CREATE INDEX "users_email_idx" ON "users"("email") WHERE "deleted_at" IS NULL;
CREATE INDEX "users_profile_idx" ON "users" USING GIN ("profile");
-- AddColumn: Add new column with default
ALTER TABLE "users" ADD COLUMN "last_login" TIMESTAMPTZ;
-- AlterColumn: Change column type
ALTER TABLE "users" ALTER COLUMN "username" TYPE VARCHAR(100);
-- RenameColumn: Rename column safely
ALTER TABLE "users" RENAME COLUMN "password_hash" TO "hashed_password";
ClaudeForge Schema Generator - Enterprise-grade database schema design with intelligent automation, comprehensive ORM integration, and seamless migration management across all major database platforms.