From bd187883da1d0da7120b6fd8d63cc0b7cb1c7c78 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 30 Oct 2024 11:55:55 -0600 Subject: [PATCH] Migration to remove dev servers (#19639) Depends on #19638 Release Notes: - None --- .../20221109000000_test_schema.sql | 28 +----------- .../20241023201725_remove_dev_servers.sql | 6 +++ crates/collab/src/db/queries/projects.rs | 43 ------------------- 3 files changed, 7 insertions(+), 70 deletions(-) create mode 100644 crates/collab/migrations/20241023201725_remove_dev_servers.sql diff --git a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql b/crates/collab/migrations.sqlite/20221109000000_test_schema.sql index c6bd87a8a5..c59091d66d 100644 --- a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql +++ b/crates/collab/migrations.sqlite/20221109000000_test_schema.sql @@ -52,9 +52,7 @@ CREATE TABLE "projects" ( "host_user_id" INTEGER REFERENCES users (id), "host_connection_id" INTEGER, "host_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE, - "unregistered" BOOLEAN NOT NULL DEFAULT FALSE, - "hosted_project_id" INTEGER REFERENCES hosted_projects (id), - "dev_server_project_id" INTEGER REFERENCES dev_server_projects(id) + "unregistered" BOOLEAN NOT NULL DEFAULT FALSE ); CREATE INDEX "index_projects_on_host_connection_server_id" ON "projects" ("host_connection_server_id"); CREATE INDEX "index_projects_on_host_connection_id_and_host_connection_server_id" ON "projects" ("host_connection_id", "host_connection_server_id"); @@ -399,30 +397,6 @@ CREATE TABLE rate_buckets ( ); CREATE INDEX idx_user_id_rate_limit ON rate_buckets (user_id, rate_limit_name); -CREATE TABLE hosted_projects ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - channel_id INTEGER NOT NULL REFERENCES channels(id), - name TEXT NOT NULL, - visibility TEXT NOT NULL, - deleted_at TIMESTAMP NULL -); -CREATE INDEX idx_hosted_projects_on_channel_id ON hosted_projects (channel_id); -CREATE UNIQUE INDEX uix_hosted_projects_on_channel_id_and_name ON hosted_projects (channel_id, name) WHERE (deleted_at IS NULL); - -CREATE TABLE dev_servers ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - user_id INTEGER NOT NULL REFERENCES users(id), - name TEXT NOT NULL, - ssh_connection_string TEXT, - hashed_token TEXT NOT NULL -); - -CREATE TABLE dev_server_projects ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - dev_server_id INTEGER NOT NULL REFERENCES dev_servers(id), - paths TEXT NOT NULL -); - CREATE TABLE IF NOT EXISTS billing_preferences ( id INTEGER PRIMARY KEY AUTOINCREMENT, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/crates/collab/migrations/20241023201725_remove_dev_servers.sql b/crates/collab/migrations/20241023201725_remove_dev_servers.sql new file mode 100644 index 0000000000..c5da673a29 --- /dev/null +++ b/crates/collab/migrations/20241023201725_remove_dev_servers.sql @@ -0,0 +1,6 @@ +ALTER TABLE projects DROP COLUMN dev_server_project_id; +ALTER TABLE projects DROP COLUMN hosted_project_id; + +DROP TABLE hosted_projects; +DROP TABLE dev_server_projects; +DROP TABLE dev_servers; diff --git a/crates/collab/src/db/queries/projects.rs b/crates/collab/src/db/queries/projects.rs index 9ea42dd9bf..7ff8aa7a9f 100644 --- a/crates/collab/src/db/queries/projects.rs +++ b/crates/collab/src/db/queries/projects.rs @@ -750,49 +750,6 @@ impl Database { Ok((project, replica_id as ReplicaId)) } - pub async fn leave_hosted_project( - &self, - project_id: ProjectId, - connection: ConnectionId, - ) -> Result { - self.transaction(|tx| async move { - let result = project_collaborator::Entity::delete_many() - .filter( - Condition::all() - .add(project_collaborator::Column::ProjectId.eq(project_id)) - .add(project_collaborator::Column::ConnectionId.eq(connection.id as i32)) - .add( - project_collaborator::Column::ConnectionServerId - .eq(connection.owner_id as i32), - ), - ) - .exec(&*tx) - .await?; - if result.rows_affected == 0 { - return Err(anyhow!("not in the project"))?; - } - - let project = project::Entity::find_by_id(project_id) - .one(&*tx) - .await? - .ok_or_else(|| anyhow!("no such project"))?; - let collaborators = project - .find_related(project_collaborator::Entity) - .all(&*tx) - .await?; - let connection_ids = collaborators - .into_iter() - .map(|collaborator| collaborator.connection()) - .collect(); - Ok(LeftProject { - id: project.id, - connection_ids, - should_unshare: false, - }) - }) - .await - } - /// Removes the given connection from the specified project. pub async fn leave_project( &self,