Implement data model changes to support new WebDAV Push spec

This commit is contained in:
Lennart
2025-05-03 15:24:00 +02:00
parent f50ef8a1d5
commit d1f249a01b
17 changed files with 605 additions and 152 deletions

View File

@@ -0,0 +1,4 @@
ALTER TABLE davpush_subscriptions
DROP public_key,
DROP public_key_type,
DROP auth_secret;

View File

@@ -0,0 +1,7 @@
-- Old subscriptions are useless anyway
DELETE FROM davpush_subscriptions;
-- Now the new columns can also be set NOT NULL
ALTER TABLE davpush_subscriptions ADD public_key TEXT NOT NULL;
ALTER TABLE davpush_subscriptions ADD public_key_type TEXT NOT NULL;
ALTER TABLE davpush_subscriptions ADD auth_secret TEXT NOT NULL;

View File

@@ -7,7 +7,7 @@ impl SubscriptionStore for SqliteStore {
async fn get_subscriptions(&self, topic: &str) -> Result<Vec<Subscription>, Error> {
Ok(sqlx::query_as!(
Subscription,
r#"SELECT id, topic, expiration, push_resource
r#"SELECT id, topic, expiration, push_resource, public_key, public_key_type, auth_secret
FROM davpush_subscriptions
WHERE (topic) = (?)"#,
topic
@@ -20,7 +20,7 @@ impl SubscriptionStore for SqliteStore {
async fn get_subscription(&self, id: &str) -> Result<Subscription, Error> {
Ok(sqlx::query_as!(
Subscription,
r#"SELECT id, topic, expiration, push_resource
r#"SELECT id, topic, expiration, push_resource, public_key, public_key_type, auth_secret
FROM davpush_subscriptions
WHERE (id) = (?)"#,
id
@@ -32,11 +32,14 @@ impl SubscriptionStore for SqliteStore {
async fn upsert_subscription(&self, sub: Subscription) -> Result<bool, Error> {
sqlx::query!(
r#"INSERT OR REPLACE INTO davpush_subscriptions (id, topic, expiration, push_resource) VALUES (?, ?, ?, ?)"#,
r#"INSERT OR REPLACE INTO davpush_subscriptions (id, topic, expiration, push_resource, public_key, public_key_type, auth_secret) VALUES (?, ?, ?, ?, ?, ?, ?)"#,
sub.id,
sub.topic,
sub.expiration,
sub.push_resource
sub.push_resource,
sub.public_key,
sub.public_key_type,
sub.auth_secret
).execute(&self.db).await.map_err(crate::Error::from)?;
// TODO: Correctly return whether a subscription already existed
Ok(false)