ai-cfia / ailab-datastore

This is a repo representing the data layer of multiple ailab projects
MIT License
2 stars 0 forks source link

As a dev, I want to delete a user from the database #172

Closed snakedye closed 1 month ago

snakedye commented 1 month ago

Context:

Currently when we run tests on the backend for database operations tied to a user, a user either has to be pre-created or created before each test. If the user is created before each test, the rollback can delete the user but it will not delete the container associated with him.

We need a way to delete the user along with his azure container.

Acceptance Criteria:

Francois-Werbrouck commented 1 month ago

I understand the need behind creating a f() to remove a user. However, I don't think the current reason behind this issue is a good enough motivation to use such functionality.


Your issue.

When doing a test, you can create the user in the setUp(self) then rollback the cursor and delete the container


 def setUp(self):
        self.con = db.connect_db(DB_CONNECTION_STRING, DB_SCHEMA)
        self.cursor = self.con.cursor()
        db.create_search_path(self.con, self.cursor, DB_SCHEMA)
        self.connection_str = BLOB_CONNECTION_STRING
        self.user_email = "test@email"
        self.tier="test-user"
        self.user_obj = asyncio.run(
            datastore.new_user(
                self.cursor, self.user_email, self.connection_str, self.tier
            )
        )
       self.container_name = "test-container"
        self.user_id = datastore.User.get_id(self.user_obj)
        self.container_client = asyncio.run(
            datastore.get_user_container_client(
                self.user_id,
                BLOB_CONNECTION_STRING,
                BLOB_ACCOUNT,
                BLOB_KEY,
                "test-user",
            )

  def tearDown(self):
        self.con.rollback()
        self.container_client.delete_container()
        db.end_query(self.con, self.cursor)

Those should be sufficient to disable a user from being created in the db (self.con.rollback()) and will remove all traces of the user being created in the Blob Storage (self.container_client.delete_container()) .


What is asked in this issue

We can create a way to erase Fertiscan users, however we need to decide of our strategy on how to handle edge cases like what if the user has validated and important data in its storage.

The need to erase users is real, yet it has not seemed important enough to be implemented into the workflow of Fertiscan yet. I will discuss with @k-allagbe to determined the best solution for all edge case and better plan the work behind what this issue require.

I personally don't think just erasing the container of a user is a good practice if we don't care for the content or transaction done on the tool by said user.

k-allagbe commented 1 month ago

We actually already found a solution for our problem in the backend. We'll update the backend if anything changes on this aspect in the datastore. Closing this.