Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete Projects,Teams,TaskTypes with name suffix to allow reusing names #7573

Merged
merged 9 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Multiple segments can be dragged and dropped in the segments tab. [#7536](https://github.com/scalableminds/webknossos/pull/7536)
- Added the option to convert agglomerate skeletons to freely modifiable skeletons in the context menu of the Skeleton tab. [#7537](https://github.com/scalableminds/webknossos/pull/7537)
- The annotation list in the dashboard now also shows segment counts of volume annotations (after they have been edited). [#7548](https://github.com/scalableminds/webknossos/pull/7548)
- After deleting specific teams, projects and task types, their names can now be re-used when creating new ones. [#7573](https://github.com/scalableminds/webknossos/pull/7573)

### Changed
- Improved loading speed of the annotation list. [#7410](https://github.com/scalableminds/webknossos/pull/7410)
Expand All @@ -35,7 +36,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Updated antd UI library from version 4.24.8 to 4.24.15. [#7505](https://github.com/scalableminds/webknossos/pull/7505)
- Changed the default dataset search mode to also search in subfolders. [#7539](https://github.com/scalableminds/webknossos/pull/7539)
- When clicking a segment in the viewport, it is automatically focused in the segment list. A corresponding context menu entry was added as well. [#7512](https://github.com/scalableminds/webknossos/pull/7512)
- Updated the isValidName route in the API to return 200 for valid and invalid names. With this, the API version was bumped up to 6. [#7550](https://github.com/scalableminds/webknossos/pull/7550)
- Updated the isValidName route in the API to return 200 for valid and invalid names. With this, the API version was bumped up to 6. [#7550](https://github.com/scalableminds/webknossos/pull/7550)
- Upgraded to Play 3. [#7562](https://github.com/scalableminds/webknossos/pull/7562)
- When no Email Address for New-User Notifications is configured, the organization owner will be notified. For overtime notifications, the project owner and the organization owner will be notified. [#7561](https://github.com/scalableminds/webknossos/pull/7561)
- The metadata for ND datasets and their annotation has changed: upper bound of additionalAxes is now stored as an exclusive value, called "end" in the NML format. [#7547](https://github.com/scalableminds/webknossos/pull/7547)
Expand Down
2 changes: 2 additions & 0 deletions app/models/project/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class ProjectDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionContext)
count <- countList.headOption
} yield count

override def deleteOne(projectId: ObjectId)(implicit ctx: DBAccessContext): Fox[Unit] =
deleteOneWithNameSuffix(projectId)
}

class ProjectService @Inject()(projectDAO: ProjectDAO, teamDAO: TeamDAO, userService: UserService, taskDAO: TaskDAO)(
Expand Down
3 changes: 3 additions & 0 deletions app/models/task/TaskType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,7 @@ class TaskTypeDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionContext)
countList <- run(q"select count(_id) from $existingCollectionName where _team = $teamId".as[Int])
count <- countList.headOption
} yield count

override def deleteOne(taskTypeId: ObjectId)(implicit ctx: DBAccessContext): Fox[Unit] =
deleteOneWithNameSuffix(taskTypeId, nameColumn = "summary")
}
3 changes: 3 additions & 0 deletions app/models/team/Team.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,7 @@ class TeamDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionContext)
_ <- run(q"DELETE FROM webknossos.folder_allowedTeams WHERE _team = $teamId".asUpdate)
} yield ()

override def deleteOne(teamId: ObjectId)(implicit ctx: DBAccessContext): Fox[Unit] =
deleteOneWithNameSuffix(teamId)

}
10 changes: 10 additions & 0 deletions app/utils/sql/SQLDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ abstract class SQLDAO[C, R, X <: AbstractTable[R]] @Inject()(sqlClient: SqlClien
} yield ()
}

def deleteOneWithNameSuffix(id: ObjectId, nameColumn: String = "name")(implicit ctx: DBAccessContext): Fox[Unit] =
for {
_ <- assertDeleteAccess(id)
deletedSuffix = s".deleted.at.${Instant.now.epochMillis}"
collectionToken = SqlToken.raw(collectionName)
nameColumnToken = SqlToken.raw(nameColumn)
_ <- run(
q"UPDATE $collectionToken SET isDeleted = TRUE, $nameColumnToken = CONCAT($nameColumnToken, $deletedSuffix) WHERE _id = $id".asUpdate)
} yield ()

protected def updateStringCol(id: ObjectId, column: X => Rep[String], newValue: String)(
implicit ctx: DBAccessContext): Fox[Unit] = {
val query = for { row <- collection if notdel(row) && idColumn(row) === id.id } yield column(row)
Expand Down
11 changes: 11 additions & 0 deletions conf/evolutions/112-reuse-deleted.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
START TRANSACTION;

do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 111, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql;

UPDATE webknossos.teams SET name = CONCAT(name, '.deleted.beforeDeletionSuffix') WHERE isDeleted = TRUE;
UPDATE webknossos.projects SET name = CONCAT(name, '.deleted.beforeDeletionSuffix') WHERE isDeleted = TRUE;
UPDATE webknossos.tasktypes SET summary = CONCAT(summary, '.deleted.beforeDeletionSuffix') WHERE isDeleted = TRUE;

UPDATE webknossos.releaseInformation SET schemaVersion = 112;

COMMIT TRANSACTION;
11 changes: 11 additions & 0 deletions conf/evolutions/reversions/112-reuse-deleted.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
START TRANSACTION;

do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 112, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql;

UPDATE webknossos.teams SET name = REPLACE(name, '.deleted.beforeDeletionSuffix', '') WHERE isDeleted = TRUE;
UPDATE webknossos.projects SET name = REPLACE(name, '.deleted.beforeDeletionSuffix', '') WHERE isDeleted = TRUE;
UPDATE webknossos.tasktypes SET summary = REPLACE(summary, '.deleted.beforeDeletionSuffix', '') WHERE isDeleted = TRUE;

UPDATE webknossos.releaseInformation SET schemaVersion = 111;

COMMIT TRANSACTION;
2 changes: 1 addition & 1 deletion tools/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE TABLE webknossos.releaseInformation (
schemaVersion BIGINT NOT NULL
);

INSERT INTO webknossos.releaseInformation(schemaVersion) values(111);
INSERT INTO webknossos.releaseInformation(schemaVersion) values(112);
COMMIT TRANSACTION;


Expand Down