feat: Implement comprehensive database schema with new models, CRUD operations, and documentation for host metrics, Docker management, and terminal sessions, while removing old test files.
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
This commit is contained in:
@@ -88,37 +88,58 @@ class DockerContainerRepository:
|
||||
compose_project: Optional[str] = None
|
||||
) -> DockerContainer:
|
||||
"""Create or update a container using SQLite upsert."""
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
# Determine if we are using MySQL or SQLite
|
||||
dialect = self.session.bind.dialect.name
|
||||
|
||||
stmt = sqlite_insert(DockerContainer).values(
|
||||
host_id=host_id,
|
||||
container_id=container_id,
|
||||
name=name,
|
||||
image=image,
|
||||
state=state,
|
||||
status=status,
|
||||
health=health,
|
||||
created_at=created_at,
|
||||
ports=ports,
|
||||
labels=labels,
|
||||
compose_project=compose_project,
|
||||
last_update_at=datetime.utcnow()
|
||||
)
|
||||
stmt = stmt.on_conflict_do_update(
|
||||
index_elements=['host_id', 'container_id'],
|
||||
set_={
|
||||
'name': stmt.excluded.name,
|
||||
'image': stmt.excluded.image,
|
||||
'state': stmt.excluded.state,
|
||||
'status': stmt.excluded.status,
|
||||
'health': stmt.excluded.health,
|
||||
'created_at': stmt.excluded.created_at,
|
||||
'ports': stmt.excluded.ports,
|
||||
'labels': stmt.excluded.labels,
|
||||
'compose_project': stmt.excluded.compose_project,
|
||||
'last_update_at': stmt.excluded.last_update_at
|
||||
}
|
||||
)
|
||||
values = {
|
||||
"host_id": host_id,
|
||||
"container_id": container_id,
|
||||
"name": name,
|
||||
"image": image,
|
||||
"state": state,
|
||||
"status": status,
|
||||
"health": health,
|
||||
"created_at": created_at,
|
||||
"ports": ports,
|
||||
"labels": labels,
|
||||
"compose_project": compose_project,
|
||||
"last_update_at": datetime.utcnow()
|
||||
}
|
||||
|
||||
if dialect == "mysql":
|
||||
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
||||
stmt = mysql_insert(DockerContainer).values(**values)
|
||||
stmt = stmt.on_duplicate_key_update(
|
||||
name=stmt.inserted.name,
|
||||
image=stmt.inserted.image,
|
||||
state=stmt.inserted.state,
|
||||
status=stmt.inserted.status,
|
||||
health=stmt.inserted.health,
|
||||
created_at=stmt.inserted.created_at,
|
||||
ports=stmt.inserted.ports,
|
||||
labels=stmt.inserted.labels,
|
||||
compose_project=stmt.inserted.compose_project,
|
||||
last_update_at=stmt.inserted.last_update_at
|
||||
)
|
||||
else:
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
stmt = sqlite_insert(DockerContainer).values(**values)
|
||||
stmt = stmt.on_conflict_do_update(
|
||||
index_elements=['host_id', 'container_id'],
|
||||
set_={
|
||||
'name': stmt.excluded.name,
|
||||
'image': stmt.excluded.image,
|
||||
'state': stmt.excluded.state,
|
||||
'status': stmt.excluded.status,
|
||||
'health': stmt.excluded.health,
|
||||
'created_at': stmt.excluded.created_at,
|
||||
'ports': stmt.excluded.ports,
|
||||
'labels': stmt.excluded.labels,
|
||||
'compose_project': stmt.excluded.compose_project,
|
||||
'last_update_at': stmt.excluded.last_update_at
|
||||
}
|
||||
)
|
||||
|
||||
await self.session.execute(stmt)
|
||||
|
||||
# Return the upserted container
|
||||
|
||||
+33
-18
@@ -63,25 +63,40 @@ class DockerImageRepository:
|
||||
created: Optional[datetime] = None
|
||||
) -> DockerImage:
|
||||
"""Create or update an image using SQLite upsert."""
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
# Determine if we are using MySQL or SQLite
|
||||
dialect = self.session.bind.dialect.name
|
||||
|
||||
stmt = sqlite_insert(DockerImage).values(
|
||||
host_id=host_id,
|
||||
image_id=image_id,
|
||||
repo_tags=repo_tags,
|
||||
size=size,
|
||||
created=created,
|
||||
last_update_at=datetime.utcnow()
|
||||
)
|
||||
stmt = stmt.on_conflict_do_update(
|
||||
index_elements=['host_id', 'image_id'],
|
||||
set_={
|
||||
'repo_tags': stmt.excluded.repo_tags,
|
||||
'size': stmt.excluded.size,
|
||||
'created': stmt.excluded.created,
|
||||
'last_update_at': stmt.excluded.last_update_at
|
||||
}
|
||||
)
|
||||
values = {
|
||||
"host_id": host_id,
|
||||
"image_id": image_id,
|
||||
"repo_tags": repo_tags,
|
||||
"size": size,
|
||||
"created": created,
|
||||
"last_update_at": datetime.utcnow()
|
||||
}
|
||||
|
||||
if dialect == "mysql":
|
||||
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
||||
stmt = mysql_insert(DockerImage).values(**values)
|
||||
stmt = stmt.on_duplicate_key_update(
|
||||
repo_tags=stmt.inserted.repo_tags,
|
||||
size=stmt.inserted.size,
|
||||
created=stmt.inserted.created,
|
||||
last_update_at=stmt.inserted.last_update_at
|
||||
)
|
||||
else:
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
stmt = sqlite_insert(DockerImage).values(**values)
|
||||
stmt = stmt.on_conflict_do_update(
|
||||
index_elements=['host_id', 'image_id'],
|
||||
set_={
|
||||
'repo_tags': stmt.excluded.repo_tags,
|
||||
'size': stmt.excluded.size,
|
||||
'created': stmt.excluded.created,
|
||||
'last_update_at': stmt.excluded.last_update_at
|
||||
}
|
||||
)
|
||||
|
||||
await self.session.execute(stmt)
|
||||
|
||||
# Return the upserted image
|
||||
|
||||
+33
-18
@@ -56,25 +56,40 @@ class DockerVolumeRepository:
|
||||
scope: Optional[str] = None
|
||||
) -> DockerVolume:
|
||||
"""Create or update a volume using SQLite upsert."""
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
# Determine if we are using MySQL or SQLite
|
||||
dialect = self.session.bind.dialect.name
|
||||
|
||||
stmt = sqlite_insert(DockerVolume).values(
|
||||
host_id=host_id,
|
||||
name=name,
|
||||
driver=driver,
|
||||
mountpoint=mountpoint,
|
||||
scope=scope,
|
||||
last_update_at=datetime.utcnow()
|
||||
)
|
||||
stmt = stmt.on_conflict_do_update(
|
||||
index_elements=['host_id', 'name'],
|
||||
set_={
|
||||
'driver': stmt.excluded.driver,
|
||||
'mountpoint': stmt.excluded.mountpoint,
|
||||
'scope': stmt.excluded.scope,
|
||||
'last_update_at': stmt.excluded.last_update_at
|
||||
}
|
||||
)
|
||||
values = {
|
||||
"host_id": host_id,
|
||||
"name": name,
|
||||
"driver": driver,
|
||||
"mountpoint": mountpoint,
|
||||
"scope": scope,
|
||||
"last_update_at": datetime.utcnow()
|
||||
}
|
||||
|
||||
if dialect == "mysql":
|
||||
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
||||
stmt = mysql_insert(DockerVolume).values(**values)
|
||||
stmt = stmt.on_duplicate_key_update(
|
||||
driver=stmt.inserted.driver,
|
||||
mountpoint=stmt.inserted.mountpoint,
|
||||
scope=stmt.inserted.scope,
|
||||
last_update_at=stmt.inserted.last_update_at
|
||||
)
|
||||
else:
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
stmt = sqlite_insert(DockerVolume).values(**values)
|
||||
stmt = stmt.on_conflict_do_update(
|
||||
index_elements=['host_id', 'name'],
|
||||
set_={
|
||||
'driver': stmt.excluded.driver,
|
||||
'mountpoint': stmt.excluded.mountpoint,
|
||||
'scope': stmt.excluded.scope,
|
||||
'last_update_at': stmt.excluded.last_update_at
|
||||
}
|
||||
)
|
||||
|
||||
await self.session.execute(stmt)
|
||||
|
||||
# Return the upserted volume
|
||||
|
||||
+3
-3
@@ -89,7 +89,7 @@ class UserRepository:
|
||||
role=role,
|
||||
is_active=is_active,
|
||||
is_superuser=is_superuser,
|
||||
password_changed_at=datetime.now(timezone.utc),
|
||||
password_changed_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
)
|
||||
self.session.add(user)
|
||||
await self.session.flush()
|
||||
@@ -106,13 +106,13 @@ class UserRepository:
|
||||
async def update_password(self, user: User, hashed_password: str) -> User:
|
||||
"""Update user password and timestamp."""
|
||||
user.hashed_password = hashed_password
|
||||
user.password_changed_at = datetime.now(timezone.utc)
|
||||
user.password_changed_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
await self.session.flush()
|
||||
return user
|
||||
|
||||
async def update_last_login(self, user: User) -> User:
|
||||
"""Update last login timestamp."""
|
||||
user.last_login = datetime.now(timezone.utc)
|
||||
user.last_login = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
await self.session.flush()
|
||||
return user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user