diff --git a/migrations/20241101063559_af_workspace_namespace.sql b/migrations/20241101063559_af_workspace_namespace.sql new file mode 100644 index 00000000..3806a6c9 --- /dev/null +++ b/migrations/20241101063559_af_workspace_namespace.sql @@ -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(); diff --git a/src/api/workspace.rs b/src/api/workspace.rs index 470fcc84..c8135a28 100644 --- a/src/api/workspace.rs +++ b/src/api/workspace.rs @@ -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, -) -> Result> { - 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,