feat: update schema for custom namespace

This commit is contained in:
Zack Fu Zi Xiang 2024-11-04 10:33:22 +08:00
parent 1fbb971b83
commit 09bcbc80ae
No known key found for this signature in database
2 changed files with 37 additions and 17 deletions

View File

@ -0,0 +1,37 @@
-- We will no longer use `publish_namespace` column to store user defined namespace.
-- `publish_namespace` will only be used to as fallback/default namespace if user did not set custom namespace.
-- `publish_namespace` will be initialized as random UUID and will never be modified.
-- We will remove UNIQUE constraint on `publish_namespace` column to avoid performance penalty on insert.
-- We will use a new table `af_workspace_namespace` to store user defined namespace for workspace.
ALTER TABLE af_workspace DROP CONSTRAINT af_workspace_publish_namespace_key;
-- Table to store user defined namespace for workspace
CREATE TABLE IF NOT EXISTS af_workspace_namespace (
workspace_id UUID,
namespace TEXT NOT NULL UNIQUE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (workspace_id) REFERENCES af_workspace (workspace_id) ON DELETE CASCADE
);
-- Create index for workspace_id
CREATE INDEX idx_af_workspace_namespace_workspace_id ON af_workspace_namespace (workspace_id);
-- Create index for namespace
CREATE INDEX idx_af_workspace_namespace_namespace ON af_workspace_namespace (namespace);
-- Create a function to update the updated_at column
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Create a trigger to call the function before each update
CREATE TRIGGER trigger_update_updated_at
BEFORE UPDATE ON af_workspace_namespace
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

View File

@ -155,10 +155,6 @@ pub fn workspace_scope() -> Scope {
web::resource("/published/{publish_namespace}")
.route(web::get().to(get_default_published_collab_info_meta_handler)),
)
.service(
web::resource("/published/{publish_namespace}/{publish_name}") // Deprecated
.route(web::get().to(get_published_collab_handler)),
)
.service(
web::resource("/v1/published/{publish_namespace}/{publish_name}")
.route(web::get().to(get_v1_published_collab_handler)),
@ -1222,19 +1218,6 @@ async fn get_default_published_collab_info_meta_handler(
))
}
/// Deprecated
async fn get_published_collab_handler(
path_param: web::Path<(String, String)>,
state: Data<AppState>,
) -> Result<Json<serde_json::Value>> {
let (workspace_namespace, publish_name) = path_param.into_inner();
let metadata = state
.published_collab_store
.get_collab_metadata(&workspace_namespace, &publish_name)
.await?;
Ok(Json(metadata))
}
async fn get_v1_published_collab_handler(
path_param: web::Path<(String, String)>,
state: Data<AppState>,