원클릭으로
migrate-db
Create database migration files for all three databases (MySQL, MSSQL, PostgreSQL) when schema changes are needed
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Create database migration files for all three databases (MySQL, MSSQL, PostgreSQL) when schema changes are needed
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Add a new API endpoint with controller, service, and DTOs following OMS patterns
Add a new database entity with migrations for all three databases (MySQL, MSSQL, PostgreSQL)
Add a new mobile page to frontend.h5 using Vant 4 components
Add a new frontend page with proper layout, table, and API integration following OMS UI standards
Audit backend code to ensure all queries properly filter by OrgId for multi-tenant security
Debug and troubleshoot issues in the OMS system with systematic approach
| name | migrate-db |
| description | Create database migration files for all three databases (MySQL, MSSQL, PostgreSQL) when schema changes are needed |
| disable-model-invocation | false |
| allowed-tools | Read, Write, Glob, Bash |
Create SQL migration files for all three supported databases when schema changes are needed.
When the user requests a database schema change (add table, add column, modify column, etc.), create migration files for all three databases.
Check existing migrations to find the next version:
# Check MySQL migrations
ls database/mysql/
# Check MSSQL migrations
ls database/mssql/
# Check PostgreSQL migrations
ls database/postgresql/
Find the highest version number (e.g., V0023) and use the next sequential number (V0024).
CRITICAL: Must create migration files for ALL THREE databases with the SAME version number.
File naming pattern: V{version}_{description}.sql
Example:
database/mysql/V0024_Add_Product_Table.sqldatabase/mssql/V0024_Add_Product_Table.sqldatabase/postgresql/V0024_Add_Product_Table.sqlEach database has different SQL syntax. Use the correct syntax for each:
-- Auto-increment primary key
CREATE TABLE `table_name` (
`Id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`OrgId` BIGINT NOT NULL,
`Name` VARCHAR(200) NOT NULL,
`Description` TEXT,
`Price` DECIMAL(18,2),
`IsActive` TINYINT(1) DEFAULT 1,
`CreatedAt` DATETIME(6) NOT NULL,
`UpdatedAt` DATETIME(6) NOT NULL,
INDEX `IX_table_name_OrgId` (`OrgId`),
INDEX `IX_table_name_Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Add column
ALTER TABLE `table_name` ADD COLUMN `NewColumn` VARCHAR(100) NULL;
-- Modify column
ALTER TABLE `table_name` MODIFY COLUMN `ExistingColumn` VARCHAR(200) NOT NULL;
-- Add index
CREATE INDEX `IX_table_name_Column` ON `table_name` (`Column`);
-- Drop column
ALTER TABLE `table_name` DROP COLUMN `OldColumn`;
-- Identity primary key
CREATE TABLE [table_name] (
[Id] BIGINT IDENTITY(1,1) PRIMARY KEY,
[OrgId] BIGINT NOT NULL,
[Name] NVARCHAR(200) NOT NULL,
[Description] NVARCHAR(MAX),
[Price] DECIMAL(18,2),
[IsActive] BIT DEFAULT 1,
[CreatedAt] DATETIME2 NOT NULL,
[UpdatedAt] DATETIME2 NOT NULL,
INDEX [IX_table_name_OrgId] ([OrgId]),
INDEX [IX_table_name_Name] ([Name])
);
-- Add column
ALTER TABLE [table_name] ADD [NewColumn] NVARCHAR(100) NULL;
-- Modify column
ALTER TABLE [table_name] ALTER COLUMN [ExistingColumn] NVARCHAR(200) NOT NULL;
-- Add index
CREATE INDEX [IX_table_name_Column] ON [table_name] ([Column]);
-- Drop column
ALTER TABLE [table_name] DROP COLUMN [OldColumn];
-- Serial primary key
CREATE TABLE "table_name" (
"Id" BIGSERIAL PRIMARY KEY,
"OrgId" BIGINT NOT NULL,
"Name" VARCHAR(200) NOT NULL,
"Description" TEXT,
"Price" DECIMAL(18,2),
"IsActive" BOOLEAN DEFAULT true,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL
);
CREATE INDEX "IX_table_name_OrgId" ON "table_name" ("OrgId");
CREATE INDEX "IX_table_name_Name" ON "table_name" ("Name");
-- Add column
ALTER TABLE "table_name" ADD COLUMN "NewColumn" VARCHAR(100) NULL;
-- Modify column
ALTER TABLE "table_name" ALTER COLUMN "ExistingColumn" TYPE VARCHAR(200);
ALTER TABLE "table_name" ALTER COLUMN "ExistingColumn" SET NOT NULL;
-- Add index
CREATE INDEX "IX_table_name_Column" ON "table_name" ("Column");
-- Drop column
ALTER TABLE "table_name" DROP COLUMN "OldColumn";
| C# Type | MySQL | SQL Server | PostgreSQL |
|---|---|---|---|
| long | BIGINT | BIGINT | BIGINT |
| int | INT | INT | INTEGER |
| string | VARCHAR(n) | NVARCHAR(n) | VARCHAR(n) |
| string (long) | TEXT | NVARCHAR(MAX) | TEXT |
| decimal | DECIMAL(18,2) | DECIMAL(18,2) | DECIMAL(18,2) |
| bool | TINYINT(1) | BIT | BOOLEAN |
| DateTime | DATETIME(6) | DATETIME2 | TIMESTAMP |
| Guid | CHAR(36) | UNIQUEIDENTIFIER | UUID |
All business entities should include:
Id - Primary key (auto-increment/identity/serial)OrgId - Organization ID for multi-tenant isolation (REQUIRED)CreatedAt - Creation timestampUpdatedAt - Last update timestampAlways add an index on OrgId for query performance.
Idempotent: Migrations should be safe to run multiple times
IF NOT EXISTS for CREATE TABLEBackward Compatible: Avoid breaking changes
Data Migration: If changing data structure
Indexes: Add indexes for:
Comments: Add comments explaining complex migrations
Scenario: Add a new Product table
MySQL (database/mysql/V0024_Add_Product_Table.sql):
-- Add Product table for product management
CREATE TABLE IF NOT EXISTS `products` (
`Id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`OrgId` BIGINT NOT NULL,
`Name` VARCHAR(200) NOT NULL,
`Code` VARCHAR(50) NOT NULL,
`Description` TEXT,
`Price` DECIMAL(18,2) NOT NULL DEFAULT 0,
`Stock` INT NOT NULL DEFAULT 0,
`IsActive` TINYINT(1) NOT NULL DEFAULT 1,
`CreatedAt` DATETIME(6) NOT NULL,
`UpdatedAt` DATETIME(6) NOT NULL,
INDEX `IX_products_OrgId` (`OrgId`),
INDEX `IX_products_Code` (`Code`),
INDEX `IX_products_Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
SQL Server (database/mssql/V0024_Add_Product_Table.sql):
-- Add Product table for product management
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'products')
BEGIN
CREATE TABLE [products] (
[Id] BIGINT IDENTITY(1,1) PRIMARY KEY,
[OrgId] BIGINT NOT NULL,
[Name] NVARCHAR(200) NOT NULL,
[Code] NVARCHAR(50) NOT NULL,
[Description] NVARCHAR(MAX),
[Price] DECIMAL(18,2) NOT NULL DEFAULT 0,
[Stock] INT NOT NULL DEFAULT 0,
[IsActive] BIT NOT NULL DEFAULT 1,
[CreatedAt] DATETIME2 NOT NULL,
[UpdatedAt] DATETIME2 NOT NULL,
INDEX [IX_products_OrgId] ([OrgId]),
INDEX [IX_products_Code] ([Code]),
INDEX [IX_products_Name] ([Name])
);
END
PostgreSQL (database/postgresql/V0024_Add_Product_Table.sql):
-- Add Product table for product management
CREATE TABLE IF NOT EXISTS "products" (
"Id" BIGSERIAL PRIMARY KEY,
"OrgId" BIGINT NOT NULL,
"Name" VARCHAR(200) NOT NULL,
"Code" VARCHAR(50) NOT NULL,
"Description" TEXT,
"Price" DECIMAL(18,2) NOT NULL DEFAULT 0,
"Stock" INTEGER NOT NULL DEFAULT 0,
"IsActive" BOOLEAN NOT NULL DEFAULT true,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL
);
CREATE INDEX IF NOT EXISTS "IX_products_OrgId" ON "products" ("OrgId");
CREATE INDEX IF NOT EXISTS "IX_products_Code" ON "products" ("Code");
CREATE INDEX IF NOT EXISTS "IX_products_Name" ON "products" ("Name");
After creating migrations:
If needed, create rollback migrations with the same version:
V0024_Add_Product_Table_Rollback.sqlInclude DROP TABLE or ALTER TABLE statements to reverse the changes.