Respect version constraints when installing extensions (#10052)

This PR modifies the extension installation and update process to
respect version constraints (schema version and Wasm API version) to
ensure only compatible versions of extensions are able to be installed.

To achieve this there is a new `GET /extensions/updates` endpoint that
will return extension versions based on the provided constraints.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-04-01 17:10:30 -04:00 committed by GitHub
parent 39cc3c0778
commit 83ce783856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 304 additions and 78 deletions

View file

@ -21,11 +21,13 @@ use sea_orm::{
FromQueryResult, IntoActiveModel, IsolationLevel, JoinType, QueryOrder, QuerySelect, Statement,
TransactionTrait,
};
use serde::{ser::Error as _, Deserialize, Serialize, Serializer};
use semantic_version::SemanticVersion;
use serde::{Deserialize, Serialize};
use sqlx::{
migrate::{Migrate, Migration, MigrationSource},
Connection,
};
use std::ops::RangeInclusive;
use std::{
fmt::Write as _,
future::Future,
@ -36,7 +38,7 @@ use std::{
sync::Arc,
time::Duration,
};
use time::{format_description::well_known::iso8601, PrimitiveDateTime};
use time::PrimitiveDateTime;
use tokio::sync::{Mutex, OwnedMutexGuard};
#[cfg(test)]
@ -730,20 +732,7 @@ pub struct NewExtensionVersion {
pub published_at: PrimitiveDateTime,
}
pub fn serialize_iso8601<S: Serializer>(
datetime: &PrimitiveDateTime,
serializer: S,
) -> Result<S::Ok, S::Error> {
const SERDE_CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT
.set_year_is_six_digits(false)
.set_time_precision(iso8601::TimePrecision::Second {
decimal_digits: None,
})
.encode();
datetime
.assume_utc()
.format(&time::format_description::well_known::Iso8601::<SERDE_CONFIG>)
.map_err(S::Error::custom)?
.serialize(serializer)
pub struct ExtensionVersionConstraints {
pub schema_versions: RangeInclusive<i32>,
pub wasm_api_versions: RangeInclusive<SemanticVersion>,
}