-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial migration for Workspaces and pipeline step (#600)
* feat: Initial migration for Workspaces and pipeline step Related: #454 We noticed most of the incoming-requests which contain a code-snippet only list a relative path with respect to where the code editor is opened. This would make difficult to accurately distinguish between repositories in Codegate. For example, a user could open 2 different code Python repositorites in different session and both repositories contain a `pyproject.toml`. It would be impossible for Codegate to determine the real repository of the file only using the relative path. Hence, the initial implementation of Workspaces will rely on a pipeline step that is able to take commands a process them. Some commands could be: - List workspaces - Add workspace - Switch active workspace - Delete workspace It would be up to the user to select the desired active workspace. This PR introduces an initial migration for Workspaces and the pipeline step with the `list` command. * Reformatting changes * Make unique workspaces name * Introduced Sessions table and added add and activate commands * Formatting changes and unit tests * Classes separation into a different file
- Loading branch information
1 parent
b4d719f
commit 147205a
Showing
14 changed files
with
589 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""introduce workspaces | ||
Revision ID: 5c2f3eee5f90 | ||
Revises: 30d0144e1a50 | ||
Create Date: 2025-01-15 19:27:08.230296 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "5c2f3eee5f90" | ||
down_revision: Union[str, None] = "30d0144e1a50" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Workspaces table | ||
op.execute( | ||
""" | ||
CREATE TABLE workspaces ( | ||
id TEXT PRIMARY KEY, -- UUID stored as TEXT | ||
name TEXT NOT NULL, | ||
UNIQUE (name) | ||
); | ||
""" | ||
) | ||
op.execute("INSERT INTO workspaces (id, name) VALUES ('1', 'default');") | ||
# Sessions table | ||
op.execute( | ||
""" | ||
CREATE TABLE sessions ( | ||
id TEXT PRIMARY KEY, -- UUID stored as TEXT | ||
active_workspace_id TEXT NOT NULL, | ||
last_update DATETIME NOT NULL, | ||
FOREIGN KEY (active_workspace_id) REFERENCES workspaces(id) | ||
); | ||
""" | ||
) | ||
# Alter table prompts | ||
op.execute("ALTER TABLE prompts ADD COLUMN workspace_id TEXT REFERENCES workspaces(id);") | ||
op.execute("UPDATE prompts SET workspace_id = '1';") | ||
# Create index for workspace_id | ||
op.execute("CREATE INDEX idx_prompts_workspace_id ON prompts (workspace_id);") | ||
# Create index for session_id | ||
op.execute("CREATE INDEX idx_sessions_workspace_id ON sessions (active_workspace_id);") | ||
|
||
|
||
def downgrade() -> None: | ||
# Drop the index for workspace_id | ||
op.execute("DROP INDEX IF EXISTS idx_prompts_workspace_id;") | ||
op.execute("DROP INDEX IF EXISTS idx_sessions_workspace_id;") | ||
# Remove the workspace_id column from prompts table | ||
op.execute("ALTER TABLE prompts DROP COLUMN workspace_id;") | ||
# Drop the sessions table | ||
op.execute("DROP TABLE IF EXISTS sessions;") | ||
# Drop the workspaces table | ||
op.execute("DROP TABLE IF EXISTS workspaces;") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.