Skip to content

Commit

Permalink
Merge pull request #28 from max-pfeiffer/bugfix/manage_database
Browse files Browse the repository at this point in the history
Fixed manage command for installing backend database
  • Loading branch information
max-pfeiffer authored Feb 2, 2024
2 parents 38ecd8c + 473eef1 commit ebc2ba6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/api_specification/api_specs_v0_1_0.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi": "3.1.0", "info": {"title": "FastAPI", "version": "0.1.0"}, "paths": {"/v1/schedule/{primary_key}": {"get": {"tags": ["schedule"], "summary": "Get Schedule", "description": "Get Schedule.", "operationId": "get_schedule_v1_schedule__primary_key__get", "parameters": [{"name": "primary_key", "in": "path", "required": true, "schema": {"type": "integer", "title": "Primary Key"}}], "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScheduleResponse"}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}, "put": {"tags": ["schedule"], "summary": "Update Schedule", "description": "Update Schedule.", "operationId": "update_schedule_v1_schedule__primary_key__put", "parameters": [{"name": "primary_key", "in": "path", "required": true, "schema": {"type": "integer", "title": "Primary Key"}}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScheduleUpdate"}}}}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}, "delete": {"tags": ["schedule"], "summary": "Delete Schedule", "description": "Delete Schedule.", "operationId": "delete_schedule_v1_schedule__primary_key__delete", "parameters": [{"name": "primary_key", "in": "path", "required": true, "schema": {"type": "integer", "title": "Primary Key"}}], "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}, "/v1/schedule/": {"get": {"tags": ["schedule"], "summary": "Get Schedules", "description": "Get Schedules.", "operationId": "get_schedules_v1_schedule__get", "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"items": {"$ref": "#/components/schemas/ScheduleResponse"}, "type": "array", "title": "Response Get Schedules V1 Schedule Get"}}}}}}, "post": {"tags": ["schedule"], "summary": "Create Schedule", "description": "Create Schedule.", "operationId": "create_schedule_v1_schedule__post", "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScheduleCreate"}}}, "required": true}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"type": "integer", "title": "Response Create Schedule V1 Schedule Post"}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}}, "components": {"schemas": {"HTTPValidationError": {"properties": {"detail": {"items": {"$ref": "#/components/schemas/ValidationError"}, "type": "array", "title": "Detail"}}, "type": "object", "title": "HTTPValidationError"}, "RelayBoardType": {"type": "string", "const": "waveshare_rpi_relay_board", "title": "RelayBoardType", "description": "Enumeration for repeat values."}, "Repeat": {"type": "string", "enum": ["every_day", "weekdays", "weekends", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], "title": "Repeat", "description": "Enumeration for repeat values."}, "ScheduleCreate": {"properties": {"start_time": {"type": "string", "format": "time", "title": "Start Time", "description": "Start time of the schedule"}, "duration": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Duration", "description": "Duration in minutes"}, "repeat": {"allOf": [{"$ref": "#/components/schemas/Repeat"}], "description": "Specifies how the schedule is repeated"}, "active": {"type": "boolean", "title": "Active", "description": "Whether the schedule is active", "default": true}, "relay_board_type": {"allOf": [{"$ref": "#/components/schemas/RelayBoardType"}], "description": "Type of the relay board"}, "relay_position": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Relay Position", "description": "Position of the relay"}}, "type": "object", "required": ["start_time", "duration", "repeat", "relay_board_type", "relay_position"], "title": "ScheduleCreate", "description": "Creation schema for schedule."}, "ScheduleResponse": {"properties": {"id": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Id", "description": "Primary key"}, "start_time": {"type": "string", "format": "time", "title": "Start Time", "description": "Start time of the schedule"}, "duration": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Duration", "description": "Duration in minutes"}, "repeat": {"allOf": [{"$ref": "#/components/schemas/Repeat"}], "description": "Specifies how the schedule is repeated"}, "active": {"type": "boolean", "title": "Active", "description": "Whether the schedule is active"}, "relay_board_type": {"allOf": [{"$ref": "#/components/schemas/RelayBoardType"}], "description": "Type of the relay board"}, "relay_position": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Relay Position", "description": "Position of the relay"}}, "type": "object", "required": ["id", "start_time", "duration", "repeat", "active", "relay_board_type", "relay_position"], "title": "ScheduleResponse", "description": "Response schema for schedule."}, "ScheduleUpdate": {"properties": {"start_time": {"anyOf": [{"type": "string", "format": "time"}, {"type": "null"}], "title": "Start Time", "description": "Start time of the schedule"}, "duration": {"anyOf": [{"type": "integer", "exclusiveMinimum": 0.0}, {"type": "null"}], "title": "Duration", "description": "Duration in minutes"}, "repeat": {"anyOf": [{"$ref": "#/components/schemas/Repeat"}, {"type": "null"}], "description": "Specifies how the schedule is repeated"}, "active": {"anyOf": [{"type": "boolean"}, {"type": "null"}], "title": "Active", "description": "Whether the schedule is active"}, "relay_board_type": {"anyOf": [{"$ref": "#/components/schemas/RelayBoardType"}, {"type": "null"}], "description": "Type of the relay board"}, "relay_position": {"anyOf": [{"type": "integer", "exclusiveMinimum": 0.0}, {"type": "null"}], "title": "Relay Position", "description": "Position of the relay"}}, "type": "object", "title": "ScheduleUpdate", "description": "Update schema for schedule."}, "ValidationError": {"properties": {"loc": {"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}, "type": "array", "title": "Location"}, "msg": {"type": "string", "title": "Message"}, "type": {"type": "string", "title": "Error Type"}}, "type": "object", "required": ["loc", "msg", "type"], "title": "ValidationError"}}}}
{"openapi": "3.1.0", "info": {"title": "FastAPI", "version": "0.1.0"}, "paths": {"/v1/schedule/{primary_key}": {"get": {"tags": ["Schedule"], "summary": "Get Schedule", "description": "Get Schedule.", "operationId": "get_schedule_v1_schedule__primary_key__get", "parameters": [{"name": "primary_key", "in": "path", "required": true, "schema": {"type": "integer", "title": "Primary Key"}}], "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScheduleResponse"}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}, "put": {"tags": ["Schedule"], "summary": "Update Schedule", "description": "Update Schedule.", "operationId": "update_schedule_v1_schedule__primary_key__put", "parameters": [{"name": "primary_key", "in": "path", "required": true, "schema": {"type": "integer", "title": "Primary Key"}}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScheduleUpdate"}}}}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}, "delete": {"tags": ["Schedule"], "summary": "Delete Schedule", "description": "Delete Schedule.", "operationId": "delete_schedule_v1_schedule__primary_key__delete", "parameters": [{"name": "primary_key", "in": "path", "required": true, "schema": {"type": "integer", "title": "Primary Key"}}], "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}, "/v1/schedule/": {"get": {"tags": ["Schedule"], "summary": "Get Schedules", "description": "Get Schedules.", "operationId": "get_schedules_v1_schedule__get", "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"items": {"$ref": "#/components/schemas/ScheduleResponse"}, "type": "array", "title": "Response Get Schedules V1 Schedule Get"}}}}}}, "post": {"tags": ["Schedule"], "summary": "Create Schedule", "description": "Create Schedule.", "operationId": "create_schedule_v1_schedule__post", "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScheduleCreate"}}}, "required": true}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"type": "integer", "title": "Response Create Schedule V1 Schedule Post"}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}, "/v1/relay/": {"get": {"tags": ["Relay"], "summary": "Get Relays", "description": "Get all relays.\n\n:return:", "operationId": "get_relays_v1_relay__get", "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"items": {"$ref": "#/components/schemas/Relay"}, "type": "array", "title": "Response Get Relays V1 Relay Get"}}}}}}}, "/v1/relay/{position}": {"get": {"tags": ["Relay"], "summary": "Get Relay", "description": "Get relay by position.\n\n:param position:\n:return:", "operationId": "get_relay_v1_relay__position__get", "parameters": [{"name": "position", "in": "path", "required": true, "schema": {"type": "integer", "title": "Position"}}], "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Relay"}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}, "put": {"tags": ["Relay"], "summary": "Update Relay", "description": "Update relay by position.\n\n:param position:\n:param relay:\n:return:", "operationId": "update_relay_v1_relay__position__put", "parameters": [{"name": "position", "in": "path", "required": true, "schema": {"type": "integer", "title": "Position"}}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/RelayUpdate"}}}}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}}, "components": {"schemas": {"HTTPValidationError": {"properties": {"detail": {"items": {"$ref": "#/components/schemas/ValidationError"}, "type": "array", "title": "Detail"}}, "type": "object", "title": "HTTPValidationError"}, "Relay": {"properties": {"position": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Position", "description": "Relay position on the board"}, "on": {"type": "boolean", "title": "On", "description": "Indicates if relay is switched on"}}, "type": "object", "required": ["position", "on"], "title": "Relay", "description": "Response schema for Relay object."}, "RelayUpdate": {"properties": {"on": {"type": "boolean", "title": "On", "description": "Indicates if relay is switched on"}}, "type": "object", "required": ["on"], "title": "RelayUpdate", "description": "Update schema for Relay object."}, "Repeat": {"type": "string", "enum": ["every_day", "weekdays", "weekends", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], "title": "Repeat", "description": "Enumeration for repeat values."}, "ScheduleCreate": {"properties": {"start_time": {"type": "string", "format": "time", "title": "Start Time", "description": "Start time of the schedule"}, "duration": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Duration", "description": "Duration in minutes"}, "repeat": {"allOf": [{"$ref": "#/components/schemas/Repeat"}], "description": "Specifies how the schedule is repeated"}, "active": {"type": "boolean", "title": "Active", "description": "Whether the schedule is active", "default": true}, "relay_position": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Relay Position", "description": "Position of the relay"}}, "type": "object", "required": ["start_time", "duration", "repeat", "relay_position"], "title": "ScheduleCreate", "description": "Creation schema for schedule."}, "ScheduleResponse": {"properties": {"id": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Id", "description": "Primary key"}, "start_time": {"type": "string", "format": "time", "title": "Start Time", "description": "Start time of the schedule"}, "duration": {"type": "integer", "exclusiveMinimum": 0.0, "title": "Duration", "description": "Duration in minutes"}, "repeat": {"allOf": [{"$ref": "#/components/schemas/Repeat"}], "description": "Specifies how the schedule is repeated"}, "active": {"type": "boolean", "title": "Active", "description": "Whether the schedule is active"}}, "type": "object", "required": ["id", "start_time", "duration", "repeat", "active"], "title": "ScheduleResponse", "description": "Response schema for schedule."}, "ScheduleUpdate": {"properties": {"start_time": {"anyOf": [{"type": "string", "format": "time"}, {"type": "null"}], "title": "Start Time", "description": "Start time of the schedule"}, "duration": {"anyOf": [{"type": "integer", "exclusiveMinimum": 0.0}, {"type": "null"}], "title": "Duration", "description": "Duration in minutes"}, "repeat": {"anyOf": [{"$ref": "#/components/schemas/Repeat"}, {"type": "null"}], "description": "Specifies how the schedule is repeated"}, "active": {"anyOf": [{"type": "boolean"}, {"type": "null"}], "title": "Active", "description": "Whether the schedule is active"}, "relay_position": {"anyOf": [{"type": "integer", "exclusiveMinimum": 0.0}, {"type": "null"}], "title": "Relay Position", "description": "Position of the relay"}}, "type": "object", "title": "ScheduleUpdate", "description": "Update schema for schedule."}, "ValidationError": {"properties": {"loc": {"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}, "type": "array", "title": "Location"}, "msg": {"type": "string", "title": "Message"}, "type": {"type": "string", "title": "Error Type"}}, "type": "object", "required": ["loc", "msg", "type"], "title": "ValidationError"}}}}
12 changes: 5 additions & 7 deletions manage/export.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
"""Export commands."""
from pathlib import Path

import click

from manage.utils import (
PROJECT_ROOT_PATH,
BACKEND_PATH,
VIRTUAL_ENVIRONMENT_PATH,
activate_virtual_environment,
run_subprocess,
)


@click.command()
@click.command(name="backend-api-specs")
def backend_api_specs():
"""Export backend API specification.
:return:
"""
backend_path: Path = PROJECT_ROOT_PATH / "backend"
virtual_environment_path: Path = PROJECT_ROOT_PATH / "backend" / ".venv"
env: dict = activate_virtual_environment(virtual_environment_path)
env: dict = activate_virtual_environment(VIRTUAL_ENVIRONMENT_PATH)
run_subprocess(
["python", "-m", "utilities.export_api_specification"],
cwd=backend_path,
cwd=BACKEND_PATH,
env=env,
)
4 changes: 2 additions & 2 deletions manage/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from manage.utils import (
BACKEND_PATH,
BACKEND_VIRTUAL_ENVIRONMENT_PATH,
VIRTUAL_ENVIRONMENT_PATH,
activate_virtual_environment,
run_subprocess,
)
Expand All @@ -27,5 +27,5 @@ def install_backend_database():
:return:
"""
env: dict = activate_virtual_environment(BACKEND_VIRTUAL_ENVIRONMENT_PATH)
env: dict = activate_virtual_environment(VIRTUAL_ENVIRONMENT_PATH)
run_subprocess(["alembic", "upgrade", "head"], cwd=BACKEND_PATH, env=env)
10 changes: 4 additions & 6 deletions manage/run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Export commands."""
from pathlib import Path

import click

from manage.utils import (
PROJECT_ROOT_PATH,
BACKEND_PATH,
VIRTUAL_ENVIRONMENT_PATH,
activate_virtual_environment,
run_subprocess,
)
Expand All @@ -16,9 +16,7 @@ def backend():
:return:
"""
backend_path: Path = PROJECT_ROOT_PATH / "backend"
virtual_environment_path: Path = PROJECT_ROOT_PATH / ".venv"
env: dict = activate_virtual_environment(virtual_environment_path)
env: dict = activate_virtual_environment(VIRTUAL_ENVIRONMENT_PATH)
run_subprocess(
[
"uvicorn",
Expand All @@ -30,6 +28,6 @@ def backend():
"8000",
"app.main:app",
],
cwd=backend_path,
cwd=BACKEND_PATH,
env=env,
)
2 changes: 1 addition & 1 deletion manage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import click

PROJECT_ROOT_PATH: Path = Path(__file__).parent.parent.resolve()
VIRTUAL_ENVIRONMENT_PATH: Path = PROJECT_ROOT_PATH / ".venv"
BACKEND_PATH: Path = PROJECT_ROOT_PATH / "backend"
BACKEND_VIRTUAL_ENVIRONMENT_PATH: Path = PROJECT_ROOT_PATH / "backend" / ".venv"


def run_subprocess(
Expand Down

0 comments on commit ebc2ba6

Please sign in to comment.