-
Notifications
You must be signed in to change notification settings - Fork 55
Fix subdomain allocation and record coexistence validation #170
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
NebuloDev
wants to merge
9
commits into
pelican:main
Choose a base branch
from
NebuloDev:fix/subdomain-record-coexistence
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
9 commits
Select commit
Hold shift + click to select a range
6e89fd0
Fix subdomain allocation and record coexistence
NebuloDev eb3e18e
Allow SRV records for separate servers
NebuloDev a92b626
Guard subdomain migration rollback
NebuloDev fbd5efe
Fix tenant type in subdomain validation
NebuloDev a2154bc
Prevent conflicting CNAME renames
NebuloDev 3f64e8d
Enforce subdomain record uniqueness globally
NebuloDev 025daa4
Allow distinct SRV service records
NebuloDev c307aa3
Fix lint issues in subdomain validation
NebuloDev 23eb9e4
Populate record identifiers during migration
NebuloDev 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
49 changes: 49 additions & 0 deletions
49
subdomains/database/migrations/011_allow_compatible_record_types.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,49 @@ | ||
| <?php | ||
|
|
||
| use Boy132\Subdomains\Models\Subdomain; | ||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| public function up(): void | ||
| { | ||
| Schema::table('subdomains', function (Blueprint $table) { | ||
| $table->dropUnique(['name', 'domain_id']); | ||
| $table->string('record_identifier')->nullable()->after('record_type'); | ||
| }); | ||
|
|
||
| Subdomain::query()->with('server')->each(function (Subdomain $subdomain) { | ||
| $subdomain->record_identifier = $subdomain->record_type->uniqueIdentifier($subdomain->server); | ||
| $subdomain->saveQuietly(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| Schema::table('subdomains', function (Blueprint $table) { | ||
| $table->string('record_identifier')->nullable(false)->change(); | ||
| $table->unique(['name', 'domain_id', 'record_identifier']); | ||
| }); | ||
| } | ||
|
|
||
| public function down(): void | ||
| { | ||
| $hasDuplicateSubdomains = DB::table('subdomains') | ||
| ->select('name', 'domain_id') | ||
| ->groupBy('name', 'domain_id') | ||
| ->havingRaw('COUNT(*) > 1') | ||
| ->exists(); | ||
|
|
||
| if ($hasDuplicateSubdomains) { | ||
| throw new RuntimeException( | ||
| 'Cannot roll back subdomain coexistence while multiple record types share the same name and domain. Remove the duplicate records first.', | ||
| ); | ||
| } | ||
|
|
||
| Schema::table('subdomains', function (Blueprint $table) { | ||
| $table->dropUnique(['name', 'domain_id', 'record_identifier']); | ||
| $table->unique(['name', 'domain_id']); | ||
|
macroscopeapp[bot] marked this conversation as resolved.
|
||
| $table->dropColumn('record_identifier'); | ||
| }); | ||
| } | ||
| }; | ||
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
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.
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.
🟠 High
migrations/011_allow_compatible_record_types.php:18The migration fails at
nullable(false)->change()wheneversubdomainsalready contains rows, becausesaveQuietly()suppresses thesavinglistener that populatesrecord_identifier, leaving every existing rowNULL. Usesave()here so the listener runs before the column is made non-nullable.🤖 Copy this AI Prompt to have your agent fix this: