-
Notifications
You must be signed in to change notification settings - Fork 0
removed coop and intern from role names #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gpalmer27
wants to merge
2
commits into
main
Choose a base branch
from
delete-coop-and-intern
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /** | ||
| * Data migration: strip the keywords "coop", "co-op", "intern", and | ||
| * "internship" (case-insensitive) out of every role title, then regenerate | ||
| * the role's slug from the cleaned title. | ||
| * | ||
| * Usage (run from packages/db): | ||
| * pnpm strip-role-keywords # dry run – prints what WOULD change | ||
| * pnpm strip-role-keywords --apply # actually writes the changes | ||
| */ | ||
| import { eq } from "drizzle-orm"; | ||
|
|
||
| import { db } from "../client"; | ||
| import { Role } from "../schema"; | ||
|
|
||
| const APPLY = process.argv.includes("--apply"); | ||
|
|
||
| const KEYWORD_RE = /\b(?:internship|intern|co-?op)\b/gi; | ||
|
|
||
| const EDGE_JUNK_RE = /^[\s\-/,&|·•:]+|[\s\-/,&|·•:]+$/g; | ||
|
|
||
| function stripKeywords(title: string): string { | ||
| return title | ||
| .replace(KEYWORD_RE, " ") | ||
| .replace(/\s+/g, " ") | ||
| .trim() | ||
| .replace(EDGE_JUNK_RE, "") | ||
| .trim(); | ||
| } | ||
|
|
||
| function createSlug(text: string): string { | ||
| return text | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9\s-]/g, "") | ||
| .replace(/\s+/g, "-") | ||
| .replace(/-+/g, "-") | ||
| .trim(); | ||
| } | ||
|
|
||
| function generateUniqueSlug( | ||
| baseSlug: string, | ||
| existingSlugs: Set<string>, | ||
| ): string { | ||
| let slug = baseSlug; | ||
| let counter = 2; | ||
| while (existingSlugs.has(slug)) { | ||
| slug = `${baseSlug}-${counter}`; | ||
| counter++; | ||
| } | ||
| return slug; | ||
| } | ||
|
|
||
| async function main() { | ||
| console.log( | ||
| `\nStripping role keywords — ${APPLY ? "APPLY mode (writing changes)" : "DRY RUN (no changes written)"}\n`, | ||
| ); | ||
|
|
||
| const roles = await db.query.Role.findMany({ | ||
| columns: { id: true, title: true, slug: true, companyId: true }, | ||
| }); | ||
|
|
||
| // Track slugs already in use per company so regenerated slugs stay unique | ||
| // within the company, accounting for both untouched and newly-written rows. | ||
| const slugsByCompany = new Map<string, Set<string>>(); | ||
| for (const r of roles) { | ||
| if (!slugsByCompany.has(r.companyId)) | ||
| slugsByCompany.set(r.companyId, new Set()); | ||
| slugsByCompany.get(r.companyId)?.add(r.slug); | ||
| } | ||
|
|
||
| let changed = 0; | ||
| let skippedEmpty = 0; | ||
|
|
||
| for (const role of roles) { | ||
| const newTitle = stripKeywords(role.title); | ||
|
|
||
| if (newTitle === role.title) continue; | ||
|
|
||
| if (newTitle.length === 0) { | ||
| skippedEmpty++; | ||
| console.warn( | ||
| ` ⚠️ SKIPPED (would be empty): "${role.title}" [role ${role.id}]`, | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| const companySlugs = slugsByCompany.get(role.companyId); | ||
| if (!companySlugs) { | ||
| throw new Error(`Missing slug set for company ${role.companyId}`); | ||
| } | ||
| companySlugs.delete(role.slug); | ||
| const newSlug = generateUniqueSlug(createSlug(newTitle), companySlugs); | ||
| companySlugs.add(newSlug); | ||
|
|
||
| changed++; | ||
| console.log( | ||
| ` "${role.title}" -> "${newTitle}" (slug: ${role.slug} -> ${newSlug})`, | ||
| ); | ||
|
|
||
| if (APPLY) { | ||
| await db | ||
| .update(Role) | ||
| .set({ title: newTitle, slug: newSlug }) | ||
| .where(eq(Role.id, role.id)); | ||
| } | ||
| } | ||
|
|
||
| console.log( | ||
| `\nScanned ${roles.length} roles — ${changed} ${APPLY ? "updated" : "to update"}${ | ||
| skippedEmpty ? `, ${skippedEmpty} skipped (would be empty)` : "" | ||
| }.`, | ||
| ); | ||
| if (!APPLY && changed > 0) { | ||
| console.log(`Re-run with --apply to write these changes.\n`); | ||
| } | ||
| } | ||
|
|
||
| main() | ||
| .then(() => process.exit(0)) | ||
| .catch((err) => { | ||
| console.error("strip-role-keywords failed:", err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so like should devs just run pnpm db:strip-role-keywords then? does this apply the changes cause wouldn't you need the --apply instead of just
pnpm with-env tsx src/scripts/strip-role-keywords.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pnpm strip-role-keywords --apply