hmu.ai
Back to Builder Agents
Builder Agent

Hyper-Focused Database Migration Script (SQL) for Freelance Developers

Stop doing this manually. Deploy an autonomous Builder agent to handle database migration script (sql) entirely in the background.

Zero-Shot Command Setup

Generate a SQL migration script from an existing PostgreSQL schema with tables 'users' (id, name, email) and 'products' (id, name, price) to a new schema where 'users' gains a 'created_at' (timestamp with default NOW()) column and 'products' has 'description' (TEXT NULLABLE) added, and 'price' becomes 'decimal(10,2)'. Assume version 1.0 to 1.1.

Core Benefits & ROI

  • Ensures data integrity during schema changes
  • Automates tedious and error-prone manual migration tasks
  • Supports schema versioning for better project management
  • Reduces downtime during database updates
  • Compatible with various SQL database systems
  • Provides a clear audit trail of schema evolution

Ecosystem Integration

This "Builder" agent is fundamental to the **Development** and **Maintenance** pillars. During development, it provides the necessary scripts to evolve the database schema as new features are built, ensuring consistency across environments. In maintenance, it facilitates safe and repeatable updates to production databases, minimizing risk and downtime. By generating robust SQL, it directly supports the overall reliability and scalability of the application, feeding into successful **Deployment** and preventing future technical debt.

Sample Output

```sql -- Migration Script: v1.0 to v1.1 -- Date: 2023-10-27 -- Database: PostgreSQL -- START TRANSACTION; -- Consider using transactions for atomicity if your client supports it -- 1. Add 'created_at' column to 'users' table ALTER TABLE users ADD COLUMN created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -- Add comments for documentation COMMENT ON COLUMN users.created_at IS 'Timestamp when the user record was created.'; -- 2. Add 'description' column to 'products' table ALTER TABLE products ADD COLUMN description TEXT NULL; COMMENT ON COLUMN products.description IS 'Detailed description of the product.'; -- 3. Modify 'price' column in 'products' table to DECIMAL(10,2) -- Note: This assumes the existing 'price' column can be cast to DECIMAL. -- If not, a more complex migration involving a temporary column, data transfer, and renaming might be needed. ALTER TABLE products ALTER COLUMN price TYPE DECIMAL(10,2); COMMENT ON COLUMN products.price IS 'Price of the product, stored as a decimal with 2 decimal places.'; -- Optional: If you use a migrations table to track schema versions -- INSERT INTO schema_migrations (version, description, applied_at) -- VALUES ('1.1', 'Add created_at to users, description to products, modify price type', NOW()); -- COMMIT; -- Commit the transaction if used ```

Frequently Asked Questions

What if I need to migrate data as part of the schema change?

This agent primarily focuses on DDL (Data Definition Language) for schema changes. If data migration (DML - Data Manipulation Language) is required (e.g., populating a new column based on existing data, or transforming data types with complex logic), you would describe those requirements, and the agent can generate `UPDATE` or `INSERT` statements to be included in the same script.

Is this script safe for production databases?

The generated script aims for best practices, but it's crucial to always test migration scripts thoroughly in a staging or development environment that mirrors your production setup. For critical changes, consider using transactions, taking database backups, and reviewing the script manually for potential edge cases specific to your data.