Skip to content

Commit 585c225

Browse files
author
bedford.scott
committed
Add Phase 1 deployment guide with testing instructions
1 parent f44e043 commit 585c225

File tree

1 file changed

+354
-0
lines changed

1 file changed

+354
-0
lines changed

PHASE1_DEPLOYMENT.md

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
# Phase 1 Deployment Guide: Database Schema & Infrastructure
2+
3+
## Overview
4+
Phase 1 adds the database foundation for search, filtering, and tagging features:
5+
- AI Provider field (7 provider options)
6+
- Many-to-many category table (multiple categories per prompt)
7+
- Migration script for existing data
8+
9+
## Prerequisites
10+
- ServiceNow instance access with admin privileges
11+
- ServiceNow Studio access
12+
- Access to the ServiceNow GenAI Prompt Library application scope
13+
14+
---
15+
16+
## Deployment Steps
17+
18+
### Step 1: Pull Latest Changes from GitHub
19+
20+
If you're using ServiceNow Source Control integration:
21+
1. Navigate to **Studio** in your ServiceNow instance
22+
2. Open the **ServiceNow GenAI Prompt Library** application
23+
3. Click **Source Control** > **Pull from Repository**
24+
4. This will import all the new XML files automatically
25+
26+
**OR** If manually importing:
27+
1. Download the following files from the repository
28+
2. Import them via **System Update Sets** or **Studio**
29+
30+
---
31+
32+
### Step 2: Verify Schema Creation
33+
34+
#### 2.1 Check AI Provider Field
35+
1. Navigate to **System Definition > Tables**
36+
2. Search for table: `x_snc_ehd_servic_0_prompt`
37+
3. Open the table and go to **Columns** tab
38+
4. Verify field `ai_provider` exists (String, max_length: 40)
39+
40+
#### 2.2 Check AI Provider Choices
41+
1. Navigate to **System Definition > Choice Lists**
42+
2. Search for table: `x_snc_ehd_servic_0_prompt`, element: `ai_provider`
43+
3. Verify 7 choices exist:
44+
- ✅ claude → "Claude (Anthropic)"
45+
- ✅ github_copilot → "GitHub Copilot"
46+
- ✅ ms_copilot → "Microsoft Copilot"
47+
- ✅ chatgpt → "ChatGPT (OpenAI)"
48+
- ✅ gemini → "Gemini (Google)"
49+
- ✅ now_assist → "Now Assist (ServiceNow)"
50+
- ✅ other → "Other AI Provider"
51+
52+
#### 2.3 Check M2M Category Table
53+
1. Navigate to **System Definition > Tables**
54+
2. Search for: `x_snc_ehd_servic_0_prompt_category_m2m`
55+
3. Verify table exists with fields:
56+
- `prompt` (Reference to x_snc_ehd_servic_0_prompt)
57+
- `category` (Reference to x_snc_ehd_servic_0_category)
58+
59+
---
60+
61+
### Step 3: Run Migration Script
62+
63+
This script migrates existing single-category relationships to the new many-to-many table.
64+
65+
#### 3.1 Check Migration Status (Before)
66+
1. Navigate to **System Definition > Scripts - Background**
67+
2. Run this script to check current state:
68+
69+
```javascript
70+
// Check migration status BEFORE running migration
71+
var migrator = new x_snc_ehd_servic_0.MigratePromptCategories();
72+
var status = migrator.checkStatus();
73+
74+
gs.info('=== MIGRATION STATUS (BEFORE) ===');
75+
gs.info('Total Active Prompts: ' + status.totalPrompts);
76+
gs.info('Prompts with Category: ' + status.promptsWithCategory);
77+
gs.info('M2M Records: ' + status.m2mRecords);
78+
gs.info('Prompts Needing Migration: ' + status.promptsNotInM2M.length);
79+
80+
if (status.promptsNotInM2M.length > 0) {
81+
gs.info('Sample prompts needing migration: ' + status.promptsNotInM2M.slice(0, 10).join(', '));
82+
}
83+
```
84+
85+
**Expected Output:**
86+
- Should show your total prompts and how many have categories
87+
- M2M Records should be 0 (or very low if some already exist)
88+
- You should see prompts that need migration
89+
90+
#### 3.2 Run Migration
91+
Once you've verified the status, run the migration:
92+
93+
```javascript
94+
// Run the migration
95+
var migrator = new x_snc_ehd_servic_0.MigratePromptCategories();
96+
var results = migrator.migrate();
97+
98+
gs.info('=== MIGRATION RESULTS ===');
99+
gs.info('Total Prompts Processed: ' + results.totalPrompts);
100+
gs.info('Successfully Migrated: ' + results.migratedPrompts);
101+
gs.info('Prompts Without Category: ' + results.promptsWithoutCategory);
102+
gs.info('Duplicates Skipped: ' + results.duplicatesSkipped);
103+
104+
if (results.errors.length > 0) {
105+
gs.error('Errors occurred: ' + results.errors.length);
106+
results.errors.forEach(function(err) {
107+
gs.error(' - ' + err);
108+
});
109+
} else {
110+
gs.info('Migration completed successfully with no errors!');
111+
}
112+
```
113+
114+
**Expected Output:**
115+
- Successfully Migrated should equal Prompts with Category
116+
- Errors should be empty
117+
- You'll see progress messages every 100 prompts
118+
119+
#### 3.3 Verify Migration (After)
120+
Run the status check again to verify migration completed:
121+
122+
```javascript
123+
// Verify migration completed successfully
124+
var migrator = new x_snc_ehd_servic_0.MigratePromptCategories();
125+
var status = migrator.checkStatus();
126+
127+
gs.info('=== MIGRATION STATUS (AFTER) ===');
128+
gs.info('Total Active Prompts: ' + status.totalPrompts);
129+
gs.info('Prompts with Category: ' + status.promptsWithCategory);
130+
gs.info('M2M Records: ' + status.m2mRecords);
131+
gs.info('Prompts Still Needing Migration: ' + status.promptsNotInM2M.length);
132+
133+
// Validation
134+
if (status.m2mRecords === status.promptsWithCategory) {
135+
gs.info('✅ SUCCESS: All prompts with categories have been migrated!');
136+
} else {
137+
gs.warn('⚠️ WARNING: M2M record count does not match prompts with categories');
138+
gs.warn('This could be normal if some prompts have multiple categories already');
139+
}
140+
141+
if (status.promptsNotInM2M.length === 0) {
142+
gs.info('✅ SUCCESS: No prompts remaining to migrate!');
143+
} else {
144+
gs.warn('⚠️ WARNING: ' + status.promptsNotInM2M.length + ' prompts still need migration');
145+
gs.warn('Sample: ' + status.promptsNotInM2M.slice(0, 10).join(', '));
146+
}
147+
```
148+
149+
---
150+
151+
### Step 4: Manual Verification
152+
153+
#### 4.1 Test AI Provider Field
154+
1. Navigate to **ServiceNow GenAI Prompt Library > Prompts**
155+
2. Open any prompt record
156+
3. Scroll to find the **AI Provider** field
157+
4. Verify the dropdown shows all 7 provider options
158+
5. Select a provider and save
159+
6. Verify it saves correctly
160+
161+
#### 4.2 Test M2M Category Table
162+
1. Navigate to **System Definition > Tables & Columns**
163+
2. Search for and open: `x_snc_ehd_servic_0_prompt_category_m2m`
164+
3. Click **Show records in this table**
165+
4. Verify you see records with prompt and category references
166+
5. Pick a few random records and verify:
167+
- Prompt reference is valid
168+
- Category reference is valid
169+
- They match the original prompt's category
170+
171+
#### 4.3 Spot Check Prompts
172+
1. Navigate to **ServiceNow GenAI Prompt Library > Prompts**
173+
2. Open 3-5 random prompts
174+
3. For each prompt:
175+
- Note the category in the `category` field
176+
- Navigate to the **Related Lists** at the bottom
177+
- Look for **Prompt Category M2M** related list
178+
- Verify the related list shows a matching category entry
179+
180+
---
181+
182+
### Step 5: Database Indexes (Optional but Recommended)
183+
184+
For better performance, add indexes on the new fields:
185+
186+
```javascript
187+
// Note: This may require elevated permissions
188+
// You may need to work with your ServiceNow admin to create these indexes
189+
190+
// Create index on ai_provider field
191+
// Navigate to: System Definition > Tables
192+
// Open x_snc_ehd_servic_0_prompt
193+
// Go to Database Indexes tab
194+
// Create new index on 'ai_provider' column
195+
196+
// Create index on m2m prompt field
197+
// Navigate to: System Definition > Tables
198+
// Open x_snc_ehd_servic_0_prompt_category_m2m
199+
// Go to Database Indexes tab
200+
// Create new index on 'prompt' column
201+
202+
// Create index on m2m category field
203+
// Create another index on 'category' column
204+
```
205+
206+
**OR** via background script (if you have permissions):
207+
208+
```javascript
209+
// WARNING: Only run if you have database admin permissions
210+
// This creates indexes for better query performance
211+
212+
var indexHelper = new GlideDBObjectManager();
213+
214+
// Index on prompt table - ai_provider field
215+
gs.info('Creating index on x_snc_ehd_servic_0_prompt.ai_provider...');
216+
// Note: Actual index creation requires admin privileges
217+
// Consult your DBA or use ServiceNow UI method above
218+
219+
gs.info('Phase 1 database indexes should be created via ServiceNow UI');
220+
gs.info('See deployment guide for instructions');
221+
```
222+
223+
---
224+
225+
## Testing Checklist
226+
227+
After deployment, verify:
228+
229+
- [ ] **AI Provider field** appears on prompt records
230+
- [ ] **All 7 provider choices** are available in the dropdown
231+
- [ ] **M2M table** created successfully (x_snc_ehd_servic_0_prompt_category_m2m)
232+
- [ ] **Migration script** executed without errors
233+
- [ ] **M2M record count** matches prompts with categories
234+
- [ ] **Spot check**: 3-5 random prompts have correct m2m entries
235+
- [ ] **Can manually select** AI provider on a prompt and save
236+
- [ ] **No errors** in system logs related to new schema
237+
- [ ] **(Optional)** Database indexes created for performance
238+
239+
---
240+
241+
## Rollback Plan (If Needed)
242+
243+
If issues occur, you can rollback:
244+
245+
### Option 1: Remove via Update Set
246+
1. Navigate to **System Update Sets > Retrieved Update Sets**
247+
2. Find the update set containing Phase 1 changes
248+
3. Select **Back out this update set**
249+
4. This will remove the new fields and table
250+
251+
### Option 2: Manual Removal
252+
1. **Delete m2m table:**
253+
- Navigate to **System Definition > Tables**
254+
- Find `x_snc_ehd_servic_0_prompt_category_m2m`
255+
- Delete the table (this also deletes all m2m records)
256+
257+
2. **Remove AI Provider field:**
258+
- Navigate to **System Definition > Tables**
259+
- Open `x_snc_ehd_servic_0_prompt`
260+
- Find `ai_provider` field in Columns tab
261+
- Delete the field
262+
263+
3. **Remove choices:**
264+
- Navigate to **System Definition > Choice Lists**
265+
- Search for `ai_provider` choices
266+
- Delete all 7 choice records
267+
268+
4. **Remove migration script:**
269+
- Navigate to **System Definition > Script Includes**
270+
- Find `MigratePromptCategories`
271+
- Delete the script include
272+
273+
**Note:** Rollback is safe because:
274+
- No existing data is modified (category field remains unchanged)
275+
- M2M table is new and doesn't affect existing functionality
276+
- AI Provider field is optional (empty values are allowed)
277+
278+
---
279+
280+
## Troubleshooting
281+
282+
### Issue: Migration script not found
283+
**Error:** `x_snc_ehd_servic_0.MigratePromptCategories is not defined`
284+
285+
**Solution:**
286+
1. Verify the script include was imported
287+
2. Navigate to **System Definition > Script Includes**
288+
3. Search for: `MigratePromptCategories`
289+
4. Verify it's in the correct scope: `x_snc_ehd_servic_0`
290+
291+
### Issue: M2M table not found
292+
**Error:** `Table x_snc_ehd_servic_0_prompt_category_m2m is invalid`
293+
294+
**Solution:**
295+
1. Check if table was created in correct scope
296+
2. Navigate to **System Definition > Tables**
297+
3. Search for: `x_snc_ehd_servic_0_prompt_category_m2m`
298+
4. If missing, re-import the table XML file
299+
300+
### Issue: Duplicate m2m records
301+
**Symptom:** Migration reports duplicates skipped
302+
303+
**Solution:**
304+
- This is normal if you run migration multiple times
305+
- The script checks for existing records and skips them
306+
- No action needed
307+
308+
### Issue: Some prompts not migrated
309+
**Symptom:** `promptsNotInM2M.length > 0` after migration
310+
311+
**Solution:**
312+
1. Check if those prompts have null category (expected)
313+
2. Verify prompts are active
314+
3. Re-run migration script (safe to run multiple times)
315+
316+
---
317+
318+
## Next Steps
319+
320+
Once Phase 1 is deployed, tested, and verified:
321+
322+
1. **Communicate to users:** New AI Provider field is available (optional)
323+
2. **Monitor for issues:** Check system logs for any errors
324+
3. **Proceed to Phase 2:** Basic Search Functionality
325+
- Search box in library widget
326+
- Keyword search implementation
327+
- Clear filters functionality
328+
329+
---
330+
331+
## Support
332+
333+
If you encounter issues:
334+
1. Check ServiceNow system logs: **System Logs > System Log > All**
335+
2. Review error messages from migration script
336+
3. Verify source control sync completed successfully
337+
4. Check that all XML files were imported
338+
339+
---
340+
341+
## Summary
342+
343+
Phase 1 adds the database foundation with:
344+
- ✅ AI Provider field with 7 provider choices
345+
- ✅ Many-to-many category table for multiple categories
346+
- ✅ Migration script to populate m2m table
347+
- ✅ Backwards compatibility maintained
348+
- ✅ No breaking changes to existing functionality
349+
350+
**Total Time:** ~15-30 minutes (including verification)
351+
**Risk Level:** Low (no existing data modified, optional fields)
352+
**Rollback:** Available and straightforward
353+
354+
Good luck with the deployment! 🚀

0 commit comments

Comments
 (0)