mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-10-03 22:11:54 +02:00
Organizations can pin the source they mirror from when more than one source is connected. - New nullable organizations.source_id column (migration 0020_org_source), backfilled only when an organization's repositories agree on exactly one source. - NULL means every source; a pin whose source was deleted falls back to the same. A valid pin scopes the org mirror job, the repository count breakdowns and org deletion to that source. - POST /api/sync/organization persists the pin, PATCH /api/organizations/:id sets or clears it, the bulk import stamps discovered orgs and clears the pin when a second source lists the same org. - UI, only with more than one source connected: a Source picker in the Add Organization dialog, a per-card inline source editor with an Every source option, and per-org View on source links. - The org mirror repository query now filters by user. - Shared provider icon map in src/lib/source-providers/icons.ts.
16 lines
775 B
SQL
16 lines
775 B
SQL
ALTER TABLE `organizations` ADD `source_id` text;--> statement-breakpoint
|
|
-- Pin each organization to the source its repositories came from, but only
|
|
-- when they agree on exactly one: organizations whose repos span several
|
|
-- sources (or have none) stay unpinned and keep following every source.
|
|
-- MIN() keeps the subquery scalar; a HAVING filter with no matching row
|
|
-- yields NULL, which leaves the column untouched.
|
|
UPDATE `organizations` SET `source_id` = (
|
|
SELECT MIN(`repositories`.`source_id`)
|
|
FROM `repositories`
|
|
WHERE `repositories`.`user_id` = `organizations`.`user_id`
|
|
AND `repositories`.`organization` = `organizations`.`name`
|
|
AND `repositories`.`source_id` IS NOT NULL
|
|
HAVING COUNT(DISTINCT `repositories`.`source_id`) = 1
|
|
)
|
|
WHERE `source_id` IS NULL;
|