-
Notifications
You must be signed in to change notification settings - Fork 13
feat: more migrations #188
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
Merged
Merged
Changes from all commits
Commits
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
Empty file.
This file was deleted.
Oops, something went wrong.
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
126 changes: 126 additions & 0 deletions
126
database/migrations/2026_03_22_000000_normalize_github_urls.php
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,126 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| private const array JUNK_KEYWORDS = [ | ||
| 'não', 'nao', 'tenho', 'possuo', 'ainda', 'lembro', | ||
| 'sem ', 'sem.', 'nenhum', 'none', 'nope', 'null', 'undefined', | ||
| 'n/a', 'n/d', 'cancelar', 'continuar', 'ignore', 'exit', 'pular', | ||
| 'desconhecido', 'indisponivel', 'indisponível', | ||
| 'privado', 'private', 'secret', 'segredo', 'prefiro', | ||
| 'depois', 'esqueci', 'preguiça', 'sorry', 'desculpa', | ||
| 'iniciante', 'construção', 'manutenção', | ||
| 'não sei', 'nao sei', 'no momento', 'por enquanto', | ||
| 'vou criar', 'vou fazer', 'vou ficar', | ||
| 'tenho q', 'fiz ainda', 'criei ainda', | ||
| 'sei nem', 'sei pra', | ||
| 'não uso', 'nao uso', 'não utilizo', | ||
| 'estou sem', 'fodase', 'fica pra', | ||
| ]; | ||
|
|
||
| private const array JUNK_EXACT = [ | ||
| '.', '..', '...', '(...)', '-', '--', '-x-', | ||
| 'a', 'x', 'xx', 'xxxx', 'd', 'dd', 'i', 'n', 'nn', 's', 't', | ||
| 'no', 'non', 'nop', 'nt', 'we', 'af', 'sa', 'lk', | ||
| '0', '00', '1', '?', '??', ';', '_', '~', | ||
| 'git', 'github', 'github.com', 'sem', 'nada', 'keine', | ||
| 'oi', 'dope', 'scarlet', 'eew', 'cat.jsx', | ||
| '⛔', '🐰', '🥸', '—', '…', | ||
| ]; | ||
|
|
||
| public function up(): void | ||
| { | ||
| $rows = DB::table('user_information') | ||
| ->whereNotNull('github_url') | ||
| ->where('github_url', '!=', '') | ||
| ->whereRaw("NOT (github_url LIKE 'https://github.com/%' AND LENGTH(github_url) > 19)") | ||
| ->get(['id', 'github_url']); | ||
|
|
||
| foreach ($rows as $row) { | ||
| $lower = mb_strtolower(mb_trim($row->github_url)); | ||
danielhe4rt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ($this->isJunk($lower)) { | ||
| DB::table('user_information')->where('id', $row->id)->update(['github_url' => null]); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| $fixed = $this->tryFixUrl($lower); | ||
|
|
||
| if ($fixed !== null) { | ||
| DB::table('user_information')->where('id', $row->id)->update(['github_url' => $fixed]); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| // Non-github links, gifs, random URLs — null them out | ||
| DB::table('user_information')->where('id', $row->id)->update(['github_url' => null]); | ||
| } | ||
| } | ||
|
|
||
| public function down(): void | ||
| { | ||
| // Irreversible: original junk values are not preserved. | ||
| } | ||
|
|
||
| private function isJunk(string $lower): bool | ||
| { | ||
| if (in_array($lower, self::JUNK_EXACT, true)) { | ||
| return true; | ||
| } | ||
|
|
||
| foreach (self::JUNK_KEYWORDS as $keyword) { | ||
| if (str_contains($lower, $keyword)) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private function tryFixUrl(string $lower): ?string | ||
| { | ||
| if (preg_match('#^github\.com/[\w.\-]+#', $lower)) { | ||
| return 'https://'.$lower; | ||
| } | ||
|
|
||
| if (preg_match('#^(https?://)?www\.github\.com/([\w.\-]+)#i', $lower, $m)) { | ||
| return 'https://github.com/'.$m[2]; | ||
| } | ||
|
|
||
| if (preg_match('#^https?://git[Hh]ub\.com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| if (preg_match('#^https?//github\.com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| if (preg_match('#^https?;//github\.com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| if (preg_match('#^https?:+//github\.com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| if (preg_match('#^h\w{3,6}s?[:/]+/*github\.com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| if (preg_match('#^https?://(?:gi[th]*ub|gu[th]*ub|githubm)\.com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| if (preg_match('#^https?://github,com/([\w.\-]+)#', $lower, $m)) { | ||
| return 'https://github.com/'.$m[1]; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| }; | ||
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.