Add the Swift package type, model and plan limit

What does this MR do and why?

This is the first of four merge requests extracted from !257972, which stays a POC and is not merged. It adds the Swift package type at the database layer: the enum value, the model, the identifier regexes and the plan limit. Nothing routes to it yet. The API skeleton, the finder and the list-releases endpoint follow in their own merge requests.

The split, the slice boundaries and the merge order were set by @radbatnag on !257972. This mirrors Cargo's DB merge request !197846 (merged), minus the metadata table: Swift needs no new table, because the scope and the name live together in packages_packages.name.

Three commits, one concern each.

The regexes derive the scope, the name and the combined identifier from one unbounded source each, the way semver_regex derives from unbounded_semver_regex in the same file. A scope is at most 39 characters and a name at most 100, each separated internally by single hyphens, with underscores also allowed in a name.

The package type and model add swift: 16 and Packages::Swift::Package, which validates the identifier and the version and matches an identifier case-insensitively, because the registry specification says scopes and names are case-insensitive. The GraphQL enum derives from Packages::Package.package_types, so the new value also reaches the GraphQL reference and both introspection results.

The plan limit adds swift_max_file_size. It is not read anywhere yet, because publishing comes in a later merge request. @radbatnag confirmed it belongs here rather than with publish, following Cargo. It is the only part of this merge request that is not behind the feature flag, since the admin API exposes the field unconditionally, which is why only that commit carries a changelog trailer.

RSpec does not run in my environment, so CI is the first execution of the new model spec, the regex assertions and the migration itself.

Database Review

References

How to set up and validate locally

  1. Run the migration:

    bin/rails db:migrate
  2. In the Rails console, confirm the package type and the identifier matching:

    Packages::Package.package_types[:swift]
    # => 16
    
    Gitlab::Regex.swift_package_identifier_regex.match?('mona.LinkedList')
    # => true, a scope and a name joined by a dot
    
    Gitlab::Regex.swift_package_identifier_regex.match?('mona')
    # => false, a bare scope is not an identifier
    
    Gitlab::Regex.swift_package_scope_regex.match?('a' * 39)
    # => true, and 40 characters is false
  3. Confirm the new plan limit is readable and exposed:

    Plan.default.actual_limits.swift_max_file_size
    # => 104857600
  4. As an administrator, GET /api/v4/application/plan_limits and confirm the response now includes swift_max_file_size.

Edited by Radamanthus Batnag

Merge request reports

Loading
Loading