-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add workspace management for admins
- Loading branch information
1 parent
28e9e64
commit 117be93
Showing
44 changed files
with
2,007 additions
and
303 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
60 changes: 60 additions & 0 deletions
60
backend/capellacollab/alembic/versions/a1e59021e0d0_add_workspaces_table.py
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,60 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Add workspaces table | ||
Revision ID: a1e59021e0d0 | ||
Revises: 49f51db92903 | ||
Create Date: 2024-07-17 09:19:57.903328 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a1e59021e0d0" | ||
down_revision = "49f51db92903" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
t_users = sa.Table( | ||
"users", | ||
sa.MetaData(), | ||
sa.Column("id", sa.Integer()), | ||
sa.Column("name", sa.String()), | ||
) | ||
|
||
|
||
def upgrade(): | ||
connection = op.get_bind() | ||
users = connection.execute(sa.select(t_users)).mappings().all() | ||
|
||
t_workspaces = op.create_table( | ||
"workspaces", | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("pvc_name", sa.String(), nullable=False), | ||
sa.Column("size", sa.String(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id", "user_id"), | ||
sa.UniqueConstraint("pvc_name"), | ||
) | ||
op.create_index( | ||
op.f("ix_workspaces_id"), "workspaces", ["id"], unique=False | ||
) | ||
|
||
for user in users: | ||
pvc_name = ( | ||
"persistent-session-" | ||
+ user["name"].replace("@", "-at-").replace(".", "-dot-").lower() | ||
) | ||
connection.execute( | ||
t_workspaces.insert().values( | ||
pvc_name=pvc_name, | ||
size="20Gi", | ||
user_id=user["id"], | ||
) | ||
) |
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.