Skip to content
Notifications
Clear all

Step-by-step: Creating a custom prompt for database migration scripts.

4 Posts
4 Users
0 Reactions
3 Views
(@lisa_m_ops)
Trusted Member
Joined: 4 months ago
Posts: 32
Topic starter   [#7157]

Alright, so I've been living in Salesforce-to-Snowflake migration data for the past quarter, and one of the biggest time-savers wasn't a fancy tool—it was a well-structured prompt for our LLM (we're using Cline). Getting the prompt right for generating database migration scripts is all about specificity. A vague prompt gives you unusable code; a precise one is like having another senior engineer on the team.

Here’s the step-by-step framework I landed on, which cut our script generation review time by about 70%. It's all about feeding the model the context it *actually* needs.

**First, define your core structure.** I always start the prompt with these non-negotiables:
- Language/Syntax (e.g., "Write a Snowflake SQL DDL script")
- Source and Target systems (e.g., "Migrate from Salesforce Production to Snowflake RAW schema")
- Specific objects/tables in scope
- Key transformation rules (e.g., "Map Salesforce 18-character ID to VARCHAR, all TIMESTAMP fields to TIMESTAMP_NTZ")

**Then, inject your business logic and data quality rules.** This is where the ROI gets real. I include:
- Handling of soft deletes (e.g., "WHERE IsDeleted = FALSE")
- Custom field mappings from our internal data dictionary
- Naming convention enforcement (e.g., "All table names must be lowercase and use underscores")
- Any primary key or foreign key constraints we've agreed upon for this phase

**A concrete example from our last batch:**
I prompted Cline with something like:
> "Generate a migration script for the Opportunity, Account, and User objects. Source: Salesforce. Target: Snowflake. Transformations: Convert Currency fields to NUMBER(38,2), convert all DATE fields to DATE, exclude any records where the custom field 'Migration_Exclude__c' is true. Include a comment line for each major section. Output should be a single, runnable SQL script."

The output was clean, followed our standards, and required only minor tweaks for edge cases we hadn't specified. The key is treating the prompt like a requirements doc—the more you put in, the more accurate the output.

Has anyone else fine-tuned a similar prompt for data pipeline work? I'm curious how you're handling more complex merges or incremental load logic.


Show me the pipeline.


   
Quote
(@cloud_cost_hawk)
Estimable Member
Joined: 1 month ago
Posts: 73
 

That 70% reduction in review time is solid, but have you factored in the runtime cost of those generated scripts? I've seen teams optimize the prompt but forget to optimize the code it produces.

Your point about key transformation rules is critical, but you need to add a rule for data volume and execution strategy. An LLM will happily write a script that does a full table scan on a 500GB Salesforce object in Snowflake. For migration scripts, always specify:
- Use warehouse size (e.g., X-SMALL for dev, MEDIUM for initial load)
- Explicitly add `COPY GRANTS` or `CREATE OR REPLACE` clauses to avoid orphaned privileges
- Instruct it to batch large data moves and avoid single, massive transactions

Without that, your efficient prompt leads to a script that burns $500 in Snowflake credits in an hour because it over-provisions. The cost of the code execution often dwarfs the cost of generating it.


cost optimization, not cost cutting


   
ReplyQuote
(@markr)
Eminent Member
Joined: 1 week ago
Posts: 21
 

Good point on execution cost. Most prompts ignore runtime economics entirely.

You missed one critical instruction, though: explicit DATE range for incremental loads. Without it, the model will default to `WHERE TRUE` on your largest timestamp column. That's a guaranteed full scan.

Add that to your batching rule and you'll cut 90% of the cost waste, not just 50%.


Data > Marketing


   
ReplyQuote
(@jacksonw)
Estimable Member
Joined: 1 week ago
Posts: 63
 

That `WHERE TRUE` default is such a sneaky trap. I'm curious, how do you actually structure that date range instruction in the prompt? Do you hardcode a specific date, or do you tell the model to prompt the user for it? I can see hardcoding making the script brittle between dev and prod runs.


not a buyer, just a nerd


   
ReplyQuote